Results 1 to 5 of 5

Thread: [Resolved] Set datagrid cell enabled to false

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Resolved [Resolved] Set datagrid cell enabled to false

    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:
    VB Code:
    1. Dim cn As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;" _
    2.                                  & "Persist Security Info=False;" _
    3.                                  & "Initial Catalog=fuel info;" _
    4.                                  & "UID=;PWD=;" _
    5.                                  & "Data Source=Server7")
    6.         cn.Open()
    7.  
    8.         Dim datAdapt As New OleDb.OleDbDataAdapter("Select Vendor_No as [Vendor No], " & _
    9.         "Vendor_Name as [Vendor Name], Vendor_Terminal as [Vendor Terminal], " & _
    10.         "Vendor_Trmnl_No As [Terminal No], Vendor_City As [City], Vendor_State As " & _
    11.         "[State], ID From Other_Vendors Order By Vendor_Name", cn)
    12.  
    13.         Dim datSet As New Data.DataSet
    14.  
    15.         datAdapt.Fill(datSet, "Other_Vendors")
    16.  
    17.         DataGrid1.DataSource = datSet
    18.         DataGrid1.DataKeyField = "ID"
    19.         DataGrid1.EditItemIndex = e.Item.ItemIndex
    20.         e.Item.Cells(3).Enabled = False
    21.         DataGrid1.DataBind()
    22.         cn.Close()
    23.         cn.Dispose()
    24.         datAdapt.Dispose()
    25.         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
    Last edited by indydavid32; Oct 25th, 2004 at 11:51 AM.
    David Wilhelm

  2. #2
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262
    Try looking into the ItemDataBound sub and adding

    Code:
    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612
    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!
    David Wilhelm

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612
    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.
    David Wilhelm

  5. #5
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width