Help in formating datagridview columns

bro840

Member
Joined
Aug 15, 2012
Messages
10
Programming Experience
1-3
Hi all

I have one DataSet bind to a one DGV. And in a Sub i have the code that formats the DGV columns.

Something like this


This works just fine.

dgJogos.Columns(4).SortMode = DataGridViewColumnSortMode.NotSortable
dgJogos.Columns(4).Width = 140
dgJogos.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
dgJogos.Columns(4).ReadOnly = False
dgJogos.Columns(4).DataPropertyName = "DATA"
dgJogos.Columns(4).HeaderText = "DATA"

This is not working

dgJogos.Columns(4).DefaultCellStyle.Format = "dd/mm/yy"
dgJogos.Columns(4).DefaultCellStyle.SelectionBackColor = Color.White

Can anyone help here?

Thank you
 
Hi,

You do not actually say what does not work but from what I can see your Date Format is incorrect and you should be using capitals for the Month in the format expression. In addition to this the Colour white for the SelectionBackColor is not a great selection since this will effectively look like the contents of the cell have disappeared since the default SelectionForeColor is also white.

Finally, if you need set multiple properties on the same object then its good practice to use a With Block. Have a look here:-

With someDataGridView.Columns(1)
  .DefaultCellStyle.Format = "dd/MM/yy"
  .DefaultCellStyle.SelectionBackColor = Color.White
  'Other Properties Associated with someDataGridView.Columns(1)
End With


Hope that helps.

Cheers,

Ian
 
Back
Top