Datagrid Formatting

W

Wizard

Hi All,

I have the following code (See below) why when I run my app dosn`t it format
the Datagrid as below, instead it just loads up the default Column styles

Many Thanks
Wizard

Private Sub frmSystemUsers_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Format DataTable
Dim aGridTableStyle As New DataGridTableStyle()
aGridTableStyle.MappingName = "SystemUsers"
Dim aUserName As New DataGridTextBoxColumn()
Dim aFirstName As New DataGridTextBoxColumn()
Dim aSurname As New DataGridTextBoxColumn()
With aUserName
..MappingName = "Users_Name"
..HeaderText = "UserName"
..Width = 30
End With
With aFirstName
..MappingName = "User_First"
..HeaderText = "First Name"
..Width = 65
End With
With aSurname
..MappingName = "User_Last"
..HeaderText = "Surname"
..Width = 50
End With
With aGridTableStyle.GridColumnStyles
..Add(aUserName)
..Add(aFirstName)
..Add(aSurname)
End With
dgdSystemUsers.TableStyles.Add(aGridTableStyle)
If dsSystemUsers.Tables(0).Rows.Count > 0 Then
With dgdSystemUsers
..DataSource = dsSystemUsers.Tables(0)
..Expand(-1)
..NavigateTo(0, "Users_Name")
End With
End If
End Sub
End Class
 
K

Ken Tucker [MVP]

Hi,

The mapping name for the table style is wrong. Try this instead

aGridTableStyle.MappingName = dsSystemUsers.Tables(0).TableName

Ken
----------------------
Hi All,

I have the following code (See below) why when I run my app dosn`t it format
the Datagrid as below, instead it just loads up the default Column styles

Many Thanks
Wizard

Private Sub frmSystemUsers_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Format DataTable
Dim aGridTableStyle As New DataGridTableStyle()
aGridTableStyle.MappingName = "SystemUsers"
Dim aUserName As New DataGridTextBoxColumn()
Dim aFirstName As New DataGridTextBoxColumn()
Dim aSurname As New DataGridTextBoxColumn()
With aUserName
..MappingName = "Users_Name"
..HeaderText = "UserName"
..Width = 30
End With
With aFirstName
..MappingName = "User_First"
..HeaderText = "First Name"
..Width = 65
End With
With aSurname
..MappingName = "User_Last"
..HeaderText = "Surname"
..Width = 50
End With
With aGridTableStyle.GridColumnStyles
..Add(aUserName)
..Add(aFirstName)
..Add(aSurname)
End With
dgdSystemUsers.TableStyles.Add(aGridTableStyle)
If dsSystemUsers.Tables(0).Rows.Count > 0 Then
With dgdSystemUsers
..DataSource = dsSystemUsers.Tables(0)
..Expand(-1)
..NavigateTo(0, "Users_Name")
End With
End If
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top