Solved

Dataview Column Width

Posted on 2004-08-14
5
454 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with sorting data in Listbox using VB.NET 3 62
LINQ - C# to VB convertion 12 57
Help with Syntax 9 37
Import a txt file into a DataGridView and TextBox 20 38
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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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