[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 909
  • Last Modified:

Dataset datagrid and show columns

Hi,

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
kGenius
0
kGenius
Asked:
kGenius
1 Solution
 
RonaldBiemansCommented:
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})
        DataGrid1.TableStyles.Add(ts)

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.Add(ts)

        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


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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