Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataGrid Column sizing - Help

Reply
Thread Tools

DataGrid Column sizing - Help

 
 
-Alex
Guest
Posts: n/a
 
      08-30-2004
I have snipped the following code from an example only to find that it
apparently doesn't work with regard to comlun sizing. I have been wrestling
with this to no avail.

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


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      08-31-2004
Alex,

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" <(E-Mail Removed)> wrote in message
news:1xMYc.4337$(E-Mail Removed)...
> I have snipped the following code from an example only to find that it
> apparently doesn't work with regard to comlun sizing. I have been

wrestling
> with this to no avail.
>
> 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
>
>



 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      08-31-2004
Hi Alex,

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.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      09-01-2004
Hi Alex,

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.

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.

 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      09-08-2004
Hi Alex,

Is your problem resolved? Do you still have any concern on this issue?
Please feel free to tell me. Thanks

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JTable column sizing Daniel Luis dos Santos Java 1 02-10-2010 03:05 PM
GridView Column sizing issue benis.ong@gmail.com ASP .Net 1 06-01-2006 01:36 AM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Datagrid & column sizing dew ASP .Net Datagrid Control 1 03-08-2006 06:32 PM
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM



Advertisments