نمایش نتایج 1 تا 4 از 4

نام تاپیک: نحوه جلوگیری کردن از خالی بودن یک سلول

  1. #1

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

    سلام به دوستان
    موقعی که کاربر دارد مقادیری را داخل سلولهای DataGridView تایپ می کند اگر یکی از سلول ها را پر نکرد از چه کدی باید استفاده کرد که فوکوس از روی آن سلول به سلول دیگری نرود و رو همان سلول خالی بماند تا موقعی که کاربر مقداری را وارد کند

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

  2. #2
    از رویداد CellValidating و پارامتر e آن رویداد استفاده کنید. با قرار دادن e.Cancel به مقدارهای false و True

  3. #3
    نقل قول نوشته شده توسط hassan razavi مشاهده تاپیک
    از رویداد CellValidating و پارامتر e آن رویداد استفاده کنید. با قرار دادن e.Cancel به مقدارهای false و True
    من این کاری که شما گفتید رو انجام دادم ولی با اینکه یه سلول رو پر می کنم بازم نمی تونم به سلول بعدی برم

  4. #4
    کاربر دائمی آواتار ali_md110
    تاریخ عضویت
    فروردین 1385
    محل زندگی
    شیراز
    پست
    1,181
    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

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •