|
-
Dec 8th, 2003, 06:11 AM
#1
Thread Starter
Fanatic Member
Datagrid Columns
Hi all, anyone who can do this please help its been driving me crazy for ages
I want to be able to define the width of the column
ie column(1).width = 100 and so on i know its not the right syntax thats what i cant do....
this is my code i wana do it on
Dim dtePicker As Date
dteOrgDate = Me.MonthCalendar1.SelectionEnd
Dim intDay As Integer = dteOrgDate.Day
Dim intMth As Integer = dteOrgDate.Month
Dim intYr As Integer = dteOrgDate.Year
dteChaseDate = intMth & "/" & intDay & "/" & intYr
Dim data_adapter1, data_adapter2 As SqlDataAdapter
Dim strSql1 As String = "SELECT AppointmentTime as Time, CustomerName as Task FROM Appointments WHERE AppointmentDate = '" & dteChaseDate & "' AND AdvisorId = " & IdList(Me.cboEmployee.SelectedIndex) & " ORDER BY AppointmentTime"
data_adapter1 = New SqlDataAdapter(strSql1, MyConnection) ' Create the SqlDataAdapter.
data_adapter1.TableMappings.Add("Table", "MyCalendar")
m_DataSet1 = New DataSet ' Fill the DataSet.
data_adapter1.Fill(m_DataSet1)
DataGrid1.DataSource = m_DataSet1.Tables("MyCalendar") ' Bind the DataGrid control to the Contacts DataTable.
DataGrid1.ReadOnly = True
thanks all
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Dec 8th, 2003, 01:36 PM
#2
Fanatic Member
You need to implement CustomTableStyles for the datagrid, and then you can set the length, etc of each of the columns.
-
Dec 8th, 2003, 05:06 PM
#3
Thread Starter
Fanatic Member
could u show me how with above code cos ive tired 100 times and cant seem to get it working
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Dec 8th, 2003, 05:26 PM
#4
Fanatic Member
Before you set your datasource for the grid, call this method (which is a sample for setting the width of a column named "SomeColumnName":
VB Code:
Private Sub AddCustomDataTableStyles(ByVal dstData As DataSet)
'Clear the table styles for the datagrid
DataGrid1.TableStyles.Clear()
'Declare local variables
Dim tsTableStyle As New DataGridTableStyle
Dim tcTextCol As DataGridTextBoxColumn
Dim intCounter As Integer
'Map the table style to the table in the dataset
tsTableStyle.MappingName = dstData.Tables(0).TableName()
'Add textbox column style for each column in the dataset
For intCounter = 0 To dstData.Tables(0).Columns.Count() - 1
'Reinstantiate the text box column and set mappings and attributes
tcTextCol = New DataGridTextBoxColumn
tcTextCol.MappingName = dstData.Tables(0).Columns.Item(intCounter).ColumnName
tcTextCol.HeaderText = dstData.Tables(0).Columns.Item(intCounter).ColumnName
'Set column size based on name
Select Case tcTextCol.MappingName()
Case "SomeColumnName"
tcTextCol.Width() = 100
Case Else
tcTextCol.Width() = 50
End Select
'Add the column to the table style
tsTableStyle.GridColumnStyles.Add(tcTextCol)
Next
'Add the table styles to the datagrid
DataGrid1.TableStyles.Add(tsTableStyle)
End Sub
-
Dec 9th, 2003, 04:37 AM
#5
Thread Starter
Fanatic Member
Thanks Buddy that works great
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
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
|