Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
751 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

610 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