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
739 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now