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
Solved

DataGridViewTextBoxColumn drop down pop up

Posted on 2011-09-28
4
1,764 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Visual Studios 1 76
VB.Net Determine if a mapped network drive exists 2 30
Install IIS7.5 on Windows Sever 2012 R2 4 22
Adding items to a C# list incrementally 5 28
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 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