>> Have you tried the EditingControlShowing event?
>
[quoted text clipped - 5 lines]
>
>-Dan
Hmm...I haven't actually done this but it might be worth a shot.
1. Create a BindingSource and associate your data with it.
2. Set the DataGridViewComboBoxColumn's data source to be the
BindingSource. These 2 steps have then setup the *whole list* of data
that the combo can show.
3. Bind the combo box column to the appropriate property on your
object (ie the one you want to set/get) using the DataPropertyName
property.
4. On the EditingControlShowing event, set the Filter property of the
BindingSource to restrict the items displayed in the combo box. It
takes a SQL-like expression syntax.
Fallback: If this doesn't work, you might consider simply using a
non-bound combo column and populating its list within the
EditingControlShowing event, or change the UI to have a little button
in an image column, and use that to pop up a form.
I'm currently learning data binding myself and I know how tricky
things can be...when it works it's great but when it doesn't figuring
out what is wrong can be a hard slog. [Aside, not directly relevant to
your situation: One thing I learnt this morning is make sure you set
properties like DisplayMember and ValueMember *before* you associate
the DataSource otherwise the control just ignores them. The code looks
right, compiles and runs fine but just doesn't do what you expect....]
Phil
Daniel Manes - 28 Jul 2006 02:12 GMT
Hey Phil,
Thanks again for the help...think I got the filtering problem solved. I
combined the CountryID and LocaleID into a single column, which then
allowed me to set the DisplayMember to the name of the locale and the
ValueMember to the new combined ID.
> I'm currently learning data binding myself and I know how tricky
> things can be...when it works it's great but when it doesn't figuring
> out what is wrong can be a hard slog.
Hehe, tell me about it. I'm currently trying to figure out which of the
over 200 (!) DataGridView events to use to process the result when the
user selects an item from the combo box. When I use CellLeave, the
value of the cell is DBNull even though I definitely set the ComboBox
to a real value. I would have thought the value would have been set by
the time CellLeave is raised but apparently not.
Either that or something else is wrong :)
Take it easy,
-Dan