1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
DataGridViewComboBoxEditingControl f = e.Control as DataGridViewComboBoxEditingControl;
int row=f.EditingControlRowIndex;
DataGridViewCell vb= dataGridView1[0, row];
object obref=vb.Value;
typfammursource ooref = obref as typfammursource;
int idtref = ooref.getidtype();
bool ONVALID = true;
DataGridViewSelectedRowCollection cs = dataGridView1.SelectedRows;
{
foreach (DataGridViewRow r in cs)
{
object vv = r.Cells[0].Value;
typfammursource oo = vv as typfammursource;
if (oo == null)
{
ONVALID = false;
break;
}
else
{
int idtt = oo.getidtype();
if (idtt!=idtref)
{
ONVALID = false;
break;
}
}
}
}
// first remove event handler to keep from attaching multiple:
cb.SelectedIndexChanged -= new
EventHandler(cb_SelectedIndexChanged);
if (ONVALID)
{
// now attach the event handler
cb.SelectedIndexChanged += new
EventHandler(cb_SelectedIndexChanged);
}
}
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox cb = sender as ComboBox;
int ind = cb.SelectedIndex;
object ob = cb.SelectedItem;
if (ob != null)
{
DataGridViewSelectedRowCollection cs = dataGridView1.SelectedRows;
{
foreach (DataGridViewRow r in cs)
{
DataGridViewCell vv = r.Cells[1];
//vv.contro
System.Windows.Forms.DataGridViewComboBoxCell combo = vv as System.Windows.Forms.DataGridViewComboBoxCell;
//combo.contro
if (combo != null)
{
//combo.sele
combo.Value = ob;
}
}
}
}
} |
Partager