|
-
Mar 13th, 2004, 05:28 AM
#1
Thread Starter
Lively Member
DatagridColumnStyle - Datetime Picker
Good day.
I have studied through the Windows Forms FAQ (http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp ) and try to use the sample code provided for data-bounded DatagridComboboxStyle.
I have tried to change the code to create a DatagridDatetimePickerStyle.
But, if I add the column style to the datagrid, all the data of the column will be set to the date value of the datetimepicker, instead of the value from the database.
Can anyone tell me what's going on here ?
Thanks.
SonicWave
P/s: the code of the class for DatagridDatetimePickerStyle is as below.
DatagridDatePickerColumn.vb
-----------------------------------------------
Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Windows.Forms
Namespace DatagridDatePicker
Public Class DatagridDatePickerColumn
Inherits DataGridTextBoxColumn
Public ColumnDatePicker As DatagridDatePicker
Private _source As System.Windows.Forms.CurrencyManager
Private _rowNum As Integer
Private _isEditing As Boolean
Public Shared _RowCount As Integer
Public Sub New()
_source = Nothing
_isEditing = False
_RowCount = -1
ColumnDatePicker = New DatagridDatePicker
AddHandler ColumnDatePicker.ValueChanged, AddressOf LeaveDatePicker
AddHandler ColumnDatePicker.DropDown, AddressOf DatePickerStartEditing
End Sub
Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs)
If ColumnDatePicker.Visible Then
ColumnDatePicker.Hide()
End If
End Sub
Private Sub DatePickerStartEditing(ByVal sender As Object, ByVal e As EventArgs)
_isEditing = True
MyBase.ColumnStartedEditing(sender)
End Sub
Private Sub LeaveDatePicker(ByVal sender As Object, ByVal e As EventArgs)
If _isEditing Then
SetColumnValueAtRow(_source, _rowNum, ColumnDatePicker.Value)
_isEditing = False
Invalidate()
End If
ColumnDatePicker.Hide()
AddHandler Me.DataGridTableStyle.DataGrid.Scroll, New EventHandler(AddressOf HandleScroll)
End Sub
Protected Overrides Sub Abort(ByVal rowNum As Integer)
End Sub
Protected Overrides Function Commit(ByVal dataSource As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
If _isEditing Then
_isEditing = False
SetColumnValueAtRow(dataSource, rowNum, ColumnDatePicker.Text)
End If
Return True
End Function
Protected Overloads Overrides Sub Edit(ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
MyBase.Edit([source], rowNum, bounds, [readOnly], instantText, cellIsVisible)
_rowNum = rowNum
_source = [source]
ColumnDatePicker.Parent = Me.TextBox.Parent
ColumnDatePicker.Location = Me.TextBox.Location
ColumnDatePicker.Size = New Size(Me.TextBox.Size.Width, ColumnDatePicker.Size.Height)
ColumnDatePicker.Value = Me.TextBox.Text
Me.TextBox.Visible = False
ColumnDatePicker.Visible = True
AddHandler Me.DataGridTableStyle.DataGrid.Scroll, AddressOf HandleScroll
ColumnDatePicker.BringToFront()
ColumnDatePicker.Focus()
End Sub
Protected Overrides Function GetMinimumHeight() As Integer
End Function
Protected Overrides Function GetPreferredHeight(ByVal g As System.Drawing.Graphics, ByVal value As Object) As Integer
End Function
Protected Overrides Function GetPreferredSize(ByVal g As System.Drawing.Graphics, ByVal value As Object) As System.Drawing.Size
End Function
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer)
End Sub
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal alignToRight As Boolean)
End Sub
Protected Overrides Sub ConcedeFocus()
Console.WriteLine("ConcedeFocus")
MyBase.ConcedeFocus()
End Sub
Protected Overrides Function GetColumnValueAtRow(ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object
Dim s As Object = MyBase.GetColumnValueAtRow([source], rowNum)
Return Me.ColumnDatePicker.Value
End Function
Protected Overrides Sub SetColumnValueAtRow(ByVal [source] As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal value As Object)
Dim s As Object = value
s = Me.ColumnDatePicker.Value
MyBase.SetColumnValueAtRow([source], rowNum, s)
End Sub
End Class
End Namespace
FOrm1.vb
--------------
Dim DatePickerCol As New DatagridDatePickerColumn
DatePickerCol.MappingName = dt.Columns(i).ColumnName
DatePickerCol.HeaderText = dt.Columns(i).ColumnName
tableStyle.PreferredRowHeight = DatePickerCol.ColumnDatePicker.Height + 2
tableStyle.GridColumnStyles.Add(DatePickerCol)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|