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
745 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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