Ben Hayat
|
|
Group: Forum Members
Posts: 374,
Visits: 1.2K
|
I mentioned this as part of another post, but I thought to make it as a post of it's own.
I see a consistent problem trying to have data grid and SF navigation toolstrip to work with each other. The toolstrip does move the record pointer and I can see data in text box change, but the pointer in the grid does not change. The same problem exists vice versa. If I move the pointer in the grid, the data in the text box does not change.
Note: I actually had the same problem using ListView and I thought ListView is less capable than Std Grid View, so I changed to Grid view, but the same problem still continues.
I also looked at the sample (Business Binding Source) and the grid and toolstrip work together. And I can't find what else needs to be set.
My setup:
BO,
BBS
Data Grid view
Thanks!
..ßen
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
Let's take the ListView approach since it is less complicated to explain. SF comes with several ListView samples that show how to use ListViews with child records and how to move the record pointer. If you take a ListView, you will handle the SelectedIndexChanged event and then seek (or navigate depedning upon your needs) which will then move the record pointer and update any bound fields. We generally store the primary key in the Tag property of the ListView and then use it for the navigation: Private Sub MyListView_SelectedIndexChanged(Byval sender as Object, Byval e as EventArgs) Handles MyListView.SelectedIndexChanged If MyListView.SelectedItems.Count > 0 Then MyBO.NavigateToPrimaryKey(CType(MyListView.SelectedItems(0).Tag, Integer)) End If End Sub The same thing is true with a grid. You will have to manage the RowChanged or whatever event the grid you are using provides and then add the same logic.
|
|
|
Ben Hayat
|
|
Group: Forum Members
Posts: 374,
Visits: 1.2K
|
Hi Trent;
Thanks for th reply; I don't mind using ListView but listview raises another important question the way it connects to BO and populate itself.
When doing "populate datasource settings", it uses the BO class and the BO Class method to populate itself [u]Rather[/u] than the local instance of that BO on the form. I may have one BO class, but each form may use an instance of that BO and may have a different method to populate the BO. And since the listview doesn't see the BO instance, that can be a problem.
Is my understanding correct on this? And that was one of the reason I approached Data grid to bind to the local instance of BO via BBS.
..ßen
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
If you will recall, we went over this in class in several different manners. Just use the CopyDataFrom method to use the data within the local instance versus a Fill method. SF comes with an advanced ListView sample that shows how to do this. Using this approach you only populate the BO on your form, use the CopyDataFrom method within the PopulationDataSourceSettings, and you will get the behavior you are looking for. This is what we do most of the time as well.
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Ben (hayat)
If I understand your question, you have a maintenancetoolstrip, a listview, and some controls bound to a BO on a form. You want to navigate the BO that the controls are bound to using both the listview and the toolstrip. Likewise, when the toolstrip does the navigation, you want to change the selected item in the listview. There are several issues to deal with: loading the listview with the same data as the BO, synching the listview to the current row, updating the ListView when data in BO changes, and the one Trent provide a code sample for, synching the BO with the selected item in listview.
Loading ListView w/data from BO
The trick is to setup the listview to populate using the CopyDataFrom() method. Then handle the ListPopulating event of the list and set the two parameters of the CopyFromData method to the BO that the controls are bound to and the BusinessCloneDataType to ClearAndFillFromCompleteTable. This keeps the list and the bo the other controls are bound to in synch.
Synching ListView to CurrentRow
Just handle the BO's Navigated event and select the appropriate item in the list view. I pretty sure the only way is to walk the items in the list view, checking the Tag to equal the pk of the current row. Maybe Trent/Ben has another/better method.
Updating the ListView when the Data in the BO changes
You will also need to handle the appropriate events when the adding/removing/editing items in the BO and update the list (Requery it) and likely reselect the correct item. There may be a better way to do this. If the lists are small this way is fine.
Reusable code
Consider putting this code it into a component. The component can be dropped onto a form, then set its BO, its ListView and your done. The BO has a property to get the name of the primary key field. You can react to the BO and listview events in the component. Very handy.
Of course if this isn't what you are doing....never mind
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Trent posted faster than I did!
|
|
|
Ben Hayat
|
|
Group: Forum Members
Posts: 374,
Visits: 1.2K
|
Trent L. Taylor (06/12/2007) If you will recall, we went over this in class in several different manners. Just use the CopyDataFrom method to use the data within the local instance versus a Fill method. SF comes with an advanced ListView sample that shows how to do this. Using this approach you only populate the BO on your form, use the CopyDataFrom method within the PopulationDataSourceSettings, and you will get the behavior you are looking for. This is what we do most of the time as well.Hi Trent; Yes I do recall from the class but couldn't find anything that shows both listview and toolstrip working both direction. I even looked at chapter 18 to get a better feel for it, but if you look at chapter 18, you see the listview does not respond to toolstip and vice versa. I think Greg hit it right on the nail. A simple toolstip, listview and a few textboxes connected to BO a) if user navigate on toolstrip, the list view moves too. b) if user moves the listview, then the toolstrip gets moved to. Now here is the strange part. There is a sample called "Binding Business Source" which works with grid. I don't see any code that creates the sync between the grid and toolstrip. However, when I duplicated that on my form, the grid and toolstrip don't sync up. This has puzzled me. In one post Ben Chase had mentioned that BBS will do this behavior and that was my original point with grid. Your input is much appreciated!
..ßen
|
|
|
Ben Hayat
|
|
Group: Forum Members
Posts: 374,
Visits: 1.2K
|
Greg, thanks for you input; Of course if this isn't what you are doing....never mind This is exactly what I wanted to describe. A two way communication between listview/grid and toolstrip.
..ßen
|
|
|
Ben Hayat
|
|
Group: Forum Members
Posts: 374,
Visits: 1.2K
|
Greg; Synching ListView to CurrentRow
Just handle the BO's Navigated event and select the appropriate item in the list view. I pretty sure the only way is to walk the items in the list view, checking the Tag to equal the pk of the current row. Maybe Trent/Ben has another/better method. This is the tricky one! Are you saying that we need to iterate thru all the items of the list view to match the current row in BO table?
..ßen
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
yep. It most likely won't be all the rows, just until it finds the correct one. There may be a better way. This works if the list is small. Another possibility would be to keep a dictionary (created when you load the list initially) that tracks the list index to the PK. The PK would be the key, the index would be the value.
|
|
|