VB.NET中手动添加到DataGridView的行为何会出现空单元格?

2026-05-06 11:491阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计243个文字,预计阅读时间需要1分钟。

VB.NET中手动添加到DataGridView的行为何会出现空单元格?

这有效:`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)

整行都是空的.

为什么排满了空单元格?

VB.NET中手动添加到DataGridView的行为何会出现空单元格?

您的newrow变量没有任何单元格,SetValues忽略您的信息,因为没有任何单元格要设置值.

从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分钟。

VB.NET中手动添加到DataGridView的行为何会出现空单元格?

这有效:`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)

整行都是空的.

为什么排满了空单元格?

VB.NET中手动添加到DataGridView的行为何会出现空单元格?

您的newrow变量没有任何单元格,SetValues忽略您的信息,因为没有任何单元格要设置值.

从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})