Advertisement

[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/22/2008 at 07:26PM PDT, ID: 23753678
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

How to prevent entering duplicate record in DataGridView?

Asked by adlink_la in Microsoft Visual Basic.Net

Tags: Microsoft, Visual Studio 2005, SP1, DataGridView, VB.NET

Hello all,
I am using a DataGridView in unbound mode.  I have some code in the RowValidating event that works well to ensure that required values are present and not too long, etc.  This prevents the user from leaving the row until the data entered is valid or the Esc key is pressed.  Next, I have code in the RowValidated event to call the Update procedure for existing rows and the Insert procedure when a user enters a new row.

What I need to do is prevent the user from entering a record that already exists.  I tried having my insert procedure do the check and then pass back a message indicating that the record already exists.  This is working.  However, the problem is that duplicate record that the user just entered remains in the grid.  I tried putting the following in right after doing the insert:

grd.Rows.RemoveAt(e.RowIndex)

However, I get an error saying that this operation is not allowed in the RowValidated event.  I don't really want to put code in the RowValidating event to check for duplicates because that event fires on every keypress and I don't want that many calls to the database.

As I said, my Insert procedure already handles checking for an existing record and will not insert a duplicate.  All I need is to be able to remove the row that the user entered into the grid if it happens to be a duplicate and was not inserted.  Basically, I want the user to see the row disappear after the message is displayed indicating that the record was a duplicate, so that it is obvious and also because if it is not removed then the grid will contain two identical rows.

I've also tried the RowsAdded and the UserAddedRow events.  But these fire on the first keypress in the 'New Row' row.  I need to do the check after all of the data has been entered on the row.

So what event can I use to do this?  Sorry for the long post.

Thanks in advance.

View the Solution FREE for 30 Days
[+][-]09/22/08 10:08 PM, ID: 22546574

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/23/08 11:23 AM, ID: 22552391

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/23/08 09:15 PM, ID: 22556703

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: Microsoft, Visual Studio 2005, SP1, DataGridView, VB.NET
Sign Up Now!
Solution Provided By: MuhammadKashif
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09/24/08 08:56 AM, ID: 22561040

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/24/08 03:19 PM, ID: 22564604

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090429-EE-VQP-58 / EE_QW_2_20070628