Friday, January 11, 2008 10:45 PMHi everyone,
I have got one table with 4 columns. The first column is the "id column" with primary keys. I have to obtain the value of the cell which is in first column and in selected row by clicking a simple button. The value should appear in textbox.
It is no problem for me to do it with dataGridView_RowEnter event
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells["COLUMN_ID"].FormattedValue.ToString();
So how to obtain the cell value of the selected row in column "COLUMN_ID" by clicking a simple button?
Thanks in advance
Monday, January 14, 2008 8:43 AM
where DataGridView1 is your datagridview name'
str = DataGridView1.Rows[DataGridView.SelectedRows.Index].Cells[X].Value.ToString();
where X is the column you want to read.
Note: it suppose to be possible to retrieve it like this, i try but didn't work:
str = DataGridView.SelectedRows.Cells[X].Value.ToString();
where 0 let you read from multiple selectedrows. 0 is the first selectedrows, 1 the second and so on...
this can be useful if you want to read or manipulate multiple selectedrows.
hope this help
Monday, January 14, 2008 12:16 PMHI all. Sorry the intromission, but i have a problem related with what youre discussing here.
Im trying to write to a xml values from a datagridview using something like:
my problem is when i try to write multiple times using a similar code to the same xml, it wont write anything at all...
thanks in advance
Monday, January 14, 2008 10:52 PM
have you try the example i write above???
can you get just the datagridview value to a simple string, like i write in my example???
Monday, January 14, 2008 11:04 PM
nevermind... the error was mine, of course
I misstyped the column name... and with that, the whole xml got corrupted... lol
Sorry about the inconvenience.
NeoBugs, thanks anyway, your code was really helpfull!!
Tuesday, October 30, 2012 11:46 AM
Heres a good way of obtaining values from desired cells ;
I obtain certain values from a selected row after I click on the cell,
my example is where I click on one cell , the event fires the following:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
nameTextbox.Text = PinInGrid;