Results 1 to 6 of 6

Thread: how to programmatically change the Width to 15 of column number 6 on Datagrid1 and th

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    how to programmatically change the Width to 15 of column number 6 on Datagrid1 and th

    Gentlemen:

    Can anyone tell me how to programmatically change the Width to 15 of column number 6 on Datagrid1 and the format to currency?

    Thanks

    Andy

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    You should add a DatagridTableStlye to your datagrid and then the datagridtextboxcolumns and datagridboolcolumns. Then you can set the width and format. As an alternative you can format the data at dataset level but i am afraid there is no other way to set the width of the columns as the properties of default DatagridTableStyle of datagrid (that is created when you just set the datagrid datasource) is not accessible. Dont know if that means anything to you, and please ppl correct me if i am wrong.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376
    Could you please tell me if this is what you mean?


    Code:
    Dim dgStyle as DataGridTableStyle
    
    
    Dim dgTableStyle As New DataGridTableStyle()
    
    Me.DataGrid1.TableStyles.Clear()
    
    Dim colStyle1 As New DataGridTextBoxColumn()
    With colStyle1
    .Alignment = HorizontalAlignment.Left
    .HeaderText = "Name"
    .MappingName = "EmployeeName"
    .Width = 50
    End With
    
    dgTableStyle.GridColumnStyles.Add(colStyle1)
    
    dgTableStyle.MappingName = "tblEmployees"
    
    Me.DataGrid1.TableStyles.Add(dgTableStyle)

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Yes. But i think you dont need this :
    Me.DataGrid1.TableStyles.Clear() if you set the datagrid datasource at last. However not sure about it.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    How do you set the format to $Currency?

    Lunatic3:

    How do you set the format of this column to Currency$

    Code:
    Dim dgStyle as DataGridTableStyle
    
    
    Dim dgTableStyle As New DataGridTableStyle()
    
    Me.DataGrid1.TableStyles.Clear()
    
    Dim colStyle1 As New DataGridTextBoxColumn()
    With colStyle1
    .Alignment = HorizontalAlignment.Left
    .HeaderText = "Cost"
    .MappingName = "ItemCost"
    .Width = 20
    End With
    
    dgTableStyle.GridColumnStyles.Add(colStyle1)
    
    dgTableStyle.MappingName = "tblEmployees"
    
    Me.DataGrid1.TableStyles.Add(dgTableStyle)

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    VB Code:
    1. With colStyle1
    2.   .Format("c")
    3. '
    c represents the local currency format. Look here for details.
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemwindowsformsdatagridtextboxcolumnclassformattopic.htm
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width