如何获取ListView中未显示在C#中ListView中的项目的主键?我谈论的主键是自动递增的,所以我没有在列表视图中显示它
问问题
479 次
3 回答
0
如果要检索该字段,则应将其添加到模型类中,否则要检索它,则需要再次查询数据库以获取它,这是非常低效的。
于 2012-10-05T10:15:02.780 回答
0
您所指的内容(因为您提到 ListView)是 listviewitem 的索引(免责声明:手写,未经测试)
var listItem = listView1.SelectedItems[0]; // Get the selected item (insert null check)
var key = listItem.Index; // Get its index
以上是获取任意 ListViewItem 的索引,如果要获取 select listviewitems 索引,可以执行以下操作:
var key = listView1.SelectedIndex;
于 2012-10-05T10:19:27.373 回答
0
尝试这个:
if (ListView1.SelectedItems.Count > 0)
var primaryKey = ListView1.SelectedValue;
于 2012-10-05T10:20:20.950 回答