Datagrid code not working!!

A

Angelina

Hi,

Im trying to format my datagrid via some code to make one
column readonly while the other can be edited.
I also tried to change the column header. The problem is
that the code does not seem to be taking effect.

Here is my code. Can anyone please offer me some help?

da = New SqlDataAdapter("SELECT Equipment_Desc, 0 as
Quantity FROM Equipment_Details", Cn)

ds = New DataSet("Equipment")
da.Fill(ds)

DataGridEquip.DataSource = ds.Tables(0)

Dim TSEquip As New DataGridTableStyle()
TSEquip.MappingName = "Equipment"

Dim TCEquipName As New DataGridTextBoxColumn()
TCEquipName.MappingName = "Equipment_Desc"
TCEquipName.HeaderText = "Equipment Name"
TCEquipName.Width = 110
TCEquipName.ReadOnly = True
TSEquip.GridColumnStyles.Add(TCEquipName)

Dim TCQuantity As New DataGridTextBoxColumn()
TCQuantity.MappingName = "Quantity"
TCQuantity.HeaderText = "Quantity"
TCQuantity.Width = 90
TCQuantity.ReadOnly = False
TSEquip.GridColumnStyles.Add(TCQuantity)


DataGridEquip.TableStyles.Add(TSEquip)
 
R

Rob Oldfield

I'm no expert, but I think the mapping name for the grid needs to be same as
the table that the data is coming from. Try changing to...

TSEquip.MappingName = "Equipment_Details"
 
A

Angelina

Hi Rob,

Thx for your input. I just tried this but i still cant
see any of the formatting i am coding in the datagrid at
runtime!! :blush:(

Does anyone have any other suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top