An object-oriented programming language developed by Microsoft that can be used in .NET.
Hi @Mansour_Dalir ,
I tested with the code below and when selecting an item from the listbox, the cells of the Datagridview exit edit mode, but do not lose focus.
Dim dt As New DataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dt.Columns.Add("Column1")
dt.Columns.Add("Column2")
dt.Columns.Add("Column3")
dt.Rows.Add("1", "2", "3")
dt.Rows.Add("4", "5", "6")
dt.Rows.Add("7", "8", "9")
DataGridView1.DataSource = dt
editingListBox.Visible = False
Me.Controls.Add(editingListBox)
End Sub
Private Sub DataGridView1_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
ShowEditingListBox(e.RowIndex, e.ColumnIndex)
End Sub
Private Sub ShowEditingListBox(rowIndex As Integer, columnIndex As Integer)
Dim cellRect As Rectangle = DataGridView1.GetCellDisplayRectangle(columnIndex, rowIndex, False)
editingListBox.Location = New Point(cellRect.Left, cellRect.Bottom)
editingListBox.Width = cellRect.Width
editingListBox.Items.Clear()
editingListBox.Items.AddRange({"Item 1", "Item 2", "Item 3"})
editingListBox.Visible = True
editingListBox.BringToFront()
End Sub
Private Sub editingListBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles editingListBox.SelectedIndexChanged
If editingListBox.SelectedItem IsNot Nothing Then
Console.WriteLine(editingListBox.SelectedItem.ToString())
Dim editingCell As DataGridViewTextBoxCell = DirectCast(DataGridView1.CurrentCell, DataGridViewTextBoxCell)
editingCell.Value = editingListBox.SelectedItem.ToString()
editingListBox.Visible = False
End If
End Sub
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.