ComboBox in a dataGrid

R

Randy

Hello,

I've got a Form which has a dataGrid on it. In one of the columns of the
dataGrid, I've implemented a ComboBox using a DataGridComboBoxColumn Class.
I've also over ridden the other columns with a custom DataGridTextBoxColumn
class so I can color certain columns.

What I'm trying to do is.based on the selection in the ComboBox, I want to
color certain cells.

The problem I'm having is.when I make a selection in the ComboBox, the
_SelectedIndexchanged event for the DataGridComboBoxColumn class fires like
it should. At this point, when it fires, I'm in the DataGridComboBoxColumn
class, not in the main Form class. The only way I know of to reference the
main form is to instantiate a new class like.

MyForm myform = new MyForm();

But when I do this, I loose the state (session) data.

When this _SelectedIndexchanged (ComboBox) fires, I need a way to get back
into the main Form code so I can change the colors of certain columns.

I think there is a way to do this, I just don't know how.



Thanks for any help...
 
N

Nicholas Paldino [.NET/C# MVP]

Randy,

The DataGridComboBoxColumn shouldn't be able to hook to the main form
like that. Rather, why not attach the form to the events on the data source
itself (the dataset) and detect when that column changes? When that
happens, you can set the color appropriately on the grid.

Hope this helps.
 
R

Randy

That sounds good...but I'm not sure how to do it. You got any examples?

Thanks


Nicholas Paldino said:
Randy,

The DataGridComboBoxColumn shouldn't be able to hook to the main form
like that. Rather, why not attach the form to the events on the data
source itself (the dataset) and detect when that column changes? When
that happens, you can set the color appropriately on the grid.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Randy said:
Hello,

I've got a Form which has a dataGrid on it. In one of the columns of the
dataGrid, I've implemented a ComboBox using a DataGridComboBoxColumn
Class. I've also over ridden the other columns with a custom
DataGridTextBoxColumn class so I can color certain columns.

What I'm trying to do is.based on the selection in the ComboBox, I want
to color certain cells.

The problem I'm having is.when I make a selection in the ComboBox, the
_SelectedIndexchanged event for the DataGridComboBoxColumn class fires
like it should. At this point, when it fires, I'm in the
DataGridComboBoxColumn class, not in the main Form class. The only way I
know of to reference the main form is to instantiate a new class like.

MyForm myform = new MyForm();

But when I do this, I loose the state (session) data.

When this _SelectedIndexchanged (ComboBox) fires, I need a way to get
back into the main Form code so I can change the colors of certain
columns.

I think there is a way to do this, I just don't know how.



Thanks for any help...
 
N

Nicholas Paldino [.NET/C# MVP]

Randy,

Well, you have the data set available to you that you bind to the grid,
right? Just find the table in the collection exposed by the Tables property
on the data set, then attach to the ColumnChanged or ColumnChanging event.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Randy said:
That sounds good...but I'm not sure how to do it. You got any examples?

Thanks


Nicholas Paldino said:
Randy,

The DataGridComboBoxColumn shouldn't be able to hook to the main form
like that. Rather, why not attach the form to the events on the data
source itself (the dataset) and detect when that column changes? When
that happens, you can set the color appropriately on the grid.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Randy said:
Hello,

I've got a Form which has a dataGrid on it. In one of the columns of the
dataGrid, I've implemented a ComboBox using a DataGridComboBoxColumn
Class. I've also over ridden the other columns with a custom
DataGridTextBoxColumn class so I can color certain columns.

What I'm trying to do is.based on the selection in the ComboBox, I want
to color certain cells.

The problem I'm having is.when I make a selection in the ComboBox, the
_SelectedIndexchanged event for the DataGridComboBoxColumn class fires
like it should. At this point, when it fires, I'm in the
DataGridComboBoxColumn class, not in the main Form class. The only way I
know of to reference the main form is to instantiate a new class like.

MyForm myform = new MyForm();

But when I do this, I loose the state (session) data.

When this _SelectedIndexchanged (ComboBox) fires, I need a way to get
back into the main Form code so I can change the colors of certain
columns.

I think there is a way to do this, I just don't know how.



Thanks for any help...
 
R

Randy

Thanks a bunch!...that works just like I need it to. I hadn't thought of
that...

Nicholas Paldino said:
Randy,

Well, you have the data set available to you that you bind to the grid,
right? Just find the table in the collection exposed by the Tables
property on the data set, then attach to the ColumnChanged or
ColumnChanging event.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Randy said:
That sounds good...but I'm not sure how to do it. You got any examples?

Thanks


Nicholas Paldino said:
Randy,

The DataGridComboBoxColumn shouldn't be able to hook to the main form
like that. Rather, why not attach the form to the events on the data
source itself (the dataset) and detect when that column changes? When
that happens, you can set the color appropriately on the grid.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

I've got a Form which has a dataGrid on it. In one of the columns of
the dataGrid, I've implemented a ComboBox using a
DataGridComboBoxColumn Class. I've also over ridden the other columns
with a custom DataGridTextBoxColumn class so I can color certain
columns.

What I'm trying to do is.based on the selection in the ComboBox, I want
to color certain cells.

The problem I'm having is.when I make a selection in the ComboBox, the
_SelectedIndexchanged event for the DataGridComboBoxColumn class fires
like it should. At this point, when it fires, I'm in the
DataGridComboBoxColumn class, not in the main Form class. The only way
I know of to reference the main form is to instantiate a new class
like.

MyForm myform = new MyForm();

But when I do this, I loose the state (session) data.

When this _SelectedIndexchanged (ComboBox) fires, I need a way to get
back into the main Form code so I can change the colors of certain
columns.

I think there is a way to do this, I just don't know how.



Thanks for any help...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top