PDA

Click to See Complete Forum and Search --> : [Resolved] Set datagrid cell enabled to false


indydavid32
Oct 21st, 2004, 08:53 AM
When a user hits the edit button, I want to either make a certain cell not enabled, or not visible. I don't care which. I can't seem to get either to work.

Here is my code that I tried:Dim cn As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;" _
& "Persist Security Info=False;" _
& "Initial Catalog=fuel info;" _
& "UID=;PWD=;" _
& "Data Source=Server7")
cn.Open()

Dim datAdapt As New OleDb.OleDbDataAdapter("Select Vendor_No as [Vendor No], " & _
"Vendor_Name as [Vendor Name], Vendor_Terminal as [Vendor Terminal], " & _
"Vendor_Trmnl_No As [Terminal No], Vendor_City As [City], Vendor_State As " & _
"[State], ID From Other_Vendors Order By Vendor_Name", cn)

Dim datSet As New Data.DataSet

datAdapt.Fill(datSet, "Other_Vendors")

DataGrid1.DataSource = datSet
DataGrid1.DataKeyField = "ID"
DataGrid1.EditItemIndex = e.Item.ItemIndex
e.Item.Cells(3).Enabled = False
DataGrid1.DataBind()
cn.Close()
cn.Dispose()
datAdapt.Dispose()
datSet.Dispose()
As you can see, the line that is not working is "e.item.cells(3).enabled = false"

Also, if anyone knows how to set the width of the cell on the fly as well, I would appreciate that as well.

Thanks

Phenglai
Oct 21st, 2004, 02:46 PM
Try looking into the ItemDataBound sub and adding


e.Item.Cells(3).Enabled = False


in there. You cant disable the cells before the data is in them. RIght now you are trying to disable that cell before the data has been bound to the grid.

Jerel

indydavid32
Oct 21st, 2004, 04:10 PM
Phelnglai, that did the trick. One more quick question. Could you set the cell width from the same place? If so, do you know the syntax? Thanks.

What about the cell header? What would the syntax be for that?

Thanks again!

indydavid32
Oct 25th, 2004, 11:51 AM
Nevermind, I see that if you just increase the width of the actual datagrid, the fields will increase and adjust on their own at run time.

Phenglai
Oct 26th, 2004, 07:03 AM
Glad you got it. Sorry I never answered your second question. I was in a car wreck and am just now getting back to work and doing thinks.

If you have any other questions, feel free to ask.

Jerel