How Do I Grab Current Row PK in Datagrid?

  • Thread starter Thread starter Steven C
  • Start date Start date
S

Steven C

Hello:

I have a datagrid that has a dataset bound to it. When the customer
selects a certain row in the grid, I would like to be able to grab the
PK for that row, so I can call the customer edit form and load the
textboxes with a SELECT based upon that PK. How do I do this? In
Foxpro, since cursors have global scope, I would just call the edit
form and load the textboxes from the current (selected) record.

Thanks!

Steven
 
The datagrid has a CurrentCell property. CurrentCell is compose of a row
and an index value. YOu can use those (assuming the sort order is the same)
which will correspond the the row and column index of the table its bound
to.

So, if the PK Value was "Bill" and the PK was the first column in your
datatable.

You could the reference dataTable.Rows[DataGrid.CurrentRowIndex][PKName]
 
Thanks, Bill

This seems to return an object, while I need to return the actual PK
value. For Instance, I have:

int PK =
CustomersTable.Rows[grdCustomers.CurrentRowIndex]["customerno"];

But this throws an exception because it's trying to return an object,
not the integer value for the PK.

Steven
The datagrid has a CurrentCell property. CurrentCell is compose of a row
and an index value. YOu can use those (assuming the sort order is the same)
which will correspond the the row and column index of the table its bound
to.

So, if the PK Value was "Bill" and the PK was the first column in your
datatable.

You could the reference dataTable.Rows[DataGrid.CurrentRowIndex][PKName]
Hello:

I have a datagrid that has a dataset bound to it. When the customer
selects a certain row in the grid, I would like to be able to grab the
PK for that row, so I can call the customer edit form and load the
textboxes with a SELECT based upon that PK. How do I do this? In
Foxpro, since cursors have global scope, I would just call the edit
form and load the textboxes from the current (selected) record.

Thanks!

Steven
 
Just cast it to whatever type the value of the PK is.
Thanks, Bill

This seems to return an object, while I need to return the actual PK
value. For Instance, I have:

int PK =
CustomersTable.Rows[grdCustomers.CurrentRowIndex]["customerno"];

But this throws an exception because it's trying to return an object,
not the integer value for the PK.

Steven
The datagrid has a CurrentCell property. CurrentCell is compose of a row
and an index value. YOu can use those (assuming the sort order is the same)
which will correspond the the row and column index of the table its bound
to.

So, if the PK Value was "Bill" and the PK was the first column in your
datatable.

You could the reference dataTable.Rows[DataGrid.CurrentRowIndex][PKName]
Hello:

I have a datagrid that has a dataset bound to it. When the customer
selects a certain row in the grid, I would like to be able to grab the
PK for that row, so I can call the customer edit form and load the
textboxes with a SELECT based upon that PK. How do I do this? In
Foxpro, since cursors have global scope, I would just call the edit
form and load the textboxes from the current (selected) record.

Thanks!

Steven
 
Coolness!

Thanks for all your help. :)

Steven
Just cast it to whatever type the value of the PK is.
Thanks, Bill

This seems to return an object, while I need to return the actual PK
value. For Instance, I have:

int PK =
CustomersTable.Rows[grdCustomers.CurrentRowIndex]["customerno"];

But this throws an exception because it's trying to return an object,
not the integer value for the PK.

Steven
The datagrid has a CurrentCell property. CurrentCell is compose of a row
and an index value. YOu can use those (assuming the sort order is the same)
which will correspond the the row and column index of the table its bound
to.

So, if the PK Value was "Bill" and the PK was the first column in your
datatable.

You could the reference dataTable.Rows[DataGrid.CurrentRowIndex][PKName]
<Steven C> wrote in message
Hello:

I have a datagrid that has a dataset bound to it. When the customer
selects a certain row in the grid, I would like to be able to grab the
PK for that row, so I can call the customer edit form and load the
textboxes with a SELECT based upon that PK. How do I do this? In
Foxpro, since cursors have global scope, I would just call the edit
form and load the textboxes from the current (selected) record.

Thanks!

Steven
 
glad it worked!
Coolness!

Thanks for all your help. :)

Steven
Just cast it to whatever type the value of the PK is.
Thanks, Bill

This seems to return an object, while I need to return the actual PK
value. For Instance, I have:

int PK =
CustomersTable.Rows[grdCustomers.CurrentRowIndex]["customerno"];

But this throws an exception because it's trying to return an object,
not the integer value for the PK.

Steven

The datagrid has a CurrentCell property. CurrentCell is compose of a row
and an index value. YOu can use those (assuming the sort order is the same)
which will correspond the the row and column index of the table its bound
to.

So, if the PK Value was "Bill" and the PK was the first column in your
datatable.

You could the reference dataTable.Rows[DataGrid.CurrentRowIndex][PKName]
<Steven C> wrote in message
Hello:

I have a datagrid that has a dataset bound to it. When the customer
selects a certain row in the grid, I would like to be able to grab the
PK for that row, so I can call the customer edit form and load the
textboxes with a SELECT based upon that PK. How do I do this? In
Foxpro, since cursors have global scope, I would just call the edit
form and load the textboxes from the current (selected) record.

Thanks!

Steven
 
Back
Top