[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1879
  • Last Modified:

DataGridViewTextBoxColumn drop down pop up

Hello,

I am using Windows Forms. I have DataGridView and some columns inside it. One of the columns is DataGridViewTextBoxColumn. Is it possible to open a drop down pop up (with autocomplete items) of this column, without editing cell? I mean - if I just click on the cell, pop up opens with items in it.

Please note: I was using DataGridViewComboBox column before - but it is very very slow with large number of items in it (more than 1000). That is why I am using DataGridViewTextBoxColumn - it's working fast, the only problem is that user must edit cell and type something in cell to have pop up opened - I want pop up to be opened on the click of the cell. Any idea?

Greetings, Frenky
0
AntonioRodrigo
Asked:
AntonioRodrigo
  • 2
1 Solution
 
nepaluzCommented:
If what youwant is populate a datagridviewcomboboxcell in the background and bring it to the fore on cell click and then send back on selected item / value changed then YES it is possible. Do you require code suggestion? or have you worked it out from the above description?
0
 
Jacques Bourgeois (James Burger)Commented:
Here is a piece of code I use in one of my application to open a CheckedListBox over a TextBoxColumn cell. It should be easy to adapt this to any other control. The idea it to find the location of the cell and open the other control over it. I think that this is what you are after.

dgvDocumentation is the grid.
ColumnID.FollowUp is the position of the column in the grid.
_lstFollowUp is the popup control that I "open" over the cell (defined as a member of the form because I use it in many places)
_currentFollowUp is the cell in the grid (same comment)
Private Sub dgvDocumentation_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvDocumentation.CellClick

   '*** Follow Up column

   'We react here instead of CellEnter because we do not want to react when the user comes into the cell while
   'tabbing in the grid. This column is not used often enough and is set as not to react to a tab. The user needs
   'to click in it in order to activate it.

   If e.ColumnIndex = ColumnID.FollowUp Then

      _currentFollowUp = dgvDocumentation.Item(e.ColumnIndex, e.RowIndex)
      Dim aPoint As Point = dgvDocumentation.GetCellDisplayRectangle(_currentFollowUp.ColumnIndex, _currentFollowUp.RowIndex, False).Location
      aPoint.X += dgvDocumentation.Parent.Location.X + dgvDocumentation.Location.X
      aPoint.Y += dgvDocumentation.Parent.Location.Y + dgvDocumentation.Location.Y

      With _lstFollowUp
         If dgvDocumentation.Item(e.ColumnIndex, e.RowIndex).Value Is Nothing Then
            .SetItemChecked(0, True)
         End If
         .Width = _currentFollowUp.Size.Width
         .Location = aPoint
         .BringToFront()
         .Height = _lstFollowUp.PreferredHeight
         .Visible = True
         .Select()
      End With '_lstfollowup

   End If   'Follow Up column

End Sub

Open in new window

In the Leave event of my popup control, I insert the result of the selection in the cell:
Private Sub _lstFollowUp_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles _lstFollowUp.Leave

   Dim newValue As Integer

   'Retrieve the checked value(s)
   For x As Integer = 0 To _lstFollowUp.Items.Count - 1
      If _lstFollowUp.CheckedItems.Contains(_lstFollowUp.Items(x)) Then
         newValue += x
      End If
   Next

   _currentFollowUp.Value = newValue 'Store the value in the cell
   _lstFollowUp.Visible = False

End Sub

Open in new window

0
 
AntonioRodrigoAuthor Commented:
James, your idea seems great. But, I've come up to some problems:

_lstFollowUp doesn't show up. Nothing happens when I trigger on click event.

I've declared _lstFollowUp in my Form as:

Friend _lstFollowUp As System.Windows.Forms.CheckedListBox

in designer.

On Form1 load event I added:

 _lstFollowUp = New CheckedListBox()
        _lstFollowUp.Items.AddRange(New Object() {"TEst1", "Test1", "Test3", "Test3"})
        _lstFollowUp.Name = "_lstFollowUp"
        _lstFollowUp.Size = New System.Drawing.Size(120, 94)


So  _lstFollowUp is declared and filled with items. I don't understand why it doesn't show up?

I've also declared

Dim _currentFollowUp As DataGridViewCell

in my Form1.

When I follow on click event with debugger, everything is cool - but nothing happens.

Am I doing something wrong?


Greetings, Frenky
0
 
AntonioRodrigoAuthor Commented:
The way to solve the problem is definitely correct - to open another control on top of first control. I've decided to use ListBox.
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now