Solved

Dataview Column Width

Posted on 2004-08-14
5
450 Views
Last Modified: 2012-05-05
how do i set a datagrids column width if it is bound to a dataview?
0
Comment
Question by:daverichardson
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:srcalc
ID: 11802675
The following code will set the width of a column named myColumnName in a table named myTableName to 25. I assume that your DataGrid is called DataGrid1.

        Dim ts As New DataGridTableStyle
        ts.MappingName = "myTableName"
        datagrid1.TableStyles.Add(ts)
        Dim cs As New DataGridTextBoxColumn
        cs.MappingName = "myColumnName"
        cs.Width = 25
        datagrid1.TableStyles(0).GridColumnStyles.Add(cs)

If you need the name of your table do this:

MsgBox(CType(datagrid1.DataSource, DataView).Table.TableName)
0
 
LVL 4

Accepted Solution

by:
srcalc earned 50 total points
ID: 11802677
Sorry you code would be more accurate like this:

        Dim ts As New DataGridTableStyle
        ts.MappingName = "myTableName"
        Dim cs As New DataGridTextBoxColumn
        cs.MappingName = "myColumnName"
        cs.Width = 25
        ts.GridColumnStyles.Add(cs)
        datagrid1.TableStyles.Add(ts)
0
 

Author Comment

by:daverichardson
ID: 11803438
That Works Great, for multiple column i have used

Dim ts As New DataGridTableStyle
        ts.MappingName = "tblstockusage"
        Dim cs As New DataGridTextBoxColumn
        cs.MappingName = "stockcode"
        cs.Width = 120
        cs.HeaderText = "Stock Code"
        ts.GridColumnStyles.Add(cs)

        Dim cs1 As New DataGridTextBoxColumn
        cs1.MappingName = "description"
        cs1.Width = 210
        cs1.HeaderText = "Description"
        ts.GridColumnStyles.Add(cs1)

        Dim cs2 As New DataGridTextBoxColumn
        cs2.MappingName = "SalesQty"
        cs2.Width = 50
        cs2.HeaderText = "Qty"
        ts.GridColumnStyles.Add(cs2)

Is that the best way?
0
 
LVL 4

Expert Comment

by:srcalc
ID: 11804538
It looks good to me
0
 

Author Comment

by:daverichardson
ID: 11807427
Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now