Assign Value to unbound DataGridViewComboBoxColumn  
Author Message
Koray Samsun





PostPosted: Windows Forms Data Controls and Databinding, Assign Value to unbound DataGridViewComboBoxColumn Top

Hi, i have a problem vith comboBoxColumn. i want to assign a value

to unbound comboBox cell and when i change its index want it to fire an event. I use CellFormatting event to assign value like below

private void dataGridView1_CellFormatting(object sender,DataGridViewCellFormattingEventArgs e)

{ //(unVisibleSourceColumn is unvisible and belongs to bound dataset)

if(dataGridView1.Columns[e.ColumnIndex].Name.Equals("comboColumn")) {

e.Value = Convert.ToString(dataGridView1.CurrentRow.Cells["unVisibleSourceColumn"].Value)}

}

At that point, assign unVisibleSourceColumn's value to combo just for new row . Registered SelectedIndexChanged event for combo in EditingControlShowing . The code in combo_SelectedIndexChanged is below

private void combo_SelectedIndexChanged(object sender, EventArgs e)

{

UpdateDataSetsUnVisibleSourceColumnValue()

// here just updates value of currentRows unVisibleSourceCells value for bound dataset

}

After this, the program seems to enter infinite loop because of CellFormatting (P4 CPU %100 and crashes)

My question is, why it calls CellFormatting continuously except just one time and if anyone have suggestion for that case:

datagridView is bound to a dataset, an unbound DataGridViewComboBox is added, want to add first value

to combocell according to sourceColumn in dataset and when changing index of it, updating sourceColumn value. Thanks to everyone..



Windows Forms17  
 
 
Koray Samsun





PostPosted: Windows Forms Data Controls and Databinding, Assign Value to unbound DataGridViewComboBoxColumn Top

Think i find it, just change selected index method like this

private void combo_SelectedIndexChanged(object sender, EventArgs e)

{

if(newComboValue == Convert.ToInt32(dataGridView1.CurrentRow.Cells["unVisibleSourceColumn"].Value))

UpdateDataSetsUnVisibleSourceColumnValue(newwComboValue)

// here just updates value of currentRows unVisibleSourceCells value for bound dataset

}

that solves infinite loop even if i can2t understand how. Since noone replies i thank to myself

Still interest in your offers, regards..