本身没有附加日期控件,需要在窗体上增加一个日期控件
具体代码
Private Sub C1TrueDBGrid1_RowColChange(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.RowColChangeEventArgs) Handles C1TrueDBGrid1.RowColChange
' position the datetime picker on the "BirthDate" column only
Dim col As C1.Win.C1TrueDBGrid.C1DataColumn = Me.c1TrueDBGrid1.Splits(0).DisplayColumns(Me.c1TrueDBGrid1.Col).DataColumn
If col.DataField = "BirthDate" Then
' get the area of the cell
Dim r As Rectangle = Me.c1TrueDBGrid1.Splits(0).GetCellBounds(Me.c1TrueDBGrid1.Row, Me.c1TrueDBGrid1.Col)
' change to screen coordiantes
r = Me.c1TrueDBGrid1.RectangleToScreen(r)
' map the screen coordinates to the forms client coordinates
Me.dateTimePicker1.Location = Me.RectangleToClient(r).Location
' size it to fit inside the cell
Me.dateTimePicker1.Size = r.Size
' default the dateTimePicker to the date in the cell
Me._bIgnoreChange = True
Me.DateTimePicker1.Value = col.CellValue(Me.C1TrueDBGrid1.Row)
Me._bIgnoreChange = False
' display it
Me.dateTimePicker1.Visible = True
Else
Me.dateTimePicker1.Visible = False
End If
End Sub
' update the grid with the users selection
Private Sub DateTimePicker1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.TextChanged
If Me._bIgnoreChange Then
Exit Sub
End If
' get the column
Dim col As C1.Win.C1TrueDBGrid.C1DataColumn = Me.C1TrueDBGrid1.Splits(0).DisplayColumns(Me.C1TrueDBGrid1.Col).DataColumn
' update the the grid
col.Text = Me.DateTimePicker1.Text
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.OleDbDataAdapter1.Fill(Me.DataSet11)
' set the grid's row height to the height of the dateTimePicker
Me.C1TrueDBGrid1.RowHeight = Me.DateTimePicker1.Height
End Sub
上面的大哥,非常感谢,基本上可以实现了,可是datatimepick不在相应的列上,
If col.DataField = "BirthDate" Then 好象不能判断,它找不到相应的列,
另外Me._bIgnoreChange = True中的_bIgnoreChange是什么?在哪里定义的?多谢大哥了,我让c1可以自动加行,可不可以使需要的列的每行都可以象使用datatimepick一样?也就是怎么控制datatimepick的位置的变化?非常感谢大哥!!!