Jayesh Acharya
asked on
cell fromtating of DataGridView need to compare two values from two cells same row, c#
I have a win form that has a gridview, and I need to change the color of the cell, based on itslef and a different cell.
If you look at the code below it works fine when changign the color of the cell besad on the current cells value.
But I need to be able to compare both values and then change the cell color.
The position of the colums can change but not the name.
private void ECCN_CellFormatting(DataGr idViewCell Formatting EventArgs ee, string case_str)
{
switch (case_str)
{
case "Y": ee.CellStyle.BackColor = Color.LawnGreen; break;
case "N": ee.CellStyle.BackColor = Color.Red; break;
case "0": ee.CellStyle.BackColor = Color.Red; ee.CellStyle.ForeColor = Color.Yellow; break;
default: break;
}
}
private void dataGridView_CellFormattin g(object sender, DataGridViewCellFormatting EventArgs ee)
{
switch (dataGridView1.Columns[ee. ColumnInde x].Name)
{
case "eccn_available": ECCN_CellFormatting(ee, (string)ee.Value); break;
case "eccn_value": ECCN_CellFormatting(ee, (string)ee.Value); break;
default: break;
}
}
these methods are called by :
public void InitializeGrid(DataGridVie w lv_StockCheckdataGridView
,string GridViewName)
{
lv_StockCheckdataGridView. ColumnHead ersHeightS izeMode = System.Windows.Forms.DataG ridViewCol umnHeaders HeightSize Mode.AutoS ize;
lv_StockCheckdataGridView. ContextMen uStrip = this.contextMenuStrip1;
lv_StockCheckdataGridView. AllowUserT oAddRows = false;
lv_StockCheckdataGridView. AllowUserT oDeleteRow s = false;
lv_StockCheckdataGridView. AllowUserT oOrderColu mns = true;
lv_StockCheckdataGridView. Anchor = ((System.Windows.Forms.Anc horStyles) ((((System .Windows.F orms.Ancho rStyles.To p | System.Windows.Forms.Ancho rStyles.Bo ttom)
| System.Windows.Forms.Ancho rStyles.Le ft)
| System.Windows.Forms.Ancho rStyles.Ri ght)));
lv_StockCheckdataGridView. Size = new System.Drawing.Size(1074, 604);
lv_StockCheckdataGridView. TabIndex = 5;
lv_StockCheckdataGridView. MouseDown += new System.Windows.Forms.Mouse EventHandl er(this.da taGridView 1_MouseDow n);
lv_StockCheckdataGridView. CellFormat ting += new System.Windows.Forms.DataG ridViewCel lFormattin gEventHand ler(this.d ataGridVie w_CellForm atting);
lv_StockCheckdataGridView. Location = new System.Drawing.Point(12, 43);
lv_StockCheckdataGridView. Name = GridViewName;
lv_StockCheckdataGridView. ReadOnly = true;
lv_StockCheckdataGridView. AllowUserT oResizeCol umns = true;
}
I need a way to look at all the values for the rows I have just populated in the grid and
If you look at the code below it works fine when changign the color of the cell besad on the current cells value.
But I need to be able to compare both values and then change the cell color.
The position of the colums can change but not the name.
private void ECCN_CellFormatting(DataGr
{
switch (case_str)
{
case "Y": ee.CellStyle.BackColor = Color.LawnGreen; break;
case "N": ee.CellStyle.BackColor = Color.Red; break;
case "0": ee.CellStyle.BackColor = Color.Red; ee.CellStyle.ForeColor = Color.Yellow; break;
default: break;
}
}
private void dataGridView_CellFormattin
{
switch (dataGridView1.Columns[ee.
{
case "eccn_available": ECCN_CellFormatting(ee, (string)ee.Value); break;
case "eccn_value": ECCN_CellFormatting(ee, (string)ee.Value); break;
default: break;
}
}
these methods are called by :
public void InitializeGrid(DataGridVie
,string GridViewName)
{
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
| System.Windows.Forms.Ancho
| System.Windows.Forms.Ancho
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
lv_StockCheckdataGridView.
}
I need a way to look at all the values for the rows I have just populated in the grid and
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER