Solved

Dataset datagrid and show columns

Posted on 2004-10-28
903 Views
Last Modified: 2010-04-24
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
Question by:kGenius
    1 Comment
     
    LVL 25

    Accepted Solution

    by:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    This video discusses moving either the default database or any database to a new volume.

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now