C# Non-invocable member 'System.Windows.Forms.DataGridView.Rows' cannot be used like a method.

Hi
In the row  "oColumns = SelectedRow.Cells(0).value.tostring;" in the code below I get the following error":
"Non-invocable member 'System.Windows.Forms.DataGridView.Rows' cannot be used like a method."

       public object Build_SQL_Columns_DataTypes()
        {
            object functionReturnValue = null;
            try
            {
                string oColumns = "";
                string oDataTypes = "";

                foreach (DataGridViewRow SelectedRow in dataGridViewTableData.SelectedRows)
                {
                    if (string.IsNullOrEmpty(oColumns))
                    {
                        oColumns = SelectedRow.Cells(0).value.tostring;
                        oDataTypes = SelectedRow.Cells(17).Value();
                    }
                    else
                    {
                        oColumns = oColumns + "," + SelectedRow.Cells(0).Value();
                        oDataTypes = oDataTypes + "," + SelectedRow.Cells(17).Value();
                    }

                }

                functionReturnValue = oColumns + "||" + oDataTypes;
            }
            catch (Exception ex)
            {
                //Interaction.MsgBox(ex.Message);
            }
            return functionReturnValue;
        }
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
Robert SchuttSoftware EngineerCommented:
Like the error says: "Did you intend to invoke the method?"

So the answer is yes, that's the reason for the parentheses in that case and not when accessing a variable like Value.
oColumns = SelectedRow.Cells[0].Value.ToString();

Open in new window

If you're not familiar with a class, in code insight you can tell the difference between variables and methods by the icon (and also the description):
capture
0
 
Robert SchuttSoftware EngineerCommented:
Use .Cells[0] etc, it should be an index, not a function call.
0
 
Robert SchuttSoftware EngineerCommented:
Also use .Value not .value or .Value()

[edit] - and finally: .ToString() ;-)
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. Thanks. I get the above error when I try that
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
Being new to C# that seems overcomplicated
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.