I have a datagrid with a column, ID with values like 1,2,3,4,5….10,11,12,13…
I want all the values should be of length two, means i want the values as 01,02,03….10,11,12…
How to do it?
EDIT
I am using Winforms.
EDIT
if (dg.Columns[e.ColumnIndex].Name == "Id")
{
try
{
//e.Value = String.Format("{0:00.0}", e.Value);
DataGridViewCellStyle ca = new DataGridViewCellStyle();
ca.ForeColor = System.Drawing.Color.Red;
ca.Format = "d2";
dg.Columns[e.ColumnIndex].DefaultCellStyle = ca;
e.FormattingApplied = true;
}
catch (FormatException)
{
e.FormattingApplied = false;
}
}
Here iam able to change backcolor and forecolor but the text format remains the same, no matter what i do. I even tried using String.Format (commented line) but its not working either.
I tried your code also, its not working. don’t know whats wrong.
Formatting the string with ToString(“00”) worked fine.