DataGrid Formating for Headers and Columns

Hello out there.

I am new to .Net and I am trying to use the datagrid to show some data from my access DB.  Here are the following columns that I want to display.

STOCKNUM Text
DESC Text
ASKINGPRICE Currency

I want to be able to fill the data grid with these fields but I want to change the column headers to more user friendly names (Stock #, Description, Asking Price)

and also I want the last column (Asking Price) to be formatted in currency and aligned to the right.

here is my relevant code:

Private dvInventory As DataView
    Private mydaInventory As OleDbDataAdapter
    Dim ds As New DataSet


   With cmdSelect
            .CommandText = "Select  StockNum, Desc, AskingPrice From Inventory"
            .Connection = cnn
        End With

        mydaInventory = New OleDbDataAdapter
        mydaInventory.SelectCommand = cmdSelect

        cnn.Open()

        mydaInventory.Fill(ds)
        cnn.Close()

    dvInventory = ds.Tables(0).DefaultView

        With grdInventory
            .DataSource = dvInventory
            .AllowNavigation = False
        End With


How do get this to look the way I want?
TyghAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

flavoCommented:
>>"Select  StockNum, Desc, AskingPrice From Inventory"

Change it to

select stockNum as [Stock #], Desc as [Description], Format(AskingPrice,"currency")  as [Asking Price] from Inventory

Dave!
0
flavoCommented:
oh sorry, its not going to like the " around currency

"select stockNum as [Stock #], Desc as [Description], Format(AskingPrice,'currency')  as [Asking Price] from Inventory"

Dave
0
RonaldBiemansCommented:
or you could use the datagridcolumn styles, something like

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
        End With

        ts.GridColumnStyles.AddRange(New DataGridColumnStyle() {col1, col2, col3})
        DataGrid1.TableStyles.Add(ts)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

TyghAuthor Commented:
I am attempting to do the datgrid column styles as shown above.  Is there another step?  It currently displays nothing in the datagrid.  I am wondering if I still have to bind the grid somehow.
0
TyghAuthor Commented:
Nevermind got it
0
TyghAuthor Commented:
One thing though, the right align is not working
0
RonaldBiemansCommented:
maybe try this instead

Dim col3 As New DataGridTextBoxColumn
        With col3
            .MappingName = "ASKINGPRICE"
            .HeaderText = "Asking Price"
            .Width = 100
            .Format = "c"
            .Alignment = HorizontalAlignment.Right
        End With
0
TyghAuthor Commented:
YEP!!!

Thanks a lot!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

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.