works like a combo box?

PhillD

Well-known member
Joined
Mar 5, 2010
Messages
91
Programming Experience
10+
For a combo box that works like a combo box?

I need to add a combo box to a DataGridView that is bound to data. I need to be able to display multiple columns within the combo box (like you would find in any other normal program).

I need the combo box to drop down without having to click it 4 times (like you would find in any other normal program). and I need to be able to enter text into the combo box and the user see what they have typed (like you would find in any other normal program). I have found many examples on the net, but nothing that ties all these requirements together.

If I had been working in .net for several years, this is something I could probably do myself, however, I am from an ms access and VB background where my programming skills have been focused on making programs work, not programming controls to make them work correctly. Hench to say, I am lost on this one. I am not asking anyone to program it for me, but the very basic of the basics would be a nice place to start. Half of the examples, I couldn't even get working so that's how thick I am.

Why did Microsoft provide such a crappy useless combo box anyway? I mean, if we're going back to the days of writing our own controls, hell, why not make us write the code to draw the screen. As you can tell, I am extremely frustrated, I could finish this project in 1 or 2 days in MS Access, a week in VB. So what makes .net so much greater if everything is so much more difficult to accomplish. I thought this was supposed to make everything easy.
 
PhillD: I don't have an answer to your combo box issue, but I just wanted to give you a thumbs up. I feel the same way you do sometimes.

Maybe some things are better left to the old ways, rather than the new.
 
While I don't have an answer, I do have to say that in .Net the ComboBox is far easier to use than in vba, imho. However, what he's trying to do is insert a Combo into a DataGrid (which isn't even possible in vba because those are different controls with a different set up in a completely different environment) which in .Net I have no idea if (based on what he's saying) it's even possible.

Then again I don't fully know what he's trying to do since the post is more of a rant against .Net than it is asking how to do something & providing details about what's to be done.
 
If you add a combo box to a form and then open the form in data grid view, you will have a combo box in a data grid. It's that easy. You don't have to code anything, but you could if you wanted to. You can attach code to any of the combo box events, and they will fire in the datagrid. Unlike .net where you must add code to a grid event and then write additional code to detect the column the event was fired on (which by the way, what happens if the user reorders the columns in the grid? does that change the column indexes? Will the code still work on the correct column?) I tried referring to the column by name but in some events, it didn't seem to be supported.
 
I know that Access form feature you're talking about, which isn't really a grid at all. What Access does (and this is my best guess, I could be wrong) it takes your form and replicates all the controls into multiple instances of some magical user control or something then simply repeats that user control right down the list. You can, of course, do that in .Net if you really want to, I wouldn't know where to start since Access is the only thing I know that does it (or even comes close to it). However, you've only mentioned that feature that Access can do, in regards to .Net controls you've mentioned using a Grid (which is probably a GridView) and you're wanting a ComboBox in it, which indicates you're probably wanting to embed a ComboBox in the control or you're overlaying one on the grid and my guess is that it isn't working out so well.

But that's just speculation, you haven't said what you're actually doing so I'm just reaching for the stars.
 
A picture is worth a thousand words. Here's what I would like to accomplish.
ComboBoxInGrid.JPG

A multi column combo box in a grid that allows the user to type in the value they desire and to be able to see what they are typing. To me, this is a standard combo box that you would find in any standard business application. For display purposes, I have shown the combo box in drop down mode but normally the box would not drop down unless the user clicked it, it does however use auto complete.
 
Yes, I know what you're trying to achieve and I don't have an outright solution for you. I've done that in Access a few times myself, but since it's an Access thing I've never been able to do that outside of vba.

Typically that's not the ideal way to handle data in apps, it works wonderfully in Access yes as a quick and dirty, informal way of handling data (which is all I've ever used vba for anyways) in a .Net app I've never had a need to try and force that kind of behavior and while I could probably make a grid control to behave that way I've never had a reason nor the time to.

I would however be willing to work with you on designing a different type of UI for your .Net app.

It also appears that I've kind of dominated this thread, if there's anyone else who's reading this thread and has things to contribute, feel free to.
 
So now I am intrigued. Here's the form I am trying to develop.

EmployeeExpenses.JPG

It's an employee expenses entry form. The user ID information is auto populated by information captured at the login screen. The problem I am having is with the expense entry lines.

As per the screen shot, the user must specify a date, customer, expense type, amount and payee. Each employee will have numerous expense lines per expense header.

[EDIT]
Forgot to add this information.
It is common practice to identify customer by their customer number. Our sales team is accustomed to this. So this is where it gets complicated.

In our old ERP system customer numbers were 1 letter followed by three numbers. E.G. M187. However, in our new ERP system, the geniuses who wrote it, decided to enforce 7 digit customer numbers. So when you enter M187, it is automatically converted and stored as M000187. This feature is consistent throughout the ERP system and used in many combo boxes. This is where is gets even more complicated. I was able to "fudge" a multi column combo box by combining 2 data fields in SQL to form the display column.
So it reads as follows:

StoredValue DisplayValue
M000187 M000187 CustomerName

The code to convert the number is simple, but implementing this in .net against a bound combobox is incredibly difficult. First, VB wants to validate the entry before it is submitted to the control, meaning that if you call combobox.value after entering M187, the result is null because it is not a valid value for that column. I tried to intercept the validation code but I cannot convert the value that was entered because it is not valid. I then tried forcing M000187 in the code for testing. It is not valid either because the entry is expecting "M000187 CustomerName" to be entered.

Does that make any sense?

In an ideal world, what I need is

M000187 | CustomerName

to display in the combo box. Customer name being a completely separate column. If the user enters M187, I convert it to M000187 and the entry is valid. If the user drops down the combo box, I need them to select the M100087 entry.

Hope this is clear. So now you said I shouldn't be doing it this way. How should I do it?

Thanks
 
Last edited:
I know this isn't the answer you are looking for, but I use to use ComponentOne controls before I was able to remove them and accomplish my needs using standard controls.

However, I do remember the CO combobox allowed for a multicolumn row, and would display just like you are trying.

I think they do a "trial" download, probably not the best option as you have to buy the controls, but I agree, most MS standard components are pretty useless!
 
Thanks for the help everyone. It's looking more and more like I just need to buy some controls. How I am I going to explain this one to upper management?
 
Back
Top