Question Datagridview Cell Field Names

ccbryan

Active member
Joined
Oct 14, 2008
Messages
30
Programming Experience
5-10
Hi... I'm writing a change log application, capturing modifications to data records. I'm having trouble with modifications made in a datagridview. I want to write a change log record on Datagridview.CellEndEdit(), but I don't know how to find the data table field name that the cell's value belongs to. The problem is that the datasourse of the Datagridview changes depending on the product type selected, so I don't know at design time which fields will be shown in the grid. So I have to have a way to determine the fields that the cells represent. In other words, I need to be able to essentially read the header of the column for the active cell.

Any ideas? Thanks for looking...

Chandler
 
Last edited:
Never Mind, figured out a way..

I know how I'm going to do it... I'll make an array containing the column names and sequence when I refresh the datagrid. Then on Datagridview.CellEndEdit I can find which column I'm in with e.columnindex or Datagridview1.currentcell.columnindex and then just look up that number in my array to find the column name.

thanks...

I can't figure out how to mark the original post as SOLVED....
 
Agree with using Columns collection, and using e.ColumnIndex to index it :) That would also work if user was allowed to reorder the columns.
 
Awesome! I had it working with the array but hadn't considered if the columns were reordered, d'oh.
DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).Name is exactly what I was looking for.

Thanks!

Chandler
 
I would as said prefer to use the column index provided by event information instead of going the route of asking the DataGridView for its current cell again.
 
Back
Top