Solved

DataGridViewTextBoxColumn drop down pop up

Posted on 2011-09-28
4
1,716 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now