Solved

DataGridViewTextBoxColumn drop down pop up

Posted on 2011-09-28
4
1,813 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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