Link to home
Start Free TrialLog in
Avatar of daverichardson
daverichardson

asked on

Dataview Column Width

how do i set a datagrids column width if it is bound to a dataview?
Avatar of srcalc
srcalc

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)
ASKER CERTIFIED SOLUTION
Avatar of srcalc
srcalc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of daverichardson

ASKER

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?
It looks good to me
Thanks