So i have a datagrid and I have a databindingsource control for my text file. Works like a bomb, but then i added a toolstripmenu so that i can right click on the datagrid, a menu pops up and i can delete the row of data from the text file through the datagrid. I already have that design and must still code it, but i know how it works.

My problem is, my program cannot find the one and only column in the datagrid.

i make use of the following code:

string Delete = SWVerGrid.Rows[SWVerGrid.CurrentCell.RowIndex].Cells["Version"].Value.ToString();

I went to the form, looked at the column properties, its clear that "Version" is my column name, i played around with it some more, then every time at runtime, another "Version" column is created for some weird reason...but its not doing that any more. I don't know what i did to fix it. lol.

The error that i receive is: Column named Version cannot be found Parameter name: columnName

Anyone else experience this?

Recommended Answers

All 6 Replies

Is the "HeaderText" actually the column name?

[Another test]
If you iterate through the columns numerically having the code write the column name to the debug window, do you see "Version" as a column name?

there is only one column, the Version column. Another strange thing about this form is, if you look at that first pic, just above the datagrid, there is an outlining of the datagrid as well...i dont know why the gray lining is there when the actual datagrid is positioned properly.

I understand there is one column, but something is going on that we both don't yet see.
All I really wanted was for you to make the code TELL you the name of the first column or any other columns it might see.
If it comes back null, that's a starting point.

i got it working now thanks. i used this:

string Delete2 = SWVerGrid.CurrentRow.DataBoundItem.ToString();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.