Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.Net ListBox数据源删除_Vb.net - Fatal编程技术网

VB.Net ListBox数据源删除

VB.Net ListBox数据源删除,vb.net,Vb.net,如何获取Id列?它是列表框中的主键,该列表框中有一个数据集来填充选定的索引,以便删除它 通常我会使用lstBox.SelectedIndex,但我猜这只是数组索引,而不是主键。那么如何获取该索引的行呢?A将实际使用的作为其数据源。如果未指定,将返回当前选定的。您可以使用它来获取主键 Dim drv As DataRowView = DirectCast(Me.ListBox1.SelectedValue, DataRowView) Dim pk As Integer = drv.Row.Item

如何获取Id列?它是列表框中的主键,该列表框中有一个数据集来填充选定的索引,以便删除它

通常我会使用lstBox.SelectedIndex,但我猜这只是数组索引,而不是主键。那么如何获取该索引的行呢?

A将实际使用的作为其数据源。如果未指定,将返回当前选定的。您可以使用它来获取主键

Dim drv As DataRowView = DirectCast(Me.ListBox1.SelectedValue, DataRowView)
Dim pk As Integer = drv.Row.Item("id")
但是,如果将值成员指定为主键列的名称,则选定值将返回当前选定项的主键

Me.ListBox1.ValueMember = "id"
Dim pk As Integer = DirectCast(Me.ListBox1.SelectedValue, Integer)