Combo box in DataGridView

johnpapa

Member
Joined
Aug 10, 2013
Messages
23
Programming Experience
10+
I would like to be able to select the last name of a customer in a from showing the appointments.
The Last name field is "nvcLast". In my appointments form, frmAppointment, I inserted a DGV and I included a combo box which is meant to retrieve nvcLast. I do not want to retrieve all customers every time, so I try to retrieve the TOP say 100 based on the letters of nvcLast.
It appears that I can fill in a specific combo box value, for say customer "Doe" , but when I try to insert another customer, say "Jones", the TOP 100 customers that begin with "J" are retrieved BUT the combo box which help value "Doe" no longer holds the value.
It seems that in a DGV the combo column will only display values which are included in the latest "SELECT" statement.
Is this the case?
If Yes, can you please suggest a solution, short of a Popup form?
Thanks,
John
 
I have moved this thread from the SQL Server forum to the Windows Forms forum. This is completely a UI issue and nothing to do with the database.

If you are setting the DataSource for the column itself then that's the issue. Setting the DataSource for the column changes it for all cells. If an item has already been selected in one cell and then you remove that item from the DataSource then you have an issue. What you need to do is set the DataSource individually for each cell, so that the item selected in each cell will always be present in the DataSource of that cell.
 
Thanks for moving to the WF forum and apologies for the inconvenience.

You have pinpointed the problem, but I do not know how to individually set the datasource for every cell in the grid column. If it makes a difference, the number of grid rows displayed will not be large, maybe from 10 to 40. The question is how to make sure that the cell datasource in these 10 to 40 cells is set individually?
 
If i get you correctly... you want to be able to set the grid column for the cells using a dataset.

i am using visual studio 2012 to demonstrate how i think you can solve your problem.[video=youtube_share;d2BPKbZ1Ozc]http://youtu.be/d2BPKbZ1Ozc[/video]
 
Many thanks for the replies Sterlingard.

I tried to indicate the two problems which I am trying to solve in the following video. The software (which I wrote) uses Access 2013.

DataGridView - YouTube

I am trying to move the application to the Cloud, using VS 2012 and SQL Server 2012.

Hope I made things clearer.
 
I had a look at the example and have spent a lot of time trying to implement your suggestion. I use VB.


As you can see from the video which I posted earlier in this thread, the goal is to populate the list of say Last names as the user types characters. If the user types an "L", I would like to bring a reasonable number (maybe 100) of Last names that begin with the letter "L", in other words not all names that begin with an "L". As the user types more characters the number of matches will become smaller.

I received another suggestion, using a textbox (instead of a combo box) in association with AutoComplete and a dropdown list. The following code works to a certain extent,

            GetPatientByLastFirstTel(dgvAppointment.CurrentCell.Value.ToString)
 
            Dim ItemCode As TextBox = TryCast(e.Control, TextBox)
            If ItemCode IsNot Nothing Then
                If dgvAppointment.CurrentCell.ColumnIndex = DFN_GRID_intPatientID_COL Then
                    With DirectCast(e.Control, TextBox)
 
                        .AutoCompleteMode = AutoCompleteMode.SuggestAppend
 
                        .AutoCompleteSource = AutoCompleteSource.CustomSource
 
                        .AutoCompleteCustomSource.AddRange(arymReturnArray)
 
                    End With
                Else
                    With DirectCast(e.Control, TextBox)
                        .AutoCompleteMode = AutoCompleteMode.None
                    End With
                End If
            End If



I need to repopulate the dropdown list every time the user types a new character or deletes a character, just in case the name I am looking for is not included in the early dropdown lists. I have tried unsuccessfully to use events Editing ControlShowing (which is fired only once on entry of the specific cell) and event CellValueChanged.

Can you suggest the events I could use to implement this or another solution? I may have to use a popup form which would open on top of the textbox in question, but this does not seem right.

Thanks,
 
Last edited by a moderator:
Back
Top