StrataFrame Forum

How to synch a DataGridView in a SF Maintenance Form with a single BO?

http://forum.strataframe.net/Topic14917.aspx

By Edhy Rijo - 3/14/2008

Hi

I am working on a form below and I want to provide the user with a readonly datagridview so they can just click the selected record and then show that record at the bottom for maintenance. 

Right now, the datagridview control is not responding to the navigation events. I found this old post http://forum.strataframe.net/Topic9799-7-1.aspx?Highlight=datagridview, but I am not sure is this has been fixed?

Is the datagridview control suppose to respond to the navigation events automatically or do I have to change some properties to make it work?

Thanks!

By Trent L. Taylor - 3/14/2008

I wouldn't use a data grid view.  Use a ListView and handle the SelectedIndexChanged event and then navigate to that record.  Obviously you can use grids, but I would not recommend doing this throughout your applicaiton.  If you are going to have a read-only list that is presenting child records for an end-user to select, I recommend using the ListView everytime.  Less overhead, faster, and fewer quirks! Smile
By Edhy Rijo - 3/14/2008

Hi Trent,

I had implemented ListView in a previous test project, but I found I had to do many little steps in order to make it work, beside having to format all listview columns. 

I am testing now with the grid and it looks easier to handle, except that it is not working with the navigation events.  I have many forms to do and I am in the process of choosing which control to use based on which one will take less time to implement and easier for me to remember many little steps or a lot of copy and paste. Wink

Back to the situation, will the datagridview works or not with the navigation bar?

Or will this be easier with a 3rd party grid from DevExpress? (I have not tried it yet)

By Trent L. Taylor - 3/14/2008

To each his own...BigGrin  You can create a class to aid in some of the steps...we have had really good luck with this approach in our medical software...we went down the data grid view in the beginning too Smile

Look at the Business Binding Source sample that comes with the framework and it should get you going in the right direction.

Whether you use a 3rd party grid or the data grid view you should have the same behavior.

By Edhy Rijo - 3/14/2008

Ben Hayat (06/26/2007)
Robin J Giltner (06/26/2007)
Well IncludeinFormNavigate is set to PrimaryBusinessObject. In fact all of the Includes are set to PrimarybusinessObject save for the Save, which is set to AllBusinessObjects.

I started messing around some, and it seems like when I removed the MaintenanceFormToolStrip from its container, and just placed it on the form, it started working.

Thanks

Robin Giltner


Robin; this is something I had recently discovered and reported it [I'm not sure if it was recorded]. The problem I ran into, was using the SF Maintenance form and BBS. Somehow, the BBS does not work with toolstrip. However, if you create a new STD SF form, place a header and toolstrip on it manually, then you'll see everything works.

Hope this helps!

Trent,

I am sorry to insist on this one, but apparently the problem with the Maintenance Form reported by Ben Hayat on 6/26/2007 still exist.

I tried Ben's test with a standard form and the datagridview is working as expected.  I would really appreciated if you can check this out to see how to make all this work as expected.

By Greg McGuffey - 3/14/2008

Edhy,



I use the ListView for this all the time. In fact I sub-classed the ListView just for this and it is pretty easy to use now. A few of things I ended up doing:



- I fill the list view with a copy of the BO i'm working with. I.e. I use the CopyDataFrom() method.

- In my subclassed BO, I have a property to indicate the BO to synch with. The property is a BusinessLayer type, so any BO will work.

- I handle the several of the BOs events:

* AfterAddNew - update list and synch it to BO

* AfterDelete - Update list and synch it to BO

* AfterSave - Update list and synch it to BO (in case the data in list has changed).

* Navigating - check if bo needs to be saved before navigating to off record

* Navigated - synch list

* CurrentDataTableRefilled - update list and synch to BO

- I handle a couple of the ListView events:

* SelectedIndexChanged - navigate BO to associated item

* ListPopulating - set parameters needed for the CopyDataFrom method, which is possible because I have the BO property of the ListView.



Anyway, just some thoughts if you go down the ListView road.... BigGrin
By Edhy Rijo - 3/14/2008

Hi Greg,

Thanks for the info.  The problem here is that I am a real novice in VB.NET.  Today it took me a couple of hours to create my own code snippet using the help file and then I got a sample snippet and finally I got my very first snipet. 

About classes and sub-classes still I have not played with them, I can manage to work it out better with a startup sample and that is how I have been able to get through my learning curve.

I have used the ListView in my first test project with a couple of forms and end up copying/pasting a lot of stuff from one form to the other.  I will review it again with your recomendations and see how far I can go.

By Greg McGuffey - 3/14/2008

I totally understand. I was there not so long ago. It's very cool when it starts to click BigGrin.



If I get a chance, I'll post the control in a sample app next week...no promises, it's been busy.
By Trent L. Taylor - 3/14/2008

Edhy,

There is an issue that has not bee fixed as it related to bubbling up the events (this has been discussed) but this really isn't a show stopper in most cases.  Here is the deal, a grid, report, etc. expects to talk to an object model that implements the IBIndingList interface.  So this is what the business binding source does.  It allows you to wrap a BO and then creates a unique BO instance for each row that emits the proper row reference.  This is what a grid wants...so the issue is that the parent business object (the instance being wrapped) works fine, but the events for each internal BO do not bubble up to the parent...but this will only effect events such as the field changed event, etc.  The Navigated event of the instance being wrapped should be getting raised.

It is on the slate to make this bubble up change before the next update...but I will take a look at this next week and see how much time will be involved in making this change and see if I can plop something out here.  The reason this isn't high on our list is that this is generally not an issue in most circumstances....thus the priority on this enhancement is pretty low since there are so many other ways to address this.

By Trent L. Taylor - 3/14/2008

Oh, I just noticed what you were referring to on Ben Hayats post...the BBS was never intended to interact with the MaintenanceFormToolstrip in that manner.  I see why you are wanting to do that, but this has more to do with the grid rather than the navigated event.  Each grid is slightly different in the way that it determines the "active" row.  This is why most developers implement their own grid navigation logic here.  Also, if you are using a grid for a child data source, in most cases it is being presented to allow the end-user to select the child record, which DOES fire the navigated event in the BO.  It is working backwards that you are wanting.  I will look at this, but that is why it was not changed.  Ben Hayat kept demanding that we make a change, but this change entailed more than just an encapsulated change. 

I will look at this again and refresh my memory, and it is still in a list that we keep up with, but that is the issue.

By Edhy Rijo - 3/14/2008

Greg McGuffey (03/14/2008)
I totally understand. I was there not so long ago. It's very cool when it starts to click BigGrin.

If I get a chance, I'll post the control in a sample app next week...no promises, it's been busy.

Well, you want believe how happy I was to have the snippet working, since that will save me some time and it is way better than copy and paste.

Thanks for the offer.

By Edhy Rijo - 3/14/2008

Trent L. Taylor (03/14/2008)
Oh, I just noticed what you were referring to on Ben Hayats post...the BBS was never intended to interact with the MaintenanceFormToolstrip in that manner.  I see why you are wanting to do that, but this has more to do with the grid rather than the navigated event.  Each grid is slightly different in the way that it determines the "active" row.  This is why most developers implement their own grid navigation logic here.  Also, if you are using a grid for a child data source, in most cases it is being presented to allow the end-user to select the child record, which DOES fire the navigated event in the BO.  It is working backwards that you are wanting.  I will look at this, but that is why it was not changed.  Ben Hayat kept demanding that we make a change, but this change entailed more than just an encapsulated change. 

I will look at this again and refresh my memory, and it is still in a list that we keep up with, but that is the issue.

Trent, I am glad to see you understood my situation.  In this project I estimate having at least 8-12 simple Maintenance form in which I would like to use my form layout of showing the data in a grid or listview, and 3-5 main forms which will require a lot of coding (remember I am re-doing my VFP applications with SF).  That is why I am testing the grid and the listview to decide which one I will use for these forms, so this will be a kind of repeating thing in all my projects and I really hate to copy & paste all the time.

Greg McGuffey has a class for the listview that he may be able to post some sample next week, but that may not happen, so if it is easier for you to post some start code for me to give it a shot in creating a similar class for the listview, I am willing to take the risk Hehe and spend the time working with this class, just be ready for more questions Wow

By Trent L. Taylor - 3/14/2008

OK....I was right in that it isn't a bug.  When everyone kept saying that it was the maintenance form I ignored that statement because a MaintenanceForm is a Standard form with a gradient form header and a maintenance form toolstrip attached to it...however BigGrin ... there is something in the InitializeComponent that is causing this form to act a little from through this tempalte...I will dig that out and determine where the issue is.

I have attached a test program that does what you want.  If you navigate through the maintenance form toolstrip, the data grid view is updated.  If you select a record through the grid, it updates and fires the Navigated event.  It works as advertised...there must be something in the MaintenanceForm template that is causing the funny behavior.

Anyway, all you have to do is this to produce a maintenance form:

  1. Create a Standard Form
  2. Drop on a gradient form header
  3. Drop on a maintenance form toolstrip

That's it Smile

I would not have believed that in a million years if I didn't see it with my own eyes w00t.

This sample uses the StrataFrameSample database and has a maintenance form toolstrip on it and loads the top 100 records and show them in a grid view.

By Edhy Rijo - 3/16/2008

Hi Trent,

I tested your sample and it fact works, but it is not stable. At some point it will stop working, either if I add a GroupBox or a ThemedContainer, it will stop working and after a while for no reason.

I guess will have to use the ListView as suggested before in order to keep moving on.

By Trent L. Taylor - 3/17/2008

I tested your sample and it fact works, but it is not stable. At some point it will stop working, either if I add a GroupBox or a ThemedContainer, it will stop working and after a while for no reason.

Edhy, I have tested this over and over and it works fine.  I am not sure what issue you are running into here, but there is more than likely something else being placed in your code that is causing the issue.  I have also double-checked with some people that I KNOW are using this logic and they are not having issues.  You might dig a little deeper...I prefer the ListView method anyway, but if you want to keep with this, people use grids in this fashion everyday...so I think that there is probably something else going on here.

By Edhy Rijo - 3/17/2008

Trent L. Taylor (03/17/2008)
Edhy, I have tested this over and over and it works fine.  I am not sure what issue you are running into here, but there is more than likely something else being placed in your code that is causing the issue.  I have also double-checked with some people that I KNOW are using this logic and they are not having issues.  You might dig a little deeper...I prefer the ListView method anyway, but if you want to keep with this, people use grids in this fashion everyday...so I think that there is probably something else going on here.

Thanks Trent, I will keep looking at this since I like the fact of the grid being manage/synch with the MaintenanceFormToolStrip.

By Greg McGuffey - 3/17/2008

I've posted a sample with a sub-classed listview:



http://forum.strataframe.net/FindPost14966.aspx
By Edhy Rijo - 3/17/2008

Thanks Greg, I will check it out now.