0

如果用户在我的 datagridview 中将单元格留空,我需要找到一种方法来提供默认值。现在,如果用户将单元格留空,我可以显示错误消息,但我还想在消息弹出后在单元格中插入默认文本。例如,如果单元格需要名称并且用户将其留空,则会弹出一条消息并告诉用户他/她不能将名称留空。在此之后,我希望文本“名称”填充单元格

If (e.ColumnIndex = 0) Then 'checking numeric value for column 1 only
Dim cellData = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
 if cellData Is Nothing OrElse IsDBNull(cellData) OrElse cellData.ToString = String.Empty Then       
   MessageBox.Show("Please Enter a Value")
   Exit Sub

万一

4

2 回答 2

2

尝试:

DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = "default value"
于 2013-06-19T01:53:49.697 回答
0

将默认值传递给 DatagridView 空单元格:

For k As Integer = 0 To DataGridView1.Rows.Count - 1

    For l = 0 To DataGridView1.ColumnCount - 1

        Dim cellData = DataGridView1.Rows(k).Cells(l).Value
        If cellData Is Nothing OrElse IsDBNull(cellData) OrElse cellData.ToString = String.Empty Then
            DataGridView1.Rows(k).Cells(l).Value = "0"
        End If

    Next

Next
于 2013-09-26T11:52:49.887 回答