VB.NET中手动添加到DataGridView的行为何会出现空单元格?
- 内容介绍
- 文章标签
- 相关推荐
本文共计243个文字,预计阅读时间需要1分钟。
这有效:`DataGridView.Rows.Add(Bla Bla Bla, value1, value2)`。但若这样操作:`Dim newrow As New DataGridViewRow newrow.SetValues(Bla Bla Bla, value1, value2) If Not value1.Equals(value2) Then newrow.DefaultCellStyle.ForeColor=颜色代码`
这有效:DataGridView.Rows.Add("Bla Bla Bla", value1, value2)
但如果我这样做:
Dim newrow As New DataGridViewRow newrow.SetValues("Bla Bla Bla", value1, value2) If Not value1.Equals(value2) Then newrow.DefaultCellStyle.ForeColor = Color.Red End If DataGridView.Rows.Add(newrow)
整行都是空的.
为什么排满了空单元格?
从DataGridViewRow.SetValues Method开始:
If there are more values in the values list than there are cells to be initialized, this method ignores the extra values and returns false. This method also returns false if any of the specified values cannot be set.
If there are fewer values than there are cells, the remaining unmatched cells retain their current values.
使用CreateCells方法填充单元格:
newrow.CreateCells(DataGridView) '' or newrow.CreateCells(DataGridView, New Object() {"Bla Bla Bla", value1, value2})
本文共计243个文字,预计阅读时间需要1分钟。
这有效:`DataGridView.Rows.Add(Bla Bla Bla, value1, value2)`。但若这样操作:`Dim newrow As New DataGridViewRow newrow.SetValues(Bla Bla Bla, value1, value2) If Not value1.Equals(value2) Then newrow.DefaultCellStyle.ForeColor=颜色代码`
这有效:DataGridView.Rows.Add("Bla Bla Bla", value1, value2)
但如果我这样做:
Dim newrow As New DataGridViewRow newrow.SetValues("Bla Bla Bla", value1, value2) If Not value1.Equals(value2) Then newrow.DefaultCellStyle.ForeColor = Color.Red End If DataGridView.Rows.Add(newrow)
整行都是空的.
为什么排满了空单元格?
从DataGridViewRow.SetValues Method开始:
If there are more values in the values list than there are cells to be initialized, this method ignores the extra values and returns false. This method also returns false if any of the specified values cannot be set.
If there are fewer values than there are cells, the remaining unmatched cells retain their current values.
使用CreateCells方法填充单元格:
newrow.CreateCells(DataGridView) '' or newrow.CreateCells(DataGridView, New Object() {"Bla Bla Bla", value1, value2})

