Question

I'm using a DataGridView to accept certain values at runtime. I've a hidden foreign key column in the DataGridView which should contain a default value while the other columns in the DataGridView are being updated using the Update() method of the OleDbAdapter class.

Was it helpful?

Solution

is the foreign-key colomn from the same bound datasource as the rest of the data?

EDIT:

first you need to find out which row you want to edit, if the event is klickbased you can use something like this:

this.dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value

okay, you can also accsess any colomn by its name value .you can just edit the column by using

this.dgv.Rows[e.RowIndex].Cells["YOUR_HIDDEN_COLOMN"].Value = "NEW_VALUE"

i hope i helped, if not, please clearify what you want to do. :-)

EDIT 2: -> if you want to edit all the Rows just use foreach (although the itemArray requires you to use the number of the colomn. i dont think this is the best technique but it is the one i know best :> )

foreach( DataRow Row in YOUR_DATASOURCE.Table[0].Rows)
{
   Row.ItemArray[YOUR_HIDDEN_COLOMN_NUMBER] = "YOUR_DEFAULT_VALUE"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top