Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding DataGrid to Collection
Message
 
To
27/05/2003 13:55:23
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00793192
Message ID:
00793211
Views:
26
This message has been marked as the solution to the initial question of the thread.
Dan,

To format the DataGrid the way you want it you must use the "DataGridTableStyle", review the following code it may help you.
' Load DataGrid
Me.dgSearchResult.DataSource = myDS.Tables("Search")
Me.dgSearchResult.ReadOnly = True
Me.dgSearchResult.AllowNavigation = False
Me.dgSearchResult.AllowSorting = False

' Now, Add the new DataGrid view
Call MyAddCustomDataTableStyle_Search()

Private Sub MyAddCustomDataTableStyle_Search()
        ' Make new DataTableStyle for DataGrid
        Dim ts As New DataGridTableStyle()
        ts.MappingName = "Search"
        ts.ReadOnly = True
        ts.AllowSorting = False
        ts.AlternatingBackColor = Color.LightYellow

        Dim TextCol1 As New DataGridTextBoxColumn()
        TextCol1.MappingName = "EmployeeID"
        TextCol1.HeaderText = "EmployeeID"
        TextCol1.Width = 65
        TextCol1.NullText = ""

        ts.GridColumnStyles.Add(TextCol1)

        Dim TextCol2 As New DataGridTextBoxColumn()
        TextCol2.MappingName = "Name_e"
        TextCol2.HeaderText = "English Name"
        TextCol2.Width = 150
        TextCol2.NullText = ""

        ts.GridColumnStyles.Add(TextCol2)

        Dim TextCol3 As New DataGridTextBoxColumn()
        TextCol3.MappingName = "Name_a"
        TextCol3.HeaderText = "Arabic Name"
        TextCol3.Width = 150
        TextCol3.NullText = ""

        ts.GridColumnStyles.Add(TextCol3)

        Dim TextCol4 As New DataGridTextBoxColumn()
        TextCol4.MappingName = "CivilID"
        TextCol4.HeaderText = "Civil ID"
        TextCol4.Width = 90
        TextCol4.NullText = ""

        ts.GridColumnStyles.Add(TextCol4)

        ' Add the TableStyle to the original DataGrid
        Me.dgSearchResult.TableStyles.Add(ts)
End Sub
HTH


>I'm trying to bind a collection to the Windows Forms DataGrid. How do I format the grid to display the columns I want? I've tried creating a DataGridTableStyle object but it doesn't seem to use it. Any ideas?
>
>Thanks,
>Dan
<><><><><><><><><><><><><><><><><><><><>
<><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
<><><><><><><><><><><><><><><><><><><><>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform