如何仅显示DataGridView特殊列DateTimePicker [英] How to show DataGridView Particular Column only DateTimePicker
本文介绍了如何仅显示DataGridView特殊列DateTimePicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨..所有
这里我使用DGV Paricular列的代码只想显示DTP ..但此代码显示所有栏目。
如何更换Paricular Columns ..
dtpCell = 新 DateTimePicker
dtpCell.Visible = 错误
AddHandler dtpCell.ValueChanged, AddressOf DateTimePickerCell_ValueChanged
' DGV1.Columns.Add(col1,String.Empty)
DGV1。 Controls.Add(dtpCell)
AddHandler DGV1.CellBeginEdit, AddressOf DataGridView_CellBeginEdit
< span class =code-keyword> AddHandler DGV1.CellEndEdit, AddressOf DataGridView _CellEndEdit
私有 Sub DataGridView_CellBeginEdit(sender As 对象,e As System.Windows.Forms.DataGridViewCellCancelEventArgs)
Dim tmpRect As Rectangle = DirectCast (sender,DataGridView).GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True )
dtpCell.Location = tmpRect.Location
dtpCell.Width = tmpRect.Width
dtpCell.Visible = True
结束 Sub
私有 Sub DataGridView_CellEndEdit(sende r 作为 对象,e 作为系统。 Windows.Forms.DataGridViewCellEventArgs)
dtpCell.Visible = False
结束 Sub
私有 Sub DateTimePickerCell_ValueChanged(发件人作为 对象,e As EventArgs)
DirectCast (sender.parent,DataGridView).CurrentCell.Value = Convert.ToDateTime(dtpCell.Value)。日期 .ToString( dd MMM yyyy)
dtpCell .Visible = False
DirectCast (sender.parent,DataG ridView)。EndEdit()
结束 Sub
请点击我点击我的DGV DOB栏点击时间显示给DTP ..
解决方案
私有 Sub DataGridView_CellBeginEdit(发件人 As 对象,e As System.Windows.Forms.DataGridViewCellCancelEventArgs)
如果 我 .DataGridView1.Focused AndAlso Me .DataGridView1.CurrentCell.ColumnIndex = 0 然后
Dim tmpRect As Rectangle = DirectCast (sender,DataGridView).GetCellDisplayRectangle(e.ColumnIndex,e.RowIndex, True )
dtpCell.Location = tmpRect.Location
dtpCell .Width = tmpRect.Width
dtpCell.Visible = True
结束 如果
结束 Sub
Hi.. All
Here i USe Code For DGV Paricular Columns Only Want to SHOW DTP.. But this code show all columns.
How can i Change Paricular Columns..
dtpCell = New DateTimePicker
dtpCell.Visible = False
AddHandler dtpCell.ValueChanged, AddressOf DateTimePickerCell_ValueChanged
'DGV1.Columns.Add("col1", String.Empty)
DGV1.Controls.Add(dtpCell)
AddHandler DGV1.CellBeginEdit, AddressOf DataGridView_CellBeginEdit
AddHandler DGV1.CellEndEdit, AddressOf DataGridView_CellEndEdit
Private Sub DataGridView_CellBeginEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellCancelEventArgs)
Dim tmpRect As Rectangle = DirectCast(sender, DataGridView).GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True)
dtpCell.Location = tmpRect.Location
dtpCell.Width = tmpRect.Width
dtpCell.Visible = True
End Sub
Private Sub DataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs)
dtpCell.Visible = False
End Sub
Private Sub DateTimePickerCell_ValueChanged(sender As Object, e As EventArgs)
DirectCast(sender.parent, DataGridView).CurrentCell.Value = Convert.ToDateTime(dtpCell.Value).Date.ToString("dd MMM yyyy")
dtpCell.Visible = False
DirectCast(sender.parent, DataGridView).EndEdit()
End Sub
Please Tell When i Click my DGV DOB Column Click time show to DTP..
解决方案
Private Sub DataGridView_CellBeginEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellCancelEventArgs) If Me.DataGridView1.Focused AndAlso Me.DataGridView1.CurrentCell.ColumnIndex = 0 Then Dim tmpRect As Rectangle = DirectCast(sender, DataGridView).GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True) dtpCell.Location = tmpRect.Location dtpCell.Width = tmpRect.Width dtpCell.Visible = True End If End Sub
这篇关于如何仅显示DataGridView特殊列DateTimePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文