Master / Detail Data - major issue/Bug?

PhillD

Well-known member
Joined
Mar 5, 2010
Messages
91
Programming Experience
10+
I have made several posts on here lately regarding master/detail or parent/child data setups but no one has been able to help. It seems like a subject people don't like to tackle BUT I really need help.

I'm having a real hard with the DataView.RowFilter functionality and it is driving me insane.

For the most part, I have the basic master/detail functionality working. When you select a record in the first grid, it shows the correct data in the second grid. When you enter a record in the first grid, you can enter related data in the second grid. I accomplish this by using a dataview and row filter bound to the 2nd grid. When you change the record in the first grid, the rowfilter for the 2nd grid is restated and reapplied.

The problem arises when I overwrite the primary field value in the first grid and the detail records become orphaned. You would think all I have to do is change the ID in the 2nd grid to match the new ID in the 1st grid but this is where I am having problems. I wrote a loop to change the ID of each record currently loaded in the 2nd grid to match the newly changed ID in the first grid. The code is here:

VB.NET:
Dim I As Integer

        For I = AuthorizationGroupsDGV.Rows.Count - 2 To 0 Step -1
            AuthorizationGroupsDGV.Rows(I).Cells(0).Value = StrEmployeeID
        Next
I have used this code before and it works great. It has to step backwards through the grid because when the ID's are changed, they no longer match the RowFilter criteria and they disappear from the grid. They still exist in the dataset. The problem is, while the code "works" the intended effect does not.

Some of the records completely disappear from the dataset and do not reload when I restate the row filter against the new ID number. I hope I am explaining this ok.

I will post some screen shots so you can see what I am talking about.

Someone please help me with this, I have been working on it for 2 weeks.

Employee.JPGEmployee2.JPG
 
The DefaultValuesNeeded event is not firing correctly when the grid is bound to data and you delete a line. I will have to write more code into the other event's to compensate for this "shortfall".

1) I was unable to reproduce your issue. My databound grid fired the DVN event reliably every time. I followed your instructions exactly
2) This is not the proper way to programmatically interact with bound data. To update a bound datasource we do not push data into controls (grids, textboxes etc designed to allow users to edit/view data) as though we were a user, we edit the underlying data model directly. In this particular case, this is also not the advocated way to apply an autoincrement to a datatable. Set the following properties of the column in question:
AutoIncrement = true
AutoIncrementSeed = 0
AutoIncrementStep = 1

Every time a new row is added to the table, the column's value will default to the next number in sequence
 

Latest posts

Back
Top