作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 DataGridViewTextBoxColumn,它包含不同类型的 DataGridViewCells(组合框、文本和按钮)。
这是我构建 datagridview 行的方法:
Public Shared Function BuildDgvRow(ByVal tq As clsTabsQuestion) As DataGridViewRow
Dim Row As New DataGridViewRow
Dim ComboBoxCell As New DataGridViewComboBoxCell
Dim CellBtn As New DataGridViewButtonCell //File Upload
Dim CellTxtQ As New DataGridViewTextBoxCell //Cell question
Dim CellTxt As New DataGridViewTextBoxCell //Cell txt
CellTxtQ = New DataGridViewTextBoxCell
//Build row
With Row
//Add cell that will contain question
.Cells.Add(CellTxtQ)
//Add CheckBox / Button / Text to the other cell that will contain the answer
Select Case tq.sType
Case "YesNo"
ComboBoxCell = New DataGridViewComboBoxCell()
ComboBoxCell.Items.AddRange(New String() {"Yes", "No", "N/A"})
.Cells.Add(ComboBoxCell)
Case "FileUpload"
CellBtn = New DataGridViewButtonCell
.Cells.Add(CellBtn)
Case "Text"
CellTxt = New DataGridViewTextBoxCell
.Cells.Add(CellTxt)
End Select
//Set row values
.SetValues({tq.Title, ""})
.Tag = tq
End With
Return Row
End Function
最佳答案
经过进一步调查,我发现了我的问题......当我尝试使用 CellBtn.Value
时我忘了我正在将行值重置为空字符串。傻我。
这是我解决它的方法(两种方式)
使用 DataGridViewButtonCell.Value 设置文本
Public Shared Function BuildDgvRow(ByVal tq As clsTabsQuestion) As DataGridViewRow
Dim Row As New DataGridViewRow
Dim ComboBoxCell As New DataGridViewComboBoxCell
Dim CellBtn As New DataGridViewButtonCell //File Upload
Dim CellTxtQ As New DataGridViewTextBoxCell //Cell question
Dim CellTxt As New DataGridViewTextBoxCell //Cell txt
CellTxtQ = New DataGridViewTextBoxCell
//Build row
With Row
//Add cell that will contain question
.Cells.Add(CellTxtQ)
//Add CheckBox / Button / Text to the other cell that will contain the answer
Select Case tq.sType
Case "YesNo"
ComboBoxCell = New DataGridViewComboBoxCell()
ComboBoxCell.Items.AddRange(New String() {"Yes", "No", "N/A"})
.Cells.Add(ComboBoxCell)
Case "FileUpload"
CellBtn = New DataGridViewButtonCell
CellBtn.Value = "ASdasdwd"
.SetValues({tq.Title, CellBtn.Value})
.Cells.Add(CellBtn)
Case "Text"
CellTxt = New DataGridViewTextBoxCell
.Cells.Add(CellTxt)
End Select
//Set values
If tq.sType <> "FileUpload" Then .SetValues({tq.Title, ""})
.Tag = tq
End With
Return Row
End Function
Public Shared Function BuildDgvRow(ByVal tq As clsTabsQuestion) As DataGridViewRow
Dim Row As New DataGridViewRow
Dim ComboBoxCell As New DataGridViewComboBoxCell
Dim CellBtn As New DataGridViewButtonCell //File Upload
Dim CellTxtQ As New DataGridViewTextBoxCell //Cell question
Dim CellTxt As New DataGridViewTextBoxCell //Cell txt
CellTxtQ = New DataGridViewTextBoxCell
//Build row
With Row
//Add cell that will contain question
.Cells.Add(CellTxtQ)
//Add CheckBox / Button / Text to the other cell that will contain the answer
Select Case tq.sType
Case "YesNo"
ComboBoxCell = New DataGridViewComboBoxCell()
ComboBoxCell.Items.AddRange(New String() {"Yes", "No", "N/A"})
.Cells.Add(ComboBoxCell)
Case "FileUpload"
CellBtn = New DataGridViewButtonCell
.Cells.Add(CellBtn)
Case "Text"
CellTxt = New DataGridViewTextBoxCell
.Cells.Add(CellTxt)
End Select
//Set values
If tq.sType = "FileUpload" Then .SetValues({tq.Title, "Upload"}) Else .SetValues({tq.Title, ""})
.Tag = tq
End With
Return Row
End Function
关于vb.net - 如何在具有多个控件的列中设置 DataGridViewButtonCell 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18293458/
我需要将我的 DataGridViewButtonCell 添加到 Column 中,并且我需要用不同的名称互相命名。 但我没有找到任何文本属性。 有人能帮帮我吗? 我做那些事 DataGridVie
我有一个 DataGridViewTextBoxColumn,它包含不同类型的 DataGridViewCells(组合框、文本和按钮)。 这是我构建 datagridview 行的方法: Publi
我正在开发一个使用 DataGridView 控件的 Windows 窗体应用程序。此 DataGridView 有一个包含按钮的单元格。默认按钮文本是 Start 但当我尝试动态更改它时,如: ((
我是一名优秀的程序员,十分优秀!