MuthuAnnamalai
asked on
Why my DatagridStyle is not working
I have given the code below, the datagridstyle which I am assigning to the datagrid is not working
'Create Table
Dim dt As New DataTable("DefaultPriceLev el")
'Add Columns
Dim dc As DataColumn
dc = New DataColumn("PriceLevel", System.Type.GetType("Syste m.String") )
dt.Columns.Add(dc)
dc = New DataColumn("MarkDownPercen t", System.Type.GetType("Syste m.String") )
dt.Columns.Add(dc)
dc = New DataColumn("Price", System.Type.GetType("Syste m.String") )
dt.Columns.Add(dc)
'Add Rows
Dim i% : For i = 0 To ds.Tables(3).Rows.Count - 1
Dim dr As DataRow
dr = dt.NewRow
dr("PriceLevel") = ds.Tables(3).Rows(i)(0)
dr("MarkDownPercent") = ds.Tables(3).Rows(i)(1)
dr("Price") = ds.Tables(3).Rows(i)(2)
dt.Rows.Add(dr)
Next
'Create Table Style
Dim ts As New DataGridTableStyle()
With ts
.RowHeadersVisible = False
.BackColor = Color.White
.AlternatingBackColor = Color.White
.HeaderBackColor = Color.LightSteelBlue
.AllowSorting = False
.HeaderBackColor = Color.FromArgb(115, 126, 183)
.HeaderForeColor = Color.White
.HeaderFont = New System.Drawing.Font("Arial ", 9.0F, System.Drawing.FontStyle.B old)
.GridLineColor = Color.DarkGray
.PreferredRowHeight = 22
End With
'Create Required Column Style (Department)
Dim column1 As New DataGridTextBoxColumn()
With column1
.MappingName = "PriceLevel"
.Width = 250
.Alignment = HorizontalAlignment.Left
.ReadOnly = False
End With
'Create Required Column Style (Active)
Dim column2 As New DataGridTextBoxColumn()
With column2
.MappingName = "MarkDown"
.Width = 100
.Alignment = HorizontalAlignment.Center
.ReadOnly = False
End With
'Create Required Column Style (Active)
Dim column3 As New DataGridTextBoxColumn()
With column3
.MappingName = "Price"
.Width = 100
.Alignment = HorizontalAlignment.Center
.ReadOnly = False
End With
'Add column styles to table style
ts.GridColumnStyles.Add(co lumn1)
ts.GridColumnStyles.Add(co lumn2)
ts.GridColumnStyles.Add(co lumn3)
'Add tablestyle to Datagrid and customize
With dgDefaultPriceLevel
.TableStyles.Add(ts)
.DataSource = dt
.CaptionVisible = False
End With
Any Help is highly appreciated
Regards,
Muthu Annamalai
'Create Table
Dim dt As New DataTable("DefaultPriceLev
'Add Columns
Dim dc As DataColumn
dc = New DataColumn("PriceLevel", System.Type.GetType("Syste
dt.Columns.Add(dc)
dc = New DataColumn("MarkDownPercen
dt.Columns.Add(dc)
dc = New DataColumn("Price", System.Type.GetType("Syste
dt.Columns.Add(dc)
'Add Rows
Dim i% : For i = 0 To ds.Tables(3).Rows.Count - 1
Dim dr As DataRow
dr = dt.NewRow
dr("PriceLevel") = ds.Tables(3).Rows(i)(0)
dr("MarkDownPercent") = ds.Tables(3).Rows(i)(1)
dr("Price") = ds.Tables(3).Rows(i)(2)
dt.Rows.Add(dr)
Next
'Create Table Style
Dim ts As New DataGridTableStyle()
With ts
.RowHeadersVisible = False
.BackColor = Color.White
.AlternatingBackColor = Color.White
.HeaderBackColor = Color.LightSteelBlue
.AllowSorting = False
.HeaderBackColor = Color.FromArgb(115, 126, 183)
.HeaderForeColor = Color.White
.HeaderFont = New System.Drawing.Font("Arial
.GridLineColor = Color.DarkGray
.PreferredRowHeight = 22
End With
'Create Required Column Style (Department)
Dim column1 As New DataGridTextBoxColumn()
With column1
.MappingName = "PriceLevel"
.Width = 250
.Alignment = HorizontalAlignment.Left
.ReadOnly = False
End With
'Create Required Column Style (Active)
Dim column2 As New DataGridTextBoxColumn()
With column2
.MappingName = "MarkDown"
.Width = 100
.Alignment = HorizontalAlignment.Center
.ReadOnly = False
End With
'Create Required Column Style (Active)
Dim column3 As New DataGridTextBoxColumn()
With column3
.MappingName = "Price"
.Width = 100
.Alignment = HorizontalAlignment.Center
.ReadOnly = False
End With
'Add column styles to table style
ts.GridColumnStyles.Add(co
ts.GridColumnStyles.Add(co
ts.GridColumnStyles.Add(co
'Add tablestyle to Datagrid and customize
With dgDefaultPriceLevel
.TableStyles.Add(ts)
.DataSource = dt
.CaptionVisible = False
End With
Any Help is highly appreciated
Regards,
Muthu Annamalai
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.