I'm want datagridview display numeric only for certain column.
eg: column is store length. data will display 25mm. Now I'm want show 25 only in datagridview column.

Recommended Answers

All 2 Replies

Hi Lianpiau, By hoping you'll solve your problem as soon as possible, do you know how to merge cells in runtime in datagridview?? :)

You will have to popualte DGV "manually". Row by row, column by column. You cannot use any dataSource, because you have to change a value. Unless if you do the binding and then go through all the rows in paint time, and change the values in partiucular column.
But this is again time consuming, so I would go to 1st option.

Where do you have data stored? In datatable?

DataTable table = new DataTable(); //fill your dataTable
            //this is my exmple dataTable creation and some example data to fill it:
            table.Columns.Add("col1", typeof(int));
            table.Columns.Add("col2", typeof(int));
            table.Columns.Add("col3", typeof(string));
            table.Rows.Add(1, 2, "35mm");
            table.Rows.Add(4, 53, "item43");
            table.Rows.Add(53, 2, "aa34bb");

            //DGV creation:
            dataGridView1.Columns.Add("col1", "Column 1");
            dataGridView1.Columns.Add("col2", "Column 2");
            dataGridView1.Columns.Add("col3", "Column 3");

            //lets assume that 3rd column is your Lenght column)! 
            int col, row = 0;
            foreach(DataRow dr in table.Rows)
            {
                col = 0;
                dataGridView1.Rows.Add();
                dataGridView1[col++, row].Value = dr[0];
                dataGridView1[col++, row].Value = dr[1];
                dataGridView1[col, row++].Value = string.Join(null, System.Text.RegularExpressions.Regex.Split(dr[2].ToString(), "[^\\d]"));
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.