Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dataview Column Width

Posted on 2004-08-14
5
Medium Priority
?
464 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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

963 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