הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Saturday, November 2, 2013 7:23 PM
Hi,
I need to allow the user to enter item manually on the combobox of DataGridView. Please note that the combobox is bound to a Data Table. I added the following code for adding a Combobox column to a Datagridview. No need to save the typed values but it should see any matching record and autocomplete the combobox.
Dim cboProducts As New DataGridViewComboBoxColumn
cboProducts.Name = "Products"
cboProducts.HeaderText = "Product"
cboProducts.DataSource = DtTable.DefaultView
cboProducts.DisplayMember = "ProductName"
cboProducts.ValueMember = "ProductCode"
DGVPurchases.Columns.Insert(0, cboProducts)
Is there anyone who knows how to implement this functionality in VB.Net DataGridView?
All replies (21)
Tuesday, November 5, 2013 3:15 PM ✅Answered
Yes I already pointed out the point the code pointed to a DataGrid and not a DataGridView.
I already indicated to get this functionality you need to write your own custom column, I have never had a need for this thus have never coded a custom column to do this as the Code Project component has met my customer needs.
So with that said either you must write a custom column to get this capability.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Tuesday, November 5, 2013 6:56 PM ✅Answered
Okay this will be one of those V8 moments (smack one's self on the head). Take the current project I gave you and find the EditingControlShowing event, replace it with the following.
Private Sub DataGridView1_EditingControlShowing(
sender As Object,
e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If TypeOf e.Control Is DataGridViewComboBoxEditingControl Then
CType(e.Control, ComboBox).DropDownStyle = ComboBoxStyle.DropDown
CType(e.Control, ComboBox).AutoCompleteSource = AutoCompleteSource.ListItems
CType(e.Control, ComboBox).AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest
End If
End Sub
Screenshot
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Sunday, November 3, 2013 9:39 AM
Hello,
Here is a good representation for the direction needed to do auto-complete. Now about adding items, that contradicts the part indicating "it should match any record", done properly, the item to find should be in the DataTable dtTable and not need to be added. Also, you would not have a ProductCode to use for newly added items. Seems to me this is a ill-designed process and should be thought through differently.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Sunday, November 3, 2013 3:42 PM
Hi,
Sorry. My requirement is to display the item in the combobox while typing. The combobox is populated from the DataTable.
This is only a dummy code displayed to get an answer from the experts. Newly added items are added from a different form, where the product code will be selected and an item code will be assigned accordingly.
Monday, November 4, 2013 3:02 PM
Hi,
Sorry. My requirement is to display the item in the combobox while typing. The combobox is populated from the DataTable.
This is only a dummy code displayed to get an answer from the experts. Newly added items are added from a different form, where the product code will be selected and an item code will be assigned accordingly.
Download the following project. In PrepareData.vb add .AutoComplete =True to the ContactPositionColumn. Build, run, test it. Now with this method you do not get a TextBox but try typing text in and as you go the Auto-Complete kicks in. So if I type Sales Ass on the third row I get the following. First part shows prior to change, second part after typing Sales ass.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Monday, November 4, 2013 7:34 PM
To make your code run, I need to install Frame Work 4.5. Currently, I'm using VS 2010. I will download Framework 4.5 and give a reply tomorrow.
Monday, November 4, 2013 8:30 PM
I originally did this in VS2010 in this project but not sure if I made changes after loading it into VS2012.
Either way the VS2012 project does not use anything specific to Framework 4.5 so if you can load it in VS2010 then simply change the Framework to 4.0
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Tuesday, November 5, 2013 8:25 AM
Hi,
My application was targeting Framework 4 Client Profile. Because of this it was not working. As advised by you, I changed to Framework 4.0 and now it works fine.
First of all, I would like to thank you for providing a sample project showing how combobox works in Datagridviews.
There is one issue still remaining. I will illustrate the issue by an example:
Ässume that a combobox contains items "Sales Manager, Sales Assistant, Salesman". Once you press "S", it will show Sales Manager. On second press "S", sometimes it show Sales Assistant otherwise it will not move. In real life, if you press "S" again, it should show the second record which "Sales Assistant".
The same issue exist in the "Gold, Yellow, Red" example. Once you press "G" it will show Gold. While showing Gold, if you press "Y", sometimes it will move to Yellow and sometimes not.
Could you please check this behavior of Datagridview Combobox and advise how to solve this issue.
Tuesday, November 5, 2013 8:34 AM
Hi Kevin,
You will see this issue only if you press different alphabets continuously.
Tuesday, November 5, 2013 10:29 AM
Hello,
The first ComboBox column is setup for auto-complete and the second one is not. Now the definition of auto-complete in this case means if you type S you are taken to the first item that starts with S and if you type SS nothing will be found and it will not cycle through items that begin with S, instead the operation is cumulative i.e. which is why I instructed you to type in sale ass or sale m. The behavior of cycling is not programmed here and can not with the normal ComboBox column of a DataGridView.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Tuesday, November 5, 2013 10:55 AM
Hi Kevin,
So in this case what is the best way to enable the requirement that I mentioned earlier.
End users are insisting to have this feature and I am finding it difficult to do it through standard combobox in datagridview. In one way, they are right because they are facing difficulties and they are familiar with the combobox of datagridview in MS Access.
What is the best the way that you recommend? I apologize that I cannot use the feature that you gave earlier because end users are not happy with what I provided.
Tuesday, November 5, 2013 10:57 AM
In other words, the end users are requesting to have the combo box feature of gridview in MS Access. In Access, it is easy. End user can easily type the value to the grid combobox (like textbox) and combobox displays the full value.
Tuesday, November 5, 2013 12:23 PM
Please check this link:
http://www.knowdotnet.com/articles/kdngrid.html
Tuesday, November 5, 2013 2:38 PM
In other words, the end users are requesting to have the combo box feature of gridview in MS Access. In Access, it is easy. End user can easily type the value to the grid combobox (like textbox) and combobox displays the full value.
My view of MS-Access is as shown below (discounting using a MS-Access form)
Or
Now if you are open to other methods I would suggest the following component on Code Project DataGridView Filter Popup. This component can be implemented with two lines of code and is highly customizable as I have implemented this component many times customized.
..
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Tuesday, November 5, 2013 2:42 PM
Please check this link:
This is a DataGrid, not a DataGridView.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Tuesday, November 5, 2013 3:07 PM
Yes,
You are right. It is a DataGrid. But can we implement this feature in DataGridView?
Tuesday, November 5, 2013 3:09 PM
Hi Kevin,
This is what my end users are looking for:
It is a DataGrid. But is there any way to implement the same in VB.Net DataGridView?
Tuesday, November 5, 2013 3:13 PM
Users can type directly on to the Combobox.
This will help them especially when there are large amounts of data to feed in.
Tuesday, November 5, 2013 6:22 PM
Hi Kevin,
Your suggestions were helpful. Hence I mark this as Answer.
I am still looking for a custom control with the feature that I need.
Tuesday, November 5, 2013 7:34 PM
Hi Kevin,
This is what I was looking for.
I appreciate the way you responded to my queries and thank you so much.
Tuesday, November 5, 2013 7:49 PM
Hi Kevin,
This is what I was looking for.
I appreciate the way you responded to my queries and thank you so much.
Your very welcome :-)
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.