Hi,
I have a grid-view with multiple grids working together, and one of the tasks at hand is if a value changes in a cell in one grid, then the main grid has to highlight any objects that shared that data that were affected by the change. The customer then needs to compile that data and at that point, the row for that object needs to have the highlight removed. I am able to get the conditional formatting for the highlight to work, but removing it from the entire row after the button click is proving to be a challenge. currently my code is set to do this using the following:
public void GridHighLighterSetConditions()
{
int x = -1;
double Index1 = - 1;
double Index2 = - 1;
double Index3 = - 1;
string MIDindex = "";
int RowIndex = 0;
int MID = 0;
foreach (GridViewDataRowInfo Index in MainGridView.SelectedRows)
{
if (MainGridView.SelectedRows.Count > 0)
{
for (x = 0; x < MainGridView.SelectedRows.Count; x++)
{
RowIndex = MainGridView.SelectedRows[x].Index;
MIDindex = MainGridVIew.Rows[RowIndex].Cells[0].Value.ToString();
MID = int.Parse(MIDindex);
}
break;
}
}
foreach (GridViewDataRowInfo Event in GridView2.Rows)
{
if (GridView2.SelectedRows.Count > 0)
{
for (x = 0; x < GridView2.SelectedRows.Count; x++)
{
Index1 = GridView2.SelectedRows[x].Index + 1;
}
break;
}
}
foreach (GridViewDataRowInfo Vevent in GridView3.Rows)
{
if (GridView3.SelectedRows.Count > 0)
{
for (x = 0; x < GridView3.SelectedRows.Count; x++)
{
Index2 = GridView3.SelectedRows[x].Index + 1;
}
break;
}
}
foreach (GridViewDataRowInfo REvent in GridView4.Rows)
{
if (GridView4.SelectedRows.Count > 0)
{
for (x = 0; x < GridView4.SelectedRows.Count; x++)
{
Index3 = GridView4.SelectedRows[x].Index + 1;
}
break;
}
}
ConditionalFormattingObject HL_1 = new ConditionalFormattingObject("Highlighter", ConditionTypes.Equal, Index1.ToString(), "", true);
Font newFont = new Font("Arial", 8f, FontStyle.Bold);
HL_1.CellFont = newFont;
HL_1.CellForeColor = Color.DarkRed;
HL_1.RowBackColor = Color.Gold;
ConditionalFormattingObject HL_2= new ConditionalFormattingObject("Highlighter", ConditionTypes.Equal, Index2.ToString(), "", true);
Font newPBVFont = new Font("Arial", 8f, FontStyle.Bold);
HL_2.CellFont = newPBVFont;
HL_2.CellForeColor = Color.DarkRed;
HL_2.RowBackColor = Color.Gold;
ConditionalFormattingObject HL_3 = new ConditionalFormattingObject("Highlighter", ConditionTypes.Equal, Index3.ToString(), "", true);
Font newRVFont = new Font("Arial", 8f, FontStyle.Bold);
HL_3.CellFont = newRVFont;
HL_3.CellForeColor = Color.DarkRed;
HL_3.RowBackColor = Color.Gold;
ConditionalFormattingObject No_HL = new ConditionalFormattingObject("No Highlighter", ConditionTypes.Equal, MIDindex, "", true);
Font newUMCFont = new Font("Arial", 8f, FontStyle.Regular);
No_HL.CellFont = newUMCFont;
No_HL.RowBackColor = Color.White;
No_HL.CellForeColor = Color.Black;
if (Index1 > Index2 && Index1 > Index3)
{
MainGridView.Columns["Column1"].ConditionalFormattingObjectList.Add(HL_1);
GridView2.ClearSelection();
}
else if (Index2 > Index1 && Index2 > Index3)
{
MainGridView.Columns["column2"].ConditionalFormattingObjectList.Add(HL_2);
GridView3.ClearSelection();
}
else if (Index3 > Index1 && Index3 > Index2)
{
MainGridView.Columns["Column3"].ConditionalFormattingObjectList.Add(HL_3);
GridView4.ClearSelection();
}
else if (MIDindex != null && MID > Index1 && MID > Index2 && MID > Index3)
{
Index1 = -1;
Index2 = -1;
Index3 = -1;
MainGridView.Columns["Column0"].ConditionalFormattingObjectList.Add(No_HL);
MainGridView.ClearSelection();
MainGridView.Refresh();
}
return;
}
I Feel as though there must be a much easier way to do this.
Thanks.