26. DataGridView@H_404_7@单元格数据错误标签表示@H_404_7@
27. DataGridView@H_404_7@单元格内输入值正确性判断@H_404_7@
28. DataGridView@H_404_7@单元格输入错误值事件的捕获@H_404_7@@H_404_7@
@H_404_7@
26. DataGridView@H_404_7@单元格数据错误标签表示@H_404_7@@H_404_7@@H_404_7@
@H_404_7@
VB.NET]@H_404_7@
'(0,0)@H_404_7@のセルにエラーアイコンを表示する@H_404_7@
DataGridView1(0,0).ErrorText = "@H_404_7@セルの値を確認してください。@H_404_7@"@H_404_7@
'@H_404_7@インデックスが@H_404_7@3@H_404_7@の行にエラーアイコンを表示する@H_404_7@
DataGridView1.Rows(3).ErrorText = "@H_404_7@負の値は入力できません。@H_404_7@"@H_404_7@
[C#]@H_404_7@
//(0,0)@H_404_7@のセルにエラーアイコンを表示する@H_404_7@
DataGridView1[0,0].ErrorText = "@H_404_7@セルの値を確認してください。@H_404_7@";@H_404_7@
//@H_404_7@インデックスが@H_404_7@3@H_404_7@の行にエラーアイコンを表示する@H_404_7@
DataGridView1.Rows[3].ErrorText = "@H_404_7@負の値は入力できません。@H_404_7@";@H_404_7@
在大量单元格需要错误提示时,也可以用@H_404_7@CellErrorTextNeeded@H_404_7@、@H_404_7@RowErrorTextNeeded@H_404_7@事件@H_404_7@
[VB.NET]@H_404_7@
'CellErrorTextNeeded@H_404_7@イベントハンドラ@H_404_7@
Private Sub DataGridView1_CellErrorTextNeeded(ByVal sender As Object,_@H_404_7@
@H_404_7@ByVal e As DataGridViewCellErrorTextNeededEventArgs) _@H_404_7@
@H_404_7@Handles DataGridView1.CellErrorTextNeeded@H_404_7@
@H_404_7@Dim dgv As DataGridView = CType(sender,DataGridView)@H_404_7@
@H_404_7@'@H_404_7@セルの値が負の整数であれば、エラーアイコンを表示する@H_404_7@
@H_404_7@Dim cellVal As Object = dgv(e.ColumnIndex,e.RowIndex).Value@H_404_7@
@H_404_7@If TypeOf cellVal Is Integer AndAlso CInt(cellVal) < 0 Then@H_404_7@
@H_404_7@e.ErrorText = "@H_404_7@負の整数は入力できません。@H_404_7@"@H_404_7@
End Sub@H_404_7@
'RowErrorTextNeeded@H_404_7@イベントハンドラ@H_404_7@
Private Sub DataGridView1_RowErrorTextNeeded(ByVal sender As Object,_@H_404_7@
@H_404_7@ByVal e As DataGridViewRowErrorTextNeededEventArgs) _@H_404_7@
@H_404_7@Handles DataGridView1.RowErrorTextNeeded@H_404_7@
@H_404_7@Dim dgv As DataGridView = CType(sender,DataGridView)@H_404_7@
@H_404_7@If dgv("Column1",e.RowIndex).Value Is DBNull.Value AndAlso _@H_404_7@
@H_404_7@dgv("Column2",e.RowIndex).Value Is DBNull.Value Then@H_404_7@
@H_404_7@e.ErrorText = _@H_404_7@
@H_404_7@"@H_404_7@少なくとも@H_404_7@Column1@H_404_7@と@H_404_7@Column2@H_404_7@のどちらかには値を入力してください。@H_404_7@"@H_404_7@
End Sub@H_404_7@
[C#]@H_404_7@
//CellErrorTextNeeded@H_404_7@イベントハンドラ@H_404_7@
private void DataGridView1_CellErrorTextNeeded(object sender,@H_404_7@
@H_404_7@DataGridViewCellErrorTextNeededEventArgs e)@H_404_7@
{@H_404_7@
@H_404_7@DataGridView dgv = (DataGridView)sender;@H_404_7@
@H_404_7@//@H_404_7@セルの値が負の整数であれば、エラーアイコンを表示する@H_404_7@
@H_404_7@object cellVal = dgv[e.ColumnIndex,e.RowIndex].Value;@H_404_7@
@H_404_7@if (cellVal is int && ((int)cellVal) < 0)@H_404_7@
@H_404_7@e.ErrorText = "@H_404_7@負の整数は入力できません。@H_404_7@";@H_404_7@
}@H_404_7@
//RowErrorTextNeeded@H_404_7@イベントハンドラ@H_404_7@
private void DataGridView1_RowErrorTextNeeded(object sender,@H_404_7@
@H_404_7@DataGridViewRowErrorTextNeededEventArgs e)@H_404_7@
{@H_404_7@
@H_404_7@DataGridView dgv = (DataGridView)sender;@H_404_7@
@H_404_7@if (dgv["Column1",e.RowIndex].Value == DBNull.Value &&@H_404_7@
@H_404_7@dgv["Column2",e.RowIndex].Value == DBNull.Value)@H_404_7@
@H_404_7@@H_404_7@e.ErrorText = @H_404_7@
@H_404_7@"@H_404_7@少なくとも@H_404_7@Column1@H_404_7@と@H_404_7@Column2@H_404_7@のどちらかには値を入力してください。@H_404_7@";@H_404_7@
}@H_404_7@
27. DataGridView@H_404_7@单元格内输入值正确性判断@H_404_7@@H_404_7@@H_404_7@
[VB.NET]@H_404_7@
'CellValidating@H_404_7@イベントハンドラ@H_404_7@
Private Sub DataGridView1_CellValidating(ByVal sender As Object,_@H_404_7@
@H_404_7@ByVal e As DataGridViewCellValidatingEventArgs) _@H_404_7@
@H_404_7@Handles DataGridView1.CellValidating@H_404_7@
@H_404_7@Dim dgv As DataGridView = CType(sender,DataGridView)@H_404_7@
@H_404_7@If dgv.Columns(e.ColumnIndex).Name = "Column1" AndAlso _@H_404_7@
@H_404_7@e.FormattedValue.ToString() = "" Then@H_404_7@
@H_404_7@'@H_404_7@行にエラーテキストを設定@H_404_7@
@H_404_7@dgv.Rows(e.RowIndex).ErrorText = "@H_404_7@値が入力されていません。@H_404_7@"@H_404_7@
@H_404_7@'@H_404_7@入力した値をキャンセルして元に戻すには、次のようにする@H_404_7@
@H_404_7@'dgv.CancelEdit()@H_404_7@
@H_404_7@'@H_404_7@キャンセルする@H_404_7@
@H_404_7@e.Cancel = True@H_404_7@
End Sub@H_404_7@
'CellValidated@H_404_7@イベントハンドラ@H_404_7@
Private Sub DataGridView1_CellValidated(ByVal sender As Object,_@H_404_7@
@H_404_7@ByVal e As DataGridViewCellEventArgs) _@H_404_7@
@H_404_7@Handles DataGridView1.CellValidated@H_404_7@
@H_404_7@Dim dgv As DataGridView = CType(sender,DataGridView)@H_404_7@
@H_404_7@'@H_404_7@エラーテキストを消す@H_404_7@
@H_404_7@dgv.Rows(e.RowIndex).ErrorText = Nothing@H_404_7@
End Sub@H_404_7@
[C#]@H_404_7@
//CellValidating@H_404_7@イベントハンドラ@H_404_7@
private void DataGridView1_CellValidating(object sender,@H_404_7@
@H_404_7@DataGridViewCellValidatingEventArgs e)@H_404_7@
{@H_404_7@
@H_404_7@DataGridView dgv = (DataGridView)sender;@H_404_7@
@H_404_7@if (dgv.Columns[e.ColumnIndex].Name == "Column1" &&@H_404_7@
@H_404_7@e.FormattedValue.ToString() == "")@H_404_7@
@H_404_7@//@H_404_7@行にエラーテキストを設定@H_404_7@
@H_404_7@dgv.Rows[e.RowIndex].ErrorText = "@H_404_7@値が入力されていません。@H_404_7@";@H_404_7@
@H_404_7@//@H_404_7@入力した値をキャンセルして元に戻すには、次のようにする@H_404_7@
@H_404_7@//dgv.CancelEdit();@H_404_7@
@H_404_7@//@H_404_7@キャンセルする@H_404_7@
@H_404_7@e.Cancel = true;@H_404_7@
}@H_404_7@
//CellValidated@H_404_7@イベントハンドラ@H_404_7@
private void DataGridView1_CellValidated(object sender,@H_404_7@
@H_404_7@DataGridViewCellEventArgs e)@H_404_7@
{@H_404_7@
@H_404_7@DataGridView dgv = (DataGridView)sender;@H_404_7@
@H_404_7@//@H_404_7@エラーテキストを消す@H_404_7@
@H_404_7@dgv.Rows[e.RowIndex].ErrorText = null;@H_404_7@
}@H_404_7@
28. DataGridView@H_404_7@单元格输入错误值事件的捕获@H_404_7@@H_404_7@@H_404_7@
[VB.NET]@H_404_7@
'DataError@H_404_7@イベントハンドラ@H_404_7@
Private Sub DataGridView1_DataError(ByVal sender As Object,_@H_404_7@
@H_404_7@ByVal e As DataGridViewDataErrorEventArgs) _@H_404_7@
@H_404_7@Handles DataGridView1.DataError@H_404_7@
@H_404_7@If Not (e.Exception Is Nothing) Then@H_404_7@
@H_404_7@MessageBox.Show(Me,_@H_404_7@
@H_404_7@String.Format("({0},{1}) @H_404_7@のセルでエラーが発生しました。@H_404_7@" + _@H_404_7@
@H_404_7@vbCrLf + vbCrLf + "@H_404_7@説明@H_404_7@: {2}",_@H_404_7@
@H_404_7@e.ColumnIndex,e.RowIndex,e.Exception.Message),_@H_404_7@
@H_404_7@"@H_404_7@エラーが発生しました@H_404_7@",_@H_404_7@
@H_404_7@MessageBoxButtons.OK,_@H_404_7@
@H_404_7@MessageBoxIcon.Error)@H_404_7@
End Sub@H_404_7@
[C#]@H_404_7@
//DataError@H_404_7@イベントハンドラ@H_404_7@
private void DataGridView1_DataError(object sender,@H_404_7@
@H_404_7@DataGridViewDataErrorEventArgs e)@H_404_7@
{@H_404_7@
@H_404_7@if (e.Exception != null)@H_404_7@
@H_404_7@MessageBox.Show(this,@H_404_7@
@H_404_7@string.Format("({0},{1}) @H_404_7@のセルでエラーが発生しました。@H_404_7@/n/n@H_404_7@説明@H_404_7@: {2}",@H_404_7@
@H_404_7@e.ColumnIndex,@H_404_7@
@H_404_7@"@H_404_7@エラーが発生しました@H_404_7@",@H_404_7@
@H_404_7@MessageBoxButtons.OK,MessageBoxIcon.Error);@H_404_7@
}@H_404_7@
[VB.NET]@H_404_7@
'DataError@H_404_7@イベントハンドラ@H_404_7@
Private Sub DataGridView1_DataError(ByVal sender As Object,_@H_404_7@
@H_404_7@ByVal e As DataGridViewDataErrorEventArgs) _@H_404_7@
@H_404_7@Handles DataGridView1.DataError@H_404_7@
@H_404_7@e.Cancel = False@H_404_7@
End Sub@H_404_7@
[C#]@H_404_7@
//DataError@H_404_7@イベントハンドラ@H_404_7@
private void DataGridView1_DataError(object sender,@H_404_7@
@H_404_7@DataGridViewDataErrorEventArgs e)@H_404_7@
{@H_404_7@
@H_404_7@e.Cancel = false;@H_404_7@
}@H_404_7@