How do i fire a message box when a user edits the datagrid.

I have a small application that allows you to plan and build a warehouse from scratch. it is a very basic application and does its job but something i over looked was the users need to brake things. i have a form that creates working zones separate working area's. the form has a datagrid that list all created zones and updates everytime one is added. the problem is even though if something is changed it will not save they need to bee told not to touch it. what i would like is to fire a message box that will tell them the details cannot be changed and then return the focus to another control that they can edit. i have looked all over the web and found nothing like what i am trying to do. could someone please help me with some code examples.!!!

mackie1908Asked:
Who is Participating?
 
jake072Commented:
mackie1908,

Making user controls is made extremely easy in VB here's a quick little intro...

On your solution, in the solution explorer, right-click and select Add->New Project...  Visual Basic, Windows Control Library.  (I've named mine JJDataGrid)...

When the code window pops up, you can copy/paste this little snippet:

Public Class JJDataGrid
    Inherits Windows.Forms.DataGrid

    Private fLockGrid As Boolean
    Public WriteOnly Property LockGrid() As Boolean
        Set(ByVal Value As Boolean)
            fLockGrid = Not fLockGrid
            If fLockGrid Then
                For Each d As DataGridColumnStyle In Me.TableStyles.Item(0).GridColumnStyles ' Set the Column to Readonly.
                    d.ReadOnly = True
                Next
            Else
                For Each d As DataGridColumnStyle In Me.TableStyles.Item(0).GridColumnStyles ' Reset the Column.
                    d.ReadOnly = False
                Next
            End If

        End Set
    End Property

    Sub New()
    End Sub

End Class

NOTE: This will set the ReadOnly of EVERY COLUMN in the grid to readonly, whenever you change it's value...  It's obviously a toggle, so if you call LockGrid twice, it will unlock it...  As you can see, it's quite simple, and it assumes that your using a tablestyle...  Make sure that you have one :)

It is easy to customize from here...

Usage: Where ever you have a DataGrid already setup in your form, simply replace System.Windows.Forms.DataGrid with JJDataGrid.JJDataGrid (Obviously you can name the solution to fit your needs)...  Et voila!  Let me know if you need more help.

Jake
0
 
Bob LearnedCommented:
If you have a column that you don't want to edit, would marking it as read-only help?

Bob
0
 
mackie1908Author Commented:
No I need the whole datagrid to error if the user tries to edit any cell within the datagrid. marking the datagrid as readonly allows me to lock the datagrid but depending on the operation the user is doing i will need to use the datagrid to edit and save data at sertain times. if i can use a simple message box to show an error and then retun focus to another control it allows me to define when the user can edit the grid very easily without using alot of code. help anyone.!! i have been trying different things allday and not getting anywhere.!!
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
jake072Commented:
Have you explored making your own user control?  I'm not at my development computer, but I'm sure that you could achieve something similar that you describe in a custom control.  Let me know if you would like some further help.

Jake
0
 
Bob LearnedCommented:
No, I meant marking that column as read-only.  Would that do?

Bob
0
 
mackie1908Author Commented:
Hi Jake

your proposal sounds very interesting. i did not know that you could create a user control within vb.net i thought they were only for asp.net use. if you can provide me with the examples of to build such a control i would be forever in dept to you.

mackie1908
0
 
jake072Commented:
Sorry,

I forgot to mention that I'm at my home PC, without Visual Studio, so that is untested...  But hopefully my memory will server me :)

Jake
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.