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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| private void cellchange(object sender, System.EventArgs e)
{
bool b = ((System.Windows.Forms.Control)(sender)).Name.Contains("traction");
if (b == true)
{
String z = ((System.Windows.Forms.Control)(sender)).Name.Remove(0, 8);
int v = int.Parse(z);
if (tlabel8[v].Text == "Traction")
{
if (tdata[v].CurrentCell.ColumnIndex == 0)
{
DataGridView Dgv = (DataGridView)sender;
DataGridViewComboBoxColumn DgvCbCol = (DataGridViewComboBoxColumn)Dgv.Columns[0];
if (tdata[v].CurrentCell.RowIndex == 0)
{
// on rajoute la valeur saisie aux items du ComboBox
if (DgvCbCol.Items.Contains(tdata[v].CurrentCell.Value + "/" + tdata[v].Rows[1].Cells[0].Value))
{
tdata[v].Rows[2].Cells[0].Value = tdata[v].CurrentCell.Value + "/" + tdata[v].Rows[1].Cells[0].Value;
}
else
{
DgvCbCol.Items.Add(tdata[v].CurrentCell.Value + "/" + tdata[v].Rows[1].Cells[0].Value);
tdata[v].Rows[2].Cells[0].Value = tdata[v].CurrentCell.Value + "/" + tdata[v].Rows[1].Cells[0].Value;
}
if (suprimer != null)
{
DgvCbCol.Items.Remove(suprimer.ToString());
suprimer = null;
}
}
if (tdata[v].CurrentCell.RowIndex == 1)
{
// on rajoute la valeur saisie aux items du ComboBox
if (DgvCbCol.Items.Contains(tdata[v].Rows[0].Cells[0].Value + "/" + tdata[v].CurrentCell.Value))
{
tdata[v].Rows[2].Cells[0].Value = tdata[v].Rows[0].Cells[0].Value + "/" + tdata[v].CurrentCell.Value;
}
else
{
DgvCbCol.Items.Add(tdata[v].Rows[0].Cells[0].Value + "/" + tdata[v].CurrentCell.Value);
tdata[v].Rows[2].Cells[0].Value = tdata[v].Rows[0].Cells[0].Value + "/" + tdata[v].CurrentCell.Value;
}
if (suprimer != null)
{
DgvCbCol.Items.Remove(suprimer.ToString());
suprimer = null;
}
}
}
}
}
}
private void EditGridView_ControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control.GetType() == typeof(DataGridViewComboBoxEditingControl))
{
DataGridViewComboBoxEditingControl Cb = (DataGridViewComboBoxEditingControl)e.Control;
Cb.DropDownStyle = ComboBoxStyle.DropDown;
DataGridView Dgv = (DataGridView)sender;
bool b = ((System.Windows.Forms.Control)(sender)).Name.Contains("traction");
if (b == true)
suprimer = Dgv.Rows[2].Cells[0].Value.ToString();
}
}
private void EditGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
DataGridView Dgv = (DataGridView)sender;
if (Dgv.Columns[e.ColumnIndex].GetType() == typeof(DataGridViewComboBoxColumn))
{
DataGridViewComboBoxColumn DgvCbCol = (DataGridViewComboBoxColumn)Dgv.Columns[e.ColumnIndex];
try
{ // on rajoute la valeur saisie qaux items du ComboBox
Object Value = Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].ParseFormattedValue(e.FormattedValue, DgvCbCol.DefaultCellStyle, null, null);
if (DgvCbCol != null && Value != null && e.FormattedValue.ToString() != "" && !DgvCbCol.Items.Contains(e.FormattedValue)) DgvCbCol.Items.Add(Value);
Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Value;
}
catch
{
MessageBox.Show("Invalid value provided for column " + Dgv.Columns[e.ColumnIndex].Name + " :" + e.FormattedValue.ToString());
e.Cancel = true;
}
}
}
//private void GridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
//{
// DataGridView Dgv = (DataGridView)sender;
// if (e.Exception.Message.ToString().Contains("DataGridViewComboBox"))
// {
// Dgv.CurrentCell.Value = DBNull.Value;
// }
// else MessageBox.Show(e.Exception.Message.ToString());
// e.Cancel = true;
//}
private void CellValidating(object sender , DataGridViewCell e)
{
DataGridView Dgv = (DataGridView)sender;
if (Dgv.Columns[e.ColumnIndex].GetType() == typeof(DataGridViewComboBoxColumn))
{
DataGridViewComboBoxColumn DgvCbCol = (DataGridViewComboBoxColumn)Dgv.Columns[e.ColumnIndex];
try
{ // on rajoute la valeur saisie aux items du ComboBox
Object Value = Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].ParseFormattedValue(e.FormattedValue, DgvCbCol.DefaultCellStyle, null, null);
if (DgvCbCol != null && Value != null && e.FormattedValue.ToString() != "" && !DgvCbCol.Items.Contains(e.FormattedValue)) DgvCbCol.Items.Add(Value.ToString() + Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = (Value.ToString() + Dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
return;
}
catch
{
MessageBox.Show("Invalid value provided for column " + Dgv.Columns[e.ColumnIndex].Name + " :" + e.FormattedValue.ToString());
}
}
} |
Partager