How Do I Grab Current Row PK in Datagrid?

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
 
W

William Ryan eMVP

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]
 
S

Steven C

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
 
W

William Ryan eMVP

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
 
S

Steven C

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
 
W

William Ryan eMVP

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top