Link to home
Start Free TrialLog in
Avatar of Tygh
Tygh

asked on

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?
Avatar of flavo
flavo
Flag of Australia image

>>"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!
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
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tygh
Tygh

ASKER

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.
Avatar of Tygh

ASKER

Nevermind got it
Avatar of Tygh

ASKER

One thing though, the right align is not working
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
Avatar of Tygh

ASKER

YEP!!!

Thanks a lot!!!