Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve dataset value when record selected in DataGrid 1

Status
Not open for further replies.

tmcnutt

Programmer
May 17, 2002
83
US
I have a datagrid control that is populated from a dataset and I only show the values the user needs to see instead of all values in the dataset. What I want to achieve is return a value from the dataset that is not shown in the datagrid, but is tied to the record selected in the datagrid. The value I want is the primary key of a table that is in the dataset, but not shown in the datagrid. The primary key is the only additional value in the dataset that is not shown in the datagri. I want to use the primary key to look up data in another table. I am not sure if I am going about this the correct way. Please let me know and give me a code sample if possible.

Thanks,
Tom
 
Check out 4guysfromrolla.com. Here is a link...

Are you returning the primary key and just not showing it in the datagrid (it is invisible)? You can then reference it by making a datatable which is filled by your dataset and referencing the cell
Code:
MyDataSet = New DataSet
        MyDataAdapter.Fill(MyDataSet, "Citizen")
        Dim mytable As DataTable = MyDataSet.Tables("Citizen")
Dim yourprimarykey as string
yourprimarykey = mytable.Rows(0).Item(1)
You can then do whatever you want to with the string (integer, whatever).
 
Yes, I want to return the primary key, but not show it in the datagrid. Can I return whatever I want to the dataset and only use certain columns from the dataset to display in the datagrid? My program returns 6 records and I display them in the datagrid. When the user selects a row, I want to get the primary key related to the row.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top