Click here to Skip to main content
14,977,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello everybody,

i have problem with DefaultCellStyle in datagridview,

i have 3 column in my bank(Access) and i want when those records come to my datagridview change their format ,

for example their format is 12000 but i want to change their format in datagridview like 12,000. this is my code "

da.SelectCommand = New OleDbCommand()

        With da.SelectCommand
            .Connection = my_con
            .CommandType = CommandType.Text
            .CommandText = "Select p_name,p_fname,p_mablagh from table1"

            If .Connection.State <> ConnectionState.Open Then
            End If
        End With

        Dim ds As New Database2DataSet
        Me.DataGridView1.DataSource = ds.Table1
        Me.DataGridView1.Columns(2).DefaultCellStyle.Format = "##,0"

first :


want this "


my english is not very well please help me.

thanks a lot

As seen from the images at URL specified in your question, the formatting is required in second Column. So, the Column Index will be 1.
Set the Format property as below
Me.DataGridView1.Columns(1).DefaultCellStyle.Format = "#,0"
i really need that .... please help me....

thanks a lot.
thank yo for your answer but if u see my code ,

i wrote your code in my code ! but it didnt work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900