By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,838 Members | 1,675 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,838 IT Pros & Developers. It's quick & easy.

Detecting selection change in ComboBox column of a DataGridView

P: n/a
Hello,

I have an unbound DataGridView of which one of the columns is a ComboBox
colum containing category data, plus an additional option called <newSo
when the ComboBox is dropped down it looks like this

<new>
First
Second
Third
Fourth

I would like to add an event to this ComboBox so that I can detect if the
user chooses <newor not. I have tried various combinations of the very
rich DataGridView event model e.g. the CellValueChanged event. The problem
with this is that it doesn't fire when the ComboBox itself changes - it only
fires when the contents of the underlying cell changes i.e. when the user
moves to another cell.

I found this via Google
http://forums.microsoft.com/MSDN/Sho...54048&SiteID=1

but I can't get it to work. It seems to have been written using a beta
version of .NET2 so maybe things were changed in the released version.

I'm wondering if what I'm trying to achieve is even possible? Is it possible
to grab the ComboBox in a ComboBox column and wire up new events for it?

Thanks in advance.

DJ
Apr 14 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"David Jackson" <so*****@somewhere.comwrote in message
news:Ou**************@TK2MSFTNGP02.phx.gbl...
I'm wondering if what I'm trying to achieve is even possible? Is it
possible to grab the ComboBox in a ComboBox column and wire up new events
for it?
It most certainly is. This MSDN article shows you how:
http://msdn2.microsoft.com/en-us/lib...ngcontrol.aspx
Apr 14 '07 #2

P: n/a
David Jackson schreef:
Hello,

I have an unbound DataGridView of which one of the columns is a ComboBox
colum containing category data, plus an additional option called <newSo
when the ComboBox is dropped down it looks like this

<new>
First
Second
Third
Fourth

I would like to add an event to this ComboBox so that I can detect if the
user chooses <newor not. I have tried various combinations of the very
rich DataGridView event model e.g. the CellValueChanged event. The problem
with this is that it doesn't fire when the ComboBox itself changes - it only
fires when the contents of the underlying cell changes i.e. when the user
moves to another cell.
Subscribe to the EditingControlShowing event.. Verify if the control is
a ComboBox and if it is, subscribe to it's SelectionChangeCommitted event:

ComboBox cbo = e.Control as ComboBox;
if (cbo != null) {
cbo.SelectionChangeCommitted += ...;
}
In that handler you simply write the values back to the binding:
foreach(Binding binding in comboBox.DataBindings) {
binding.WriteValue();
}
--
Tim Van Wassenhove <url:http://www.timvw.be/>
Apr 14 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.