Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. DataGridTableStyle

DataGridTableStyle

Scheduled Pinned Locked Moved Visual Basic
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joypreeti
    wrote on last edited by
    #1

    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

    W 1 Reply Last reply
    0
    • J joypreeti

      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

      W Offline
      W Offline
      Werner Vos
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups