Last post Sep 05, 2017 02:54 PM by Mr.Torbati
Sep 05, 2017 07:41 AM|Mr.Torbati|LINK
I have a DataGridView that column 6 have integer value (8 digits). I want to format this column that put character "-" between digits in this format : "1234-56-78"
I write this code but don't show my desired result:
dataGridView4.Columns.DefaultCellStyle.Format = "N0";
Any help in advanced would be appreciated.
Sep 05, 2017 09:54 AM|Eric Du|LINK
According to your description and code, I think this issue is related to the winform, I think you could get the a suitable answer in this forum:
Also I try to make a sample to change value format, please check:
private void dataGridView1_CellFormatting_1(object sender, DataGridViewCellFormattingEventArgs e)
foreach (DataGridViewRow Myrow in dataGridView1.Rows)
string orgvalue = Myrow.Cells.Value.ToString();
string a = orgvalue.Substring(0, 4);
string b = orgvalue.Substring(4, 2);
string c = orgvalue.Substring(6, 2);
string objvalue = a + "-" + b + "-" + c;
Myrow.Cells.Value = objvalue;
Sep 05, 2017 02:54 PM|Mr.Torbati|LINK
Thanks a lot for your kindly help.
I think a paradox take place. We have integer values but shown in "Data grid view" like string that cause some error!