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
|
bool m_bEditInProgress = false;
private void uc_dgv_Tags_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if( uc_dgv_Tags.Rows.Count == 1 || m_bEditInProgress || (e.ColumnIndex < 4) )
{
return;
}
if( e.RowIndex == 0 )
{// on clique sur un entete -> on met la meme valeur pour la colonne en entier //
m_bEditInProgress = true;
CheckState currentvalue = CheckState.Indeterminate;
bool currentbvalue = false;
bool bbool = false;
if( uc_dgv_Tags[e.ColumnIndex, e.RowIndex].EditedFormattedValue is CheckState )
{
currentvalue = (CheckState)uc_dgv_Tags[e.ColumnIndex, e.RowIndex].EditedFormattedValue;
bbool = false;
}
else
{
currentbvalue = (bool)uc_dgv_Tags[e.ColumnIndex, e.RowIndex].EditedFormattedValue;
bbool = true;
}
if( (!bbool && (currentvalue == CheckState.Indeterminate)) || (bbool && (currentbvalue)) )
{
(uc_dgv_Tags[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell).ThreeState = false;
}
for( int i = 1; i < uc_dgv_Tags.Rows.Count; ++i )
{
DataGridViewCheckBoxCell cbcell = uc_dgv_Tags[e.ColumnIndex, i] as DataGridViewCheckBoxCell;
if( (!bbool && currentvalue == CheckState.Checked) || (bbool && currentbvalue) )
{
cbcell.Value = true;
}
else
{
cbcell.Value = false;
}
}
m_bEditInProgress = false;
}
else
{
m_bEditInProgress = true;
uc_dgv_Tags[e.ColumnIndex, e.RowIndex].Value = !(bool)uc_dgv_Tags[e.ColumnIndex, e.RowIndex].Value;
bool btoutafaux = true;
bool btoutavrai = true;
bool bAumoinsunAfaux = false;
bool bAumoinsunAvrai = false;
for( int j = 1; j < uc_dgv_Tags.Rows.Count; ++j )
{
if( (bool)uc_dgv_Tags[e.ColumnIndex, j].Value )
{
bAumoinsunAvrai = true;
btoutafaux = false;
}
else
{
btoutavrai = false;
bAumoinsunAfaux = true;
}
}
DataGridViewCheckBoxCell cbcell = uc_dgv_Tags[e.ColumnIndex, 0] as DataGridViewCheckBoxCell;
if( (bAumoinsunAvrai && bAumoinsunAfaux) && (!btoutafaux && !btoutavrai) )
{
cbcell.ThreeState = true;
cbcell.Value = CheckState.Indeterminate;
}
else if( btoutavrai )
{
uc_dgv_Tags[e.ColumnIndex, 0].Value = CheckState.Checked;
}
else if( btoutafaux )
{
uc_dgv_Tags[e.ColumnIndex, 0].Value = CheckState.Unchecked;
}
}
m_bEditInProgress = false;
} |
Partager