我正试图初始化一个检查器,该检查器检查datagridview中特定列的单元格,如果该单元格等于StaffMixname
,则按钮文本应为VIEW
;否则,按钮文本为LOCKED
到目前为止,这是我的代码。
Dim dgButtonColumn As New DataGridViewButtonColumn
Dim i As Integer
MetroGrid7.Columns.Add(dgButtonColumn)
dgButtonColumn.HeaderText = "Security"
dgButtonColumn.UseColumnTextForButtonValue = True
For i = 0 To MetroGrid7.Rows.Count
If MetroGrid7.Rows(i).Cells.Item(4).Value.ToString() = StaffMixname.Text Then
dgButtonColumn.Text = "VIEW"
dgButtonColumn.Name = "viewBtn"
dgButtonColumn.ToolTipText = "View"
Else
dgButtonColumn.Text = "LOCKED"
dgButtonColumn.Name = "searchSecurityBtn"
dgButtonColumn.ToolTipText = "LOCKED"
End If
Next
答案 0 :(得分:1)
它不能像这样工作。在DataGridViewButtonColumn
中,每个单元格都包含一个button
,但您不能访问它。您可以获取DataGridViewButtonCell
并更改这两个属性value and ToolTipText
。 name
中没有DataGridViewButtonCell
属性。所以要更改它们:
Dim dgButtonColumn As New DataGridViewButtonColumn
Dim i As Integer
MetroGrid7.Columns.Add(dgButtonColumn)
dgButtonColumn.HeaderText = "Security"
'remove this line
'dgButtonColumn.UseColumnTextForButtonValue = True
For i = 0 To MetroGrid7.Rows.Count
If MetroGrid7.Rows(i).Cells.Item(4).Value.ToString() = StaffMixname.Text Then
MetroGrid7.Rows(i).Cells.Item(6).Value = "VIEW"
MetroGrid7.Rows(i).Cells.Item(6).ToolTipText = "View"
Else
MetroGrid7.Rows(i).Cells.Item(6).Value = "LOCKED"
MetroGrid7.Rows(i).Cells.Item(6).ToolTipText = "LOCKED"
End If
Next
答案 1 :(得分:0)
Dim status As String
status = status & Me.dgTitleList.CurrentRow.Cells("BDO").Value
status = status & Chr(13)
将Value
Datagridview
的{{1}}插入Column
并满足条件。
String
我建议使用BreakPoint并检查If status = StaffMixname.Text Then
dgButtonColumn.Text = "VIEW"
dgButtonColumn.Name = "viewBtn"
dgButtonColumn.ToolTipText = "View"
Else
dgButtonColumn.Text = "LOCKED"
dgButtonColumn.Name = "searchSecurityBtn"
dgButtonColumn.ToolTipText = "LOCKED"
End If
是否具有StaffMixName.Text
。