|
-
Jul 21st, 2004, 05:47 AM
#1
Thread Starter
Junior Member
DataGrid Column Width
Hi,
I am newbie with regards to VB so please be gentle....
I am reading in a text file that I split into four fields using string slicing. I am creating a DataTable in code, and populating it with the data from the text file, and then creating a DataSet in code and adding the DataTable to the DataSet, and then binding these to a DataGrid that I have placed on my form at design time.
It all works wonderfully well, and is as fast as I could ever have wished for. However, I would like to be able to control the individual column widths in the DataGrid, and I can't see a way to do it as the "Preferred Width" Property applies to every column. My fields are something like this:
DAY.........DATE............TIME...........EVENT
Wed........01.07.2004.....10.04.09......The Blackbird Flies South
So I would like to be able to individually control the column widths.
Thanks.
-
Jul 21st, 2004, 05:54 AM
#2
This is what I have used.
ds is my dataset.
colDescription is a previously declared column that is present in the dataset.
VB Code:
'Set the column styles
Dim t As DataTable
For Each t In ds.Tables
Dim myGridTableStyle As DataGridTableStyle = New _
DataGridTableStyle()
Dim col As DataColumn
For Each col In ds.Tables("CalcTable").Columns
Dim c As New DataGridTextBoxColumn()
c.NullText = ""
c.HeaderText = col.Caption
c.MappingName = col.ColumnName
If col Is colDescription Then
c.Width = 150
Else
c.Width = 75
End If
myGridTableStyle.GridColumnStyles.Add(c)
Next
myGridTableStyle.MappingName = t.TableName
DataGrid1.TableStyles.Add(myGridTableStyle)
Next t
This world is not my home. I'm just passing through.
-
Jul 21st, 2004, 06:40 AM
#3
Thread Starter
Junior Member
You sir are, indeed, THE man!
That did the trick. Many thanks.
-
Aug 2nd, 2004, 12:19 PM
#4
Thread Starter
Junior Member
Further to this issue......
I have my DataTable, and have added the DataTable to the DataSet, and then bound these to a DataGrid that I have placed on my form at design time. Following the excellent help, I have also been able to change the column widths as required.
Now, I have an array (0 to maximum number of rows in the data grid) that contains a color entry that I want to be able to apply to each line (row) on the data grid. Ideally, I would like to be able to change the foreground and background colour of each row in the data grid based on the stored entry in the colour array.
Is this possible? I will eventually want to be able to use searches to filter the data that is displayed, and the colours will need to be consistent.
Many thanks.
-
Aug 3rd, 2004, 05:22 AM
#5
Try this link.
http://www.devx.com/vb2themax/Articl...8/1954?pf=true
Scroll down to the bottom and see if the example is what you are after. I haven't read through the whole thing myself, but it looks like what you are asking for.
This world is not my home. I'm just passing through.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|