?
Solved

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

Posted on 2006-04-12
7
Medium Priority
?
226 Views
Last Modified: 2010-04-23
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.!!!

0
Comment
Question by:mackie1908
  • 3
  • 2
  • 2
7 Comments
 
LVL 96

Expert Comment

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

Bob
0
 

Author Comment

by:mackie1908
ID: 16440173
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
 
LVL 14

Expert Comment

by:jake072
ID: 16442326
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16446093
No, I meant marking that column as read-only.  Would that do?

Bob
0
 

Author Comment

by:mackie1908
ID: 16448435
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
 
LVL 14

Accepted Solution

by:
jake072 earned 2000 total points
ID: 16450108
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
 
LVL 14

Expert Comment

by:jake072
ID: 16450114
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

862 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