Hai
I want to create a usercontrol with a Datagrid And a listbox.I want to show Listbox below the cell for the column DataGridViewTextBoxCell.
I inherit a class with datagridview called IGrid. And added a Listbox called Lstbox.
I want a popup of listbox . for this i use this code.
I want to make visible Listbox as stated in the code below.
I tried to create an instance of Igrid, also created new variable for listbox,but bothcase i cant make visible. Please show a method how to do this.
Public Class IGrid
Inherits DataGridView
#Region "Main"
Public WithEvents LstBox As New System.Windows.Forms.ListBox
Public Sub New()
InitializeComponent()
Me.Controls.Add(LstBox)
LstBox.Visible = False
InitializeComponent()
End Sub
#End Region
#Region "TlBox"
Public Class DataGridViewTLBoxColumn
Inherits DataGridViewColumn
Public Sub New()
MyBase.New(New TLBoxCell())
End Sub
Public Overrides Property CellTemplate() As DataGridViewCell
Get
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
MyBase.CellTemplate = value
End Set
End Property
End Class
Public Class TLBoxCell
Inherits DataGridViewTextBoxCell
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)
MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
Dim ctl As TLBoxEditingControl = CType(DataGridView.EditingControl, TLBoxEditingControl)
ctl.Text = Me.Value
End Sub
Public Overrides ReadOnly Property EditType() As Type
Get
Return GetType(TLBoxEditingControl)
End Get
End Property
Public Overrides ReadOnly Property ValueType() As Type
Get
Return GetType(String)
End Get
End Property
Public Overrides ReadOnly Property DefaultNewRowValue() As Object
Get
Return Me.Value
End Get
End Property
End Class
Private Class TLBoxEditingControl
Inherits TextBox
Implements IDataGridViewEditingControl
Private DataGridViewControl As DataGridView
Private ValueIsChanged As Boolean = False
Private RowIndexNum As Integer
'Public WithEvents Lbox As New IGrid
'Or
Public WithEvents Lbox As New ListBox
Public Property EditingControlFormattedValue() As Object Implements IDataGridViewEditingControl.EditingControlFormattedValue
Get
Return Me.Text
End Get
Set(ByVal value As Object)
Me.Text = value
End Set
End Property
Public Function GetEditingControlFormattedValue(ByVal context As DataGridViewDataErrorContexts) As Object Implements IDataGridViewEditingControl.GetEditingControlFormattedValue
Return Me.Text
End Function
Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As DataGridViewCellStyle) Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl
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
Select Case key And Keys.KeyCode
Case Keys.Down
Lbox.Focus()
Lbox.SelectedIndex = 0
Case Keys.Up
End Select
Return True
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 OnTextChanged(ByVal eventargs As EventArgs)
ValueIsChanged = True
Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
MyBase.OnTextChanged(eventargs)
End Sub
Private Sub TlBoxEditingControl_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.TextChanged
If Len(Me.Text) > 1 Then
Lbox.Items.Add("111")
Lbox.Items.Add("222")
Lbox.Items.Add("333")
Lbox.Visible = True
Else
Lbox.Items.Clear()
Lbox.Visible = False
End If
End Sub
End Class
#End Region
End Class
I got an example from codeproject but in that i cant get down arrow key. My purpose is while editing when i press down arrow key i want to get focus listbox and move in listbox and when i press enterkey i want the selected text of listbox in the gridcell.