Solved

DataGrid - How do I disable (or make visible = false) for a specific column on my edit row and keep the rest editable. (this would be based on the user logged in)

Posted on 2004-03-30
6
747 Views
Last Modified: 2007-12-19
This is what I have inside my function:

    Private Sub dtgItemMstr_EditCommand _
    (ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles dtgItemMstr.EditCommand
        Response.Write(" --EditItem-- ")

        dtgItemMstr.EditItemIndex = e.Item.ItemIndex
        'Cell => rows (table cells)
        'Controls => columns

        da.Fill(dsItemMstr)
        dtgItemMstr.DataSource = dsItemMstr
        dtgItemMstr.DataBind()
    End Sub


Now I want to disable certain columns -> make them UNeditable and keep the others editable, how do I reference a specific column on my edit row?

I've tried:
        e.Item.Cells(e.Item.ItemIndex).Controls(0).FindControl("txtPartDescrip").Visible = False

Note:
All my colums are template columns not bound.

Please help.

Thanks!
0
Comment
Question by:africaoh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10717711
Hi,
U cannot disable a column in a DataGrid, but u can make  the column as readonly.  Try this sample code IN THE Mouse_Down event of the Data Grid

   Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
        Dim strValue As String
        Dim Hi As DataGrid.HitTestInfo
        Try
            Hi = dgrMenuDetails.HitTest(e.X, e.Y)
            strValue = dgrMenuDetails.Item(Hi.Row, Hi.Column)

            Select Case Hi.Column ' Select the column that u want to make as read only
                Case 0
                        dgrMenuDetails.TableStyles.Item(0).GridColumnStyles.Item("COL_MAP1").ReadOnly = True
                Case 1
                    If strValue = <some value> Then
                        dgrMenuDetails.TableStyles.Item(0).GridColumnStyles.Item("COL_MAP2").ReadOnly = True
                    Else
                        dgrMenuDetails.TableStyles.Item(0).GridColumnStyles.Item("COL_MAP2").ReadOnly = False
                    End If

            End Select
        Catch
        End Try
    End Sub
0
 

Author Comment

by:africaoh
ID: 10717783
I've also tried:

       'Try to print the value of a specific column of the edit row, get the following error:
       'System.NullReferenceException: Object reference not set to an instance of an object.

        Dim blah As TextBox = CType(e.Item.Cells(e.Item.ItemIndex).FindControl("txtPartDescrip"), TextBox)
        Reponse.Write(blah.text)

Still no luck


0
 

Author Comment

by:africaoh
ID: 10718260
Got it working with the following, think the problem was the fact that i had it in my edit function and not in my update function, hence the field was not a textbox yet, well that's what im thinking, here goes the working code:

 Private Sub dtgItemMstr_UpdateCommand _
    (ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles dtgItemMstr.UpdateCommand

        Dim test As TextBox = e.Item.Cells(e.Item.ItemIndex).FindControl("txtDrawingNum")
        Response.Write("=== " & test.Text & " ===")
        test.ReadOnly = True

        DataBind()

    End Sub

With the above I can get the text value out of my edit row from the "txtDrawingNum" column! kewl now I still cant get the thing disables though... or readonly or whatever, anyone has any ideas?????????????
0
 

Accepted Solution

by:
africaoh earned 0 total points
ID: 10724357
Fellas,

This is actually little easier than I made it, all I did was simply hide the column when Im going into edit mode and then display again with this command


dtgItemMstr.Columns(x).Visible = False
dtgItemMstr.Columns(x).Visible = True

Rather than trying to make the field un-editable... that would also be possible, but you would have to create your template columns in code with a new class, which is not too hard to do either.... if you have the time to do so, e.g. based on certain user's login you would have different template columns... if you need to know how look at this fella's example:
http://www.codeproject.com/Purgatory/templatecolumn.asp

0

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question