Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ต้องการ DateTimePicker ใน Datagirdview vb 2010 ครับ



 

ต้องการ DateTimePicker ใน Datagirdview vb 2010 ครับ

 



Topic : 128390



โพสกระทู้ ( 122 )
บทความ ( 0 )



สถานะออฟไลน์




วันที่



Tag : .NET, VB.NET, VS 2010 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-07-27 12:00:43 By : outhai View : 879 Reply : 2
 

 

No. 1



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

Code (VB.NET)
Public Class DataGridViewDatetimepickerColumn
    Inherits System.Windows.Forms.DataGridViewColumn

    Public Sub New()
        MyBase.New(New DataGridViewDatetimepickerCell())
    End Sub
    Private _PickerFormat As System.Windows.Forms.DateTimePickerFormat = System.Windows.Forms.DateTimePickerFormat.[Long]
    ' [System.ComponentModel.DefaultValue(System.Windows.Forms.DateTimePickerFormat.Long)]
    <System.ComponentModel.Browsable(True)> _
    <System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)> _
    <System.ComponentModel.Category("Behavior")> _
    <System.ComponentModel.Description("Open Dialog is dispalyed and on success the contents of the Cell is replaced with the new  path.")> _
    Public Property PickerFormat() As System.Windows.Forms.DateTimePickerFormat
        Get
            Return _PickerFormat
        End Get
        Set(value As System.Windows.Forms.DateTimePickerFormat)
            _PickerFormat = value
        End Set
    End Property
    Public Overrides Function Clone() As Object
        Dim clm = TryCast(MyBase.Clone(), DataGridViewDatetimepickerColumn)
        Dim xxx As DataGridViewDatetimepickerColumn = TryCast(MyBase.Clone(), DataGridViewDatetimepickerColumn)
        If clm IsNot Nothing Then
            clm.PickerFormat = _PickerFormat
        End If
        Return clm

    End Function
    Public Overrides Property CellTemplate() As System.Windows.Forms.DataGridViewCell
        Get
            Return MyBase.CellTemplate
        End Get

        Set(value As System.Windows.Forms.DataGridViewCell)
            If (value IsNot Nothing) AndAlso Not value.[GetType]().IsAssignableFrom(GetType(DataGridViewDatetimepickerCell)) Then
                Throw New InvalidCastException("Must be a DataGridViewDatetimepickerCell")
            End If
            MyBase.CellTemplate = value
        End Set
    End Property

End Class

Public Class DataGridViewDatetimepickerCell
    Inherits System.Windows.Forms.DataGridViewTextBoxCell

    Public Sub New()
    End Sub

    Public Overrides Sub InitializeEditingControl(rowIndex As Integer, initialFormattedValue As Object, dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle)
        ' Set the value of the editing control to the current cell value.
        MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)

        Dim ctl As CalendarEditingControl = DirectCast(DataGridView.EditingControl, CalendarEditingControl)

        If (Not Object.ReferenceEquals(Me.Value, DBNull.Value)) Then
            If (Me.Value IsNot Nothing) Then
                ctl.Value = DirectCast(Me.Value, DateTime)
            End If
        End If
        Dim fileColumn As DataGridViewDatetimepickerColumn = DirectCast(Me.DataGridView.Columns(ColumnIndex), DataGridViewDatetimepickerColumn)
        ctl.Format = fileColumn.PickerFormat
    End Sub

    Public Overrides ReadOnly Property EditType() As Type
        ' Return the type of the editing contol that DataGridViewDatetimepickerCell uses.
        Get
            Return GetType(CalendarEditingControl)
        End Get
    End Property

    Public Overrides ReadOnly Property ValueType() As Type
        ' Return the type of the value that DataGridViewDatetimepickerCell contains.
        Get
            Return GetType(DateTime)
        End Get
    End Property
End Class




Public Class CalendarEditingControl
    Inherits DateTimePicker
    Implements IDataGridViewEditingControl

    Private dataGridViewControl As DataGridView
    Private valueIsChanged As Boolean = False
    Private rowIndexNum As Integer

    Public Sub New()
        Me.Format = DateTimePickerFormat.Short
    End Sub

    Public Property EditingControlFormattedValue() As Object _
        Implements IDataGridViewEditingControl.EditingControlFormattedValue

        Get
            Return Me.Value.ToShortDateString()
        End Get

        Set(ByVal value As Object)
            Try
                ' This will throw an exception of the string is 
                ' null, empty, or not in the format of a date.
                Me.Value = DateTime.Parse(CStr(value))
            Catch
                ' In the case of an exception, just use the default
                ' value so we're not left with a null value.
                Me.Value = DateTime.Now
            End Try
        End Set

    End Property

    Public Function GetEditingControlFormattedValue(ByVal context _
        As DataGridViewDataErrorContexts) As Object _
        Implements IDataGridViewEditingControl.GetEditingControlFormattedValue

        Return Me.Value.ToShortDateString()

    End Function

    Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As  _
        DataGridViewCellStyle) _
        Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl

        Me.Font = dataGridViewCellStyle.Font
        Me.CalendarForeColor = dataGridViewCellStyle.ForeColor
        Me.CalendarMonthBackground = dataGridViewCellStyle.BackColor

    End Sub

    Public Property EditingControlRowIndex() As Integer _
        Implements IDataGridViewEditingControl.EditingControlRowIndex

        Get
            Return rowIndexNum
        End Get
        Set(ByVal value As Integer)
            rowIndexNum = value
        End Set

    End Property

    Public Function EditingControlWantsInputKey(ByVal key As Keys, _
        ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
        Implements IDataGridViewEditingControl.EditingControlWantsInputKey

        ' Let the DateTimePicker handle the keys listed.
        Select Case key And Keys.KeyCode
            Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
                Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp

                Return True

            Case Else
                Return Not dataGridViewWantsInputKey
        End Select

    End Function

    Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _
        Implements IDataGridViewEditingControl.PrepareEditingControlForEdit

        ' No preparation needs to be done.

    End Sub

    Public ReadOnly Property RepositionEditingControlOnValueChange() _
        As Boolean Implements _
        IDataGridViewEditingControl.RepositionEditingControlOnValueChange

        Get
            Return False
        End Get

    End Property

    Public Property EditingControlDataGridView() As DataGridView _
        Implements IDataGridViewEditingControl.EditingControlDataGridView

        Get
            Return dataGridViewControl
        End Get
        Set(ByVal value As DataGridView)
            dataGridViewControl = value
        End Set

    End Property

    Public Property EditingControlValueChanged() As Boolean _
        Implements IDataGridViewEditingControl.EditingControlValueChanged

        Get
            Return valueIsChanged
        End Get
        Set(ByVal value As Boolean)
            valueIsChanged = value
        End Set

    End Property

    Public ReadOnly Property EditingControlCursor() As Cursor _
        Implements IDataGridViewEditingControl.EditingPanelCursor

        Get
            Return MyBase.Cursor
        End Get

    End Property

    Protected Overrides Sub OnValueChanged(ByVal eventargs As EventArgs)

        ' Notify the DataGridView that the contents of the cell have changed.
        valueIsChanged = True
        Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
        MyBase.OnValueChanged(eventargs)

    End Sub

End Class







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-07-27 12:14:06 By : lamaka.tor
 


 

No. 2



โพสกระทู้ ( 122 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : lamaka.tor เมื่อวันที่ 2017-07-27 12:14:06
รายละเอียดของการตอบ ::
... ขอบคุณครับ.......

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-07-27 14:19:30 By : outhai
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการ DateTimePicker ใน Datagirdview vb 2010 ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่