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
746 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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