rhino000 says:
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
|
private void dgEmp_CellFormatting( object sender, DataGridViewCellFormattingEventArgs e)
{
for ( int i = 0; i < Count; i++)
{
if (dgEmp.Columns[e.ColumnIndex].Name == "Status" )
{
if (e.Value.ToString() == "1" )
{
e.Value = "Completed" ;
}
}
if (dgEmp.Columns[e.ColumnIndex].Name == "Additional_Time" )
{
if (e.Value.ToString() == "0" )
{
e.Value = "No Additional Time Taken" ;
}
}
if (dgEmp.Columns[e.ColumnIndex].Name == "Remaining_Time" )
{
if (e.Value.ToString() == "0" )
{
e.Value = "No Remaining Time" ;
}
}
}
}
|
Am using this but in this if we use the else condition the else condtion values only displayed in the datagridview .....
here am not using else but if i using means it change all the values in datagrdview
1) You don’t need to use for loop as it will always call for each cell.
2) Value which you need to match for current column you can modify by checking its value as you did.
Change the code and check your result hope it will work fine.
private void dgEmp_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
/* It will check column name as STATUS and if status column value is 1 then it will modify the same value as you assigned */
if (dgEmp.Columns[e.ColumnIndex].Name.ToUpper() == "STATUS")
{
if (e.Value.ToString() == "1")
{
e.Value = "Completed";
}
}
/* It will check column name as ADDITIONAL_TIME and if status column value is 0 then it will modify the same value as you assigned */
if (dgEmp.Columns[e.ColumnIndex].Name.ToUpper() == "ADDITIONAL_TIME")
{
if (e.Value.ToString() == "0")
{
e.Value = "No Additional Time Taken";
}
}
/* It will check column name as REMAINING_TIME and if status column value is 0 then it will modify the same value as you assigned */
if (dgEmp.Columns[e.ColumnIndex].Name.ToUpper() == "REMAINING_TIME")
{
if (e.Value.ToString() == "0")
{
e.Value = "No Remaining Time";
}
}
}