c# WinForm datagridview 在单元格输入时显示时间格式 : (00:00),其中":"为默认的,用户不需输入也不能删除,请问单元格如何设置?

解决方案 »

  1.   

    在单元格内格进行改变时进行有效性判断,了解一下datagridview的事件。
      

  2.   

    DataGridView1_CellFormatting事件里
    类似这样写:
    Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
            If DataGridView1.Columns(e.ColumnIndex).Name = "时间" Then     'Col1表示列名
                If e.Value IsNot DBNull.Value Then                e.Value = CDate(e.Value).ToLongTimeString
                End If        End If
        End Sub