Q: Formatting a column in a DataGrid

G

Geoff Jones

Hi

In a problem that was kindly solved for me in this newsgroup I had a table
which I was displaying in a DataGrid. One column had date and time. When
displayed in the grid it showed only the date part. I wanted the time to be
displayed. I was told I could do this by using the following code:

Dim aColumn1 As New DataGridTextBoxColumn
Dim aColumn2 As New DataGridTextBoxColumn

etc.

With aColumn1
.MappingName = "Col1"
.HeaderText = "Col1"
.Width = 50
End With

etc.

The column with the date/time has .Format set to the correct type to
display.

Finally, we use

With aGridStyle.GridColumnStyles
.Add(aColumn1)
etc.
End With

DataGrid1.TableStyles(aGridStyle)

As I say, the method works BUT what if the table I have has 100 columns?
Then using this method I have to create 100 DataGridTextBoxColumn objects
and then just add a format command to one of them.

I suspect there is an easier way to do it. As I say, all I need to do is to
change the format of one of the columns. Is there a way of doing this
without doing all the "unnecessary" work?

Thanks in advance guys

Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top