• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 910
  • Last Modified:

Dataset datagrid and show columns


I have a dataset filled from an access database.
I've binded a datagrid to this dataset.
Several textboxes are binded also to the dataset.
Now I want to show only some of the columns of the dataset in the grid. All the columns are shown in the textboxes?
Do I have to use DataView ? I'm very new to these topics.

Thank you in advance
1 Solution
Hi Kgenius,

there a a couple of things you can do one is this.

Create your own datagridtablestyle and gridcolumnstyles and just create the ones you want

Dim ts As DataGridTableStyle
        ts = New DataGridTableStyle
        ts.MappingName = ds.Tables(0).ToString()

        Dim col1 As New DataGridTextBoxColumn
        With col1
            .MappingName = "STOCKNUM"
            .HeaderText = "Stock #"
            .Width = 80
        End With

        Dim col2 As New DataGridTextBoxColumn
        With col2
            .MappingName = "DESC"
            .HeaderText = "Description"
            .Width = 100
        End With

        Dim col3 As New DataGridTextBoxColumn
        With col3
            .MappingName = "ASKINGPRICE"
            .HeaderText = "Asking Price"
            .Width = 100
            .Format = "c"
            .TextBox.TextAlign = HorizontalAlignment.Right
            .Alignment = HorizontalAlignment.Right

        End With

        ts.GridColumnStyles.AddRange(New DataGridColumnStyle() {col1, col2, col3})

or set the width of the ones you don't want to 0, like

Dim ts As DataGridTableStyle
        ts = New DataGridTableStyle
        ts.MappingName = ds.Tables(0).ToString()

        DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 100 'show col 1
        DataGrid1.TableStyles(0).GridColumnStyles(1).Width = 0    'don't show col 2 etc..
        DataGrid1.TableStyles(0).GridColumnStyles(2).Width = 100
        DataGrid1.TableStyles(0).GridColumnStyles(3).Width = 0
        DataGrid1.TableStyles(0).GridColumnStyles(4).Width = 100

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now