Datagridview.selectedValue help?
-
I'm trying to find a way to grab a given rows cell information, for now just the primary key, and store it in a variable to use somewhere else. If I use listbox's I can simply use .selectedValue() and it gives me exactly what I need, but in this case, I'm needing to do it with a datagridview and this attribute doesn't exist. Thanks!
-
I'm trying to find a way to grab a given rows cell information, for now just the primary key, and store it in a variable to use somewhere else. If I use listbox's I can simply use .selectedValue() and it gives me exactly what I need, but in this case, I'm needing to do it with a datagridview and this attribute doesn't exist. Thanks!
PyroManiak wrote:
I'm trying to find a way to grab a given rows cell information, for now just the primary key, and store it in a variable to use somewhere else.
If your DataGridView is populated through a DataSource, then the following code snippet might help you.
stringVariable = dataGridView.Rows[index].Cells[index].Value.toString();
Here index could be an integer value or variable holding a value: and is zero (0) based. Alternatively you can use Column name as Cells index, like:
stringVariable = dataGridView.Rows[index].Cells["ColumnName"].Value.toString();
Also you can get the value from the selected or Current row, like this:
stringVariable = dataGridView.CurrentRow.Cells[index].Value.toString();
Using the same technique you cann't get value from an unbound datagridview Hope this would solve your problem. Best of Luck. _____________________________ Success is not something to wait for, its something to work for.
-
PyroManiak wrote:
I'm trying to find a way to grab a given rows cell information, for now just the primary key, and store it in a variable to use somewhere else.
If your DataGridView is populated through a DataSource, then the following code snippet might help you.
stringVariable = dataGridView.Rows[index].Cells[index].Value.toString();
Here index could be an integer value or variable holding a value: and is zero (0) based. Alternatively you can use Column name as Cells index, like:
stringVariable = dataGridView.Rows[index].Cells["ColumnName"].Value.toString();
Also you can get the value from the selected or Current row, like this:
stringVariable = dataGridView.CurrentRow.Cells[index].Value.toString();
Using the same technique you cann't get value from an unbound datagridview Hope this would solve your problem. Best of Luck. _____________________________ Success is not something to wait for, its something to work for.
stringVariable = dataGridView.CurrentRow.Cells[index].Value.toString(); That worked for my purposes just great! Thanks a bunch!