DataGridTableStyle
-
hi friends, i have a datagrid in my project and i m using a datatable to fill the datagrid.the default preferredcolumnwidht property is set to 200. but i want to use datagridtable style and disply the columns with different widhts but all efforts til now went in vain...... the code i used is pasted below.......... plz help me. the code for style whihc i used is commented..... hoping for quick solutions..... Dim lDataTable As New DataTable("ItemList") mintRecCount = Datasource.Length lDataTable.Columns.Add("Code", System.Type.GetType("System.String")) lDataTable.Columns.Add("Description", System.Type.GetType("System.String")) lDataTable.Columns.Add("UOM", System.Type.GetType("System.String")) lDataTable.Columns.Add("Quantity", System.Type.GetType("System.Int32")) 'lDataTable.Columns.Add("AltQty", System.Type.GetType("System.Int32")) lDataTable.Columns.Add("Weight", System.Type.GetType("System.Single")) lDataTable.Columns.Add("Price", System.Type.GetType("System.Single")) For mRowIndex = 0 To mintRecCount - 1 lDataRow = lDataTable.NewRow() 'code for entering data into the datarow lDataTable.Rows.Add(lDataRow) Next mRowIndex lDataTable.Columns(0).ReadOnly = True lDataTable.Columns(1).ReadOnly = True lDataTable.Columns(2).ReadOnly = True lDataTable.Columns(4).ReadOnly = True 'Dim ts As New DataGridTableStyle 'ts.MappingName = "ItemList" 'Dim cs As DataGridTextBoxColumn 'cs = New DataGridTextBoxColumn 'cs.MappingName = "Code" 'cs.HeaderText = "Code" 'cs.Width = 64 'ts.GridColumnStyles.Add(cs) 'similiar code for other columns 'dgOrdInvAddItem.TableStyles.Add(ts) dgOrdInvAddItem.DataSource = lDataTable
-
hi friends, i have a datagrid in my project and i m using a datatable to fill the datagrid.the default preferredcolumnwidht property is set to 200. but i want to use datagridtable style and disply the columns with different widhts but all efforts til now went in vain...... the code i used is pasted below.......... plz help me. the code for style whihc i used is commented..... hoping for quick solutions..... Dim lDataTable As New DataTable("ItemList") mintRecCount = Datasource.Length lDataTable.Columns.Add("Code", System.Type.GetType("System.String")) lDataTable.Columns.Add("Description", System.Type.GetType("System.String")) lDataTable.Columns.Add("UOM", System.Type.GetType("System.String")) lDataTable.Columns.Add("Quantity", System.Type.GetType("System.Int32")) 'lDataTable.Columns.Add("AltQty", System.Type.GetType("System.Int32")) lDataTable.Columns.Add("Weight", System.Type.GetType("System.Single")) lDataTable.Columns.Add("Price", System.Type.GetType("System.Single")) For mRowIndex = 0 To mintRecCount - 1 lDataRow = lDataTable.NewRow() 'code for entering data into the datarow lDataTable.Rows.Add(lDataRow) Next mRowIndex lDataTable.Columns(0).ReadOnly = True lDataTable.Columns(1).ReadOnly = True lDataTable.Columns(2).ReadOnly = True lDataTable.Columns(4).ReadOnly = True 'Dim ts As New DataGridTableStyle 'ts.MappingName = "ItemList" 'Dim cs As DataGridTextBoxColumn 'cs = New DataGridTextBoxColumn 'cs.MappingName = "Code" 'cs.HeaderText = "Code" 'cs.Width = 64 'ts.GridColumnStyles.Add(cs) 'similiar code for other columns 'dgOrdInvAddItem.TableStyles.Add(ts) dgOrdInvAddItem.DataSource = lDataTable
Here is some code I used in one of my projects and it worked quite fine. Hope it helps... Private Sub setDGProperties() dgDetails.TableStyles.Clear() Dim dgts As New DataGridTableStyle dgts.MappingName = "TransDetails" dgts.AlternatingBackColor = Color.LightGray Dim prod As New DataGridTextBoxColumn prod.MappingName = "ProductID" prod.HeaderText = "ProductID" dgts.GridColumnStyles.Add(prod) Dim cname As New DataGridTextBoxColumn cname.MappingName = "ProductName" cname.HeaderText = "Product Name" cname.Width = 120 dgts.GridColumnStyles.Add(cname) Dim quan As New DataGridTextBoxColumn quan.MappingName = "Quantity" quan.HeaderText = "Quantity" dgts.GridColumnStyles.Add(quan) Dim price As New DataGridTextBoxColumn price.MappingName = "TPrice" price.HeaderText = "Price" price.Format = "C" dgts.GridColumnStyles.Add(price) dgDetails.TableStyles.Add(dgts) End Sub