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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Bob
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.!!
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
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.