PDA

View Full Version : نحوه جلوگیری کردن از خالی بودن یک سلول



amir_pro
شنبه 26 آبان 1386, 20:57 عصر
سلام به دوستان
موقعی که کاربر دارد مقادیری را داخل سلولهای DataGridView تایپ می کند اگر یکی از سلول ها را پر نکرد از چه کدی باید استفاده کرد که فوکوس از روی آن سلول به سلول دیگری نرود و رو همان سلول خالی بماند تا موقعی که کاربر مقداری را وارد کند

ممنون از دوستانی که پاسخ میدهند

hassan razavi
شنبه 26 آبان 1386, 22:12 عصر
از رویداد CellValidating و پارامتر e آن رویداد استفاده کنید. با قرار دادن e.Cancel به مقدارهای false و True

roya roya
سه شنبه 29 آبان 1386, 09:11 صبح
از رویداد CellValidating و پارامتر e آن رویداد استفاده کنید. با قرار دادن e.Cancel به مقدارهای false و True

من این کاری که شما گفتید رو انجام دادم ولی با اینکه یه سلول رو پر می کنم بازم نمی تونم به سلول بعدی برم

ali_md110
پنج شنبه 06 دی 1386, 12:06 عصر
Private Sub dg_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEve ntArgs) Handles dg.CellFormatting
Dim cell As Integer
Select Case dg.CurrentRow.Cells(cell).Selected
Case cell = 0
If CType(e.ColumnIndex, String).Length > 0 Then
dg.Rows(e.RowIndex).Cells(0).ErrorText = Nothing
End If
Case cell = 3
If CType(e.ColumnIndex, String).Length > 0 Then
dg.Rows(e.RowIndex).Cells(3).ErrorText = Nothing
End If
Case cell = 4
If CType(e.ColumnIndex, String).Length > 0 Then
dg.Rows(e.RowIndex).Cells(4).ErrorText = Nothing
End If

End Select
End Sub
===================================
یا از این کد
Dim cell As Integer
Select Case dg.CurrentRow.Cells(cell).Selected
Case cell = 0
' If dg.CurrentRow.Cells(0).Selected = True Then
If CType(e.FormattedValue, String).Length = 0 Then
dg.Rows(e.RowIndex).Cells(0).ErrorText = "انتخاب کنید"
'dg.EditMode = DataGridViewEditMode.EditOnEnter

dg.CurrentRow.Cells(0).Value = id_kala.ToString
'e.Cancel = True
ElseIf CType(e.FormattedValue, String).Length > 0 Then
e.Cancel = False
dg.Rows(e.RowIndex).Cells(0).ErrorText = Nothing
'dg.EditMode = DataGridViewEditMode.EditOnEnter
'frm.Close()
End If
Case cell = 3
If CType(e.FormattedValue, String).Length = 0 Then
dg.Rows(e.RowIndex).Cells(3).ErrorText = "انتخاب کنید"
ElseIf CType(e.FormattedValue, String).Length > 0 Then
e.Cancel = False
dg.Rows(e.RowIndex).Cells(3).ErrorText = Nothing
End If
Case cell = 4
If CType(e.FormattedValue, String).Length = 0 Then
dg.Rows(e.RowIndex).Cells(4).ErrorText = "انتخاب کنید"
ElseIf CType(e.FormattedValue, String).Length > 0 Then
e.Cancel = False
dg.Rows(e.RowIndex).Cells(4).ErrorText = Nothing
End If

End Select

'End If