My first combobox in the datagrid :-(

M

Michael Schindler

why see my combobox not in datagrid with values(offen, closed) not to column
the 5?

Please help me!

This is my first combobox and i have no idea what i can to do.

My source:



private void button1_Click(object sender, System.EventArgs e)

{

ComboInTheGrid();

}



private void ComboInTheGrid()

{

// Create a table style that will hold the new column style

// that we set and also tie it to our customer's table from our DB

DataGridTableStyle tableStyle = new DataGridTableStyle();

tableStyle.MappingName = "tblFiBuPeriode";

DataTable dt = ds.Tables["tblFiBuPeriode"];


// make the dataGrid use our new tablestyle and bind it to our table

for(int i = 0; i < dt.Columns.Count; ++i)

{

if(i == 5)

{

DataGridComboBoxColumn ComboTextCol = new DataGridComboBoxColumn();


tableStyle.PreferredRowHeight = ComboTextCol.ColumnComboBox.Height + 2;

ComboTextCol.MappingName = "Status";

tableStyle.GridColumnStyles.Add(ComboTextCol);

ComboTextCol.ColumnComboBox.Items.Clear();

ComboTextCol.ColumnComboBox.Items.Add("Open");

ComboTextCol.ColumnComboBox.Items.Add("Close");

ComboTextCol.ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

}

else

{

// Nothing

}

}

}



The datasource is the datasource from the hole datagrid that i have.

I have a datagrid with columns and i want in the last column a choice open
or close in my datagrid...it is this possible and how?



Thanks and i hope your understand my english :)



Thanks



Michael
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Michael,

DataGridTableStyle/DataGridColumnStyle setup should occur BEFORE the grid is
bound to a data source. In your case, it seems to be you are trying to set
up the combo box column upon a button click way after the grid has been
bound to the data source.
 
M

Michael Schindler

It is possible you set my code in the right form?

I try now more as one day for this solution and now i have no more patience

I have a siple code with a datagrin and into this datagrid i want a combobox
that the user can coise open or close...that is all...but i have many
problems
with this control into a datagrid and all exampels ar others as my code.

Thank

Michael

For test i have a button yes.

Later I make from this source a methode. If I start this form i start this
methode.
 

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