Why am I getting this 'method group' error?
-
Tuesday, March 27, 2012 12:38 AM
I am making a Windows Forms MySql admin system and I have got this error.
I had declared:
DataGridViewCell = sSelect;
So what I want to happen is that when a cell is selected, and I click a "Load" button, a second DataGridView is populated. This is the snippet for that:
private void button1_Click(object sender, EventArgs e)
{
if (sSelect = "Pop")
{
updateDataGridPList();
dgvPlaylist.Columns["SongTitle"].HeaderText="Song Name";
dgvPlaylist.Columns["Artist"].HeaderText="Artist";
dgvPlaylist.Columns["runningorder"].HeaderText="Order of Running";
dgvPlaylist.Columns["runningTime"].HeaderText="Running Time (Sec)";
}}
However, I get this annoying error that says:
Error 1 Cannot assign to 'sSelect' because it is a 'method group'
Anybody help me please?
Much appreciated,
-Jake Gray.
All Replies
-
Tuesday, March 27, 2012 1:29 AM
You're missing an equals sign.
if (sSelect == "Pop")
-
Tuesday, March 27, 2012 1:38 AM
I did that, but know I'm given this error:
Operator '==' cannot be applied to operands of type 'method group' and 'string'
This is weird!
-
Tuesday, March 27, 2012 2:11 AMModerator
sSelect is the name of a Method in your type, not a variable. If you're trying to execute the method, you need:
if (sSelect() == "Pop")
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". -
Tuesday, March 27, 2012 10:30 AM
Sorry if I'm being a complete NOOB here... well, I am, but anyway... after putting this in, I'm greeted with this error
Operator '==' cannot be applied to operands of type 'System.Windows.Forms.DataGridViewCell' and 'string'
Basically, I just want to select a field in one DGV, hit a load button, it runs the query and show's up in a second DGV! Annoying! What am I doing wrong?
Thanks!
-
Tuesday, March 27, 2012 11:04 AMModerator
What exactly is "sSelect"?
DataGridViewCell = sSelect;
I cannot make sense of that line of code. There is no variable declaration in it. What are you trying to do on that line of code? DataGridViewCell is a type name. That line should produce a compile time error, "DataGridViewCell is a 'type' but it is used like a 'variable'." if the line is within a method, or an "invalid token" if the line appears outside of a method at the class scope level.
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."
-
Tuesday, March 27, 2012 11:07 AM
What i found is that you cannot directly compare sSelect with string, please check maybe sSelect is an object and you need to select and property to compare forexample .Value in certain cases. Try writing sSelect. it will bring some intellisense or typecast the sSelect to string and then compare it with "pop"
like this
if(sSelect.ToString()=="pop")
Ovais Mehboob
-
Tuesday, March 27, 2012 6:11 PM
Okay, in my first post I wasn't meant to write:
DataGridViewCell = sSelect();
It is actually is:
DataGridViewCell sSelect();
-----
Ovais, I did what you said, but my new ending error's comes up with another... this:
MainForm.sSelect()' is a 'method', which is not valid in the given context
Pulling my hair out now!
-
Tuesday, March 27, 2012 6:45 PMModerator
Okay, sSelect is a method. Try this. ....
if(sSelect.Value.ToString == "Pop")
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."
-
Tuesday, March 27, 2012 8:24 PM
Okay I still have the same error, with another added too:
MainForm.sSelect()' must declare a body because it is not marked abstract, extern, or partial
Why am I finding this so hard to do?
Could someone just tell me:
How to make it so that I select a cell in a DGV, click a button that say's "Load", and have the results show up in a second DGV!?
I already have the SQL statements ready to put in, it's just the C# I'm finding hard!
-
Tuesday, March 27, 2012 9:29 PM
Hi,
please provide detail information about MainForm.sSelect() method.
Thanks, Lukas
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Tuesday, March 27, 2012 9:41 PMModerator
MainForm.sSelect()' is a 'method', which is not valid in the given context
Pulling my hair out now!
That is the first time that you mentioned a line of code that contains that. Up till now it was only the if conditional statement. Did the code that I posted work?
You need to provide some context for your code that gives you errors. There are some folks around here who are amazing at connecting the dots, but not that good.
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."
-
Wednesday, March 28, 2012 10:05 AM
Okay, in my first post I wasn't meant to write:
DataGridViewCell = sSelect();
It is actually is:
DataGridViewCell sSelect();
To declare a DataGridViewCell, you don't put parentheses after the variable. Maybe you meant
DataGridViewCell sSelect = new DataGridViewCell();
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Friday, April 06, 2012 9:05 AM
-
Wednesday, March 28, 2012 11:25 AMModerator
DataGridViewCell = sSelect();
To declare a DataGridViewCell, you don't put parentheses after the variable. Maybe you meant
DataGridViewCell sSelect = new DataGridViewCell();
I suspect that that issue is resolved. See my prior post. I think sSelect is a method that returns a DGVCell.
It appears the OP has moved on to a new problem that contains this code, MainForm.sSelect. The OP has posted the message, but not the line of code that causes the error message.
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."
-
Wednesday, March 28, 2012 12:15 PM
I suspect that that issue is resolved. See my prior post. I think sSelect is a method that returns a DGVCell.
I don't think so. There is an error stating "MainForm.sSelect()' must declare a body because it is not marked abstract, extern, or partial". That means it has been declared as though it was a method. And since the compiler thinks it is supposed to be a method, it explains also the other error. -
Wednesday, March 28, 2012 1:25 PMModerator
Good point. Like I said, though. The OP has changed his code without posting any of it and apparently moved on to other errors, or as you say created a new one.
This should compile, but not do anything useful. It can replace whatever the OP has just to clear the errors.
public DataGridViewCell sSelect() { throw new NotImplementedException("sSelect"); }
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Friday, April 06, 2012 9:05 AM

