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.SelectComman d = 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?
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.SelectComman
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?
oh sorry, its not going to like the " around currency
"select stockNum as [Stock #], Desc as [Description], Format(AskingPrice,'curren cy') as [Asking Price] from Inventory"
Dave
"select stockNum as [Stock #], Desc as [Description], Format(AskingPrice,'curren
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
Nevermind got it
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
Dim col3 As New DataGridTextBoxColumn
With col3
.MappingName = "ASKINGPRICE"
.HeaderText = "Asking Price"
.Width = 100
.Format = "c"
.Alignment = HorizontalAlignment.Right
End With
ASKER
YEP!!!
Thanks a lot!!!
Thanks a lot!!!
Change it to
select stockNum as [Stock #], Desc as [Description], Format(AskingPrice,"curren
Dave!