Vb.net 是否为DataGridView控件中的行设置名称?
VB.Net的DataGridView支持命名列,但我想知道它是否能以某种方式对行执行相同的操作,以便我们可以使用如下内容:Vb.net 是否为DataGridView控件中的行设置名称?,vb.net,datagridview,rows,Vb.net,Datagridview,Rows,VB.Net的DataGridView支持命名列,但我想知道它是否能以某种方式对行执行相同的操作,以便我们可以使用如下内容: With DataGridView1 .Rows.Add(4) .Rows(0).Name = "Setting1" .Rows(1).Name = "Setting2" 'Added two columns at design time .Columns("Key").Row("Setting1") = "Key1"
With DataGridView1
.Rows.Add(4)
.Rows(0).Name = "Setting1"
.Rows(1).Name = "Setting2"
'Added two columns at design time
.Columns("Key").Row("Setting1") = "Key1"
.Columns("Value").Row("Setting1") = "Value1"
.Columns("Key").Row("Setting2") = "Key2"
.Columns("Value").Row("Setting2") = "Value2"
End With
您确认这是不可能的吗?我们必须使用数字索引来引用行号?在
DataGridViewRow
上没有Name
属性,因此不,这是不可能的
您可以始终使用字典
将名称绑定到DataGridViewRow
:
Dim dictRows As New Dictionary(Of String, DataGridViewRow)
'Map names to corresponding rows
dictRows.Add("Setting1", DataGridView1.Rows(0))
dictRows.Add("Setting2", DataGridView1.Rows(1))
'Access rows with names, using dictionary
dictRows("Setting1").Cells("Key").Value = "Key1"
dictRows("Setting1").Cells("Value").Value = "Value1"
DataGridViewRow
上没有Name
属性,因此不可能
您可以始终使用字典
将名称绑定到DataGridViewRow
:
Dim dictRows As New Dictionary(Of String, DataGridViewRow)
'Map names to corresponding rows
dictRows.Add("Setting1", DataGridView1.Rows(0))
dictRows.Add("Setting2", DataGridView1.Rows(1))
'Access rows with names, using dictionary
dictRows("Setting1").Cells("Key").Value = "Key1"
dictRows("Setting1").Cells("Value").Value = "Value1"
存在一种使用.Value执行此操作的方法
For Each dr As DataGridViewRow In DataGridView1.Rows
Dim hashrow As String = hst("SQLServer")
Dim cellvalue As String = dr.Cells(hashrow).Value.ToString
values = values & "'" & cellvalue & "' , "
存在一种使用.Value执行此操作的方法
For Each dr As DataGridViewRow In DataGridView1.Rows
Dim hashrow As String = hst("SQLServer")
Dim cellvalue As String = dr.Cells(hashrow).Value.ToString
values = values & "'" & cellvalue & "' , "
它必须是一个整数。请看:它必须是一个整数。请看:您能再解释一下您的解决方案吗?当您有一个DataGridViewRow时,您可以使用Cells属性访问单个值,只需输入列的名称或该列的索引,如dr.Cells('Column1')。value.ToString您能再解释一下您的解决方案吗,请?当您拥有DataGridViewRow时,您可以使用Cells属性访问单个值,只需输入列的名称或该列的索引,如dr.Cells('Column1')。value.ToString