簡體   English   中英

在Datagridview控件中驗證/禁用日歷列的日期

[英]Validation/disabling dates of Calendar Column in Datagridview control

您能否建議在datagridview控件中禁用“日歷”列中的日期。以下是要求

 -> User is not allowed to select a date which is less than today's date and the next 1 month dates. Example - Today's Date - **Sep 12th 2014** Now all the dates less than Sep12th,2014 are disabled and the dates till **Oct12,2014** ie till next month are disabled. So user is allowed to select the dates only after Oct12th,2014. --> When the calendar column is added to the Datagrid..it must already show the dates from next month.As per above example from 

2014年10月13日。

您能否就我如何實現這一目標提出建議。

謝謝,Prathap

希望這會幫助您入門。 我設置了一個datagridview,其中一個名為“ Date”的列在每一行中列出了不同的日期。 為了弄清楚要設置為只讀的日期,我使用以下代碼:

Dim myDate As Date = Date.Today
Dim rowNumber As Integer = 0
Dim rowDate As Date = Nothing
Dim enabledDate As Date = myDate.AddDays(30)

Do Until rowDate = enabledDate
    rowDate = DataGridView1.Rows(rowNumber).Cells(0).Value

    If rowDate < enabledDate Then
        DataGridView1.Rows(rowNumber).Cells(0).ReadOnly = True
        DataGridView1.Rows(rowNumber).Cells(0).Style.ForeColor = Color.Gray
    Else
        DataGridView1.Rows(rowNumber).Cells(0).ReadOnly = False
        DataGridView1.Rows(rowNumber).Cells(0).Style.ForeColor = Color.Black
    End If

    rowNumber = rowNumber + 1
Loop

設置方式雖然您需要根據當月的月份用不同的值填充“ enabledDate”。 對於本月,您將增加30天,但下個月將需要31天。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM