Solved

DataGridViewTextBoxColumn drop down pop up

Posted on 2011-09-28
4
1,782 Views
Last Modified: 2013-11-27
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
Comment
Question by:AntonioRodrigo
  • 2
4 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 36717429
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36717666
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
 

Author Comment

by:AntonioRodrigo
ID: 36813078
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
 

Author Closing Comment

by:AntonioRodrigo
ID: 36813201
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question