简体   繁体   中英

How to get a datakey in windowsforms 4

Iam having a small problem, Iam working with windows forms

How do i get my datakey for a row that i have selected so i can delete it out of the dataset/table I have seen many people that have same question and they get this slution:

  int ID = Convert.ToInt32(gridview.DataKeys[gridview.SelectedIndex].Values.toString());

But That doenst work for me. I can type this:

 int ID = Convert.ToInt32(gridview.

then the intellisence doesnt give me datakeys. so Thats the point where he blows out. Do i miss a reference of something

Please give me a solution.

DataKeys are for GridView the web control and not available in Window Forms. You need to have required columns in data source to bind with DataGridView (For Window Forms) and hide them if you do not want to show them.

Binding the required column and hide the column

 dgv.DataSource = source; 
 dgv.Columns["YourColumnName"].Visible = false;

Getting value from hidden column

string value dgvInHouseApp.Rows[rowIndex].Cells["YourColumnName"].Value.ToString()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM