The dataset is filled with the expected data but the size is wrong.
Whenever I run with the code below numeric fields have a size of 1, vchar
fields a size of 5 and date fields a size of 2.
If I comment the column.width statements they all seem to default to about a
size of 12.
Can anyone twist my head in the right direction?
Thanks,
-Alex
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(Me.DataSet11)
'Step 1: Create a DataGridTableStyle &
' set mappingname to table.
Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "Clinics"
'Step 2: Create DataGridColumnStyle for each col
' we want to see in the grid and in the
' order that we want to see them.
'Step 2: ClinincID
Dim column As New DataGridTextBoxColumn
column.MappingName = "ClinicID"
column.HeaderText = "Clinic ID"
column.Width = 12
tableStyle.GridColumnStyles.Add(column)
'Step 2: ClinicName
column = New DataGridTextBoxColumn
column.MappingName = "ClinicName"
column.HeaderText = "Clinic Name"
column.Width = 30
tableStyle.GridColumnStyles.Add(column)
'Step 2: Administrator
column = New DataGridTextBoxColumn
column.MappingName = "Administrator"
column.HeaderText = "Administrator"
column.Width = 30
tableStyle.GridColumnStyles.Add(column)
'Step 2: ActivityCount
column = New DataGridTextBoxColumn
column.MappingName = "ActivityCount"
column.HeaderText = "Activity Count"
column.Width = 12
tableStyle.GridColumnStyles.Add(column)
'Step 2: LastActivityDateTime
column = New DataGridTextBoxColumn
column.MappingName = "LastActivityDateTime"
column.HeaderText = "Last Activity"
column.Width = 15
tableStyle.GridColumnStyles.Add(column)
'Step 3: Add the tablestyle to the datagrid
Me.DataGrid1.TableStyles.Add(tableStyle)
End Sub
When it come to column width, the browser considers your instructions as
recommendations only. It will make columns as wide as needed to accommodate
the content. You can try to trick the browser by using non-breaking spaces,
some other tricks, bust the best advice is to relax and put up with the
browser's superiority.
Eliyahu
"-Alex" <N...@No.com> wrote in message
news:1xMYc.4337$xY4....@news02.roc.ny...
I have reviewed you post, and will reply you latter. Thanks for your
understanding.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Sorry for letting you wait for so long time.
I think the problem should be that you did not specify the correct
MappingName property for the DataGridTableStyle. You should set the
DataGridTableStyle.MappingName to the datatable's tablename.
The below code snippet works well:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MakeParentTable()
Me.DataGrid1.DataSource = myDataSet.Tables(0)
Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "Clinics"
Dim column As New DataGridTextBoxColumn
column.MappingName = "id"
column.HeaderText = "Clinic ID"
column.Width = 50
tableStyle.GridColumnStyles.Add(column)
column = New DataGridTextBoxColumn
column.MappingName = "Item"
column.HeaderText = "Clinic Item"
column.Width = 100
tableStyle.GridColumnStyles.Add(column)
tableStyle.MappingName = "MyTable"
Me.DataGrid1.TableStyles.Add(tableStyle)
End Sub
Dim myDataSet As DataSet
Private Sub MakeParentTable()
' Create a new DataTable.
Dim myDataTable As DataTable = New DataTable("MyTable")
' Declare variables for DataColumn and DataRow objects.
Dim myDataColumn As DataColumn
Dim myDataRow As DataRow
' Create new DataColumn, set DataType, ColumnName and add to
DataTable.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.Int32")
myDataColumn.ColumnName = "id"
myDataColumn.ReadOnly = True
myDataColumn.Unique = True
' Add the Column to the DataColumnCollection.
myDataTable.Columns.Add(myDataColumn)
' Create second column.
myDataColumn = New DataColumn
myDataColumn.DataType = System.Type.GetType("System.String")
myDataColumn.ColumnName = "Item"
myDataColumn.AutoIncrement = False
myDataColumn.Caption = "ParentItem"
myDataColumn.ReadOnly = False
myDataColumn.Unique = False
' Add the column to the table.
myDataTable.Columns.Add(myDataColumn)
' Instantiate the DataSet variable.
myDataSet = New DataSet
' Add the new DataTable to the DataSet.
myDataSet.Tables.Add(myDataTable)
' Create three new DataRow objects and add them to the DataTable
Dim i As Integer
For i = 0 To 2
myDataRow = myDataTable.NewRow()
myDataRow("id") = i
myDataRow("Item") = "Item " + i.ToString()
myDataTable.Rows.Add(myDataRow)
Next i
End Sub
====================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Is your problem resolved? Do you still have any concern on this issue?
Please feel free to tell me. Thanks