Datagrid code not working!!

  • Thread starter Thread starter Angelina
  • Start date Start date
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)
 
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"
 
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!! :o(

Does anyone have any other suggestions?
 
Back
Top