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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
0
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. Thanks. I get the above error when I try that
0
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
Being new to C# that seems overcomplicated
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.