StrataFrame Forum

Help understanding BrowseDialog inheritance

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

By Edhy Rijo - 8/3/2009

I have a base BrowseDialog I want to use in other similar forms that share the same search table but with different fields. Ok I created my base class BDBase and setup all possible search fields in SearchFields property and also setup the BrowseResultsLayout.



So far so good. Now I create another class and inherited from BDBase and in the designer, I removed the fields I don't need from SearchFields and BrowseResultsLayout. When I add an instance of this class in my form, those 2 properties are reset to the default values in BDBase class.



What am I doing wrong? Also is this the correct approach to reuse the BrowseDialog?
By Edhy Rijo - 8/4/2009

Hi Trent,



Just in case this message was overlook, please see if you can help me out here.



Thanks!
By Trent L. Taylor - 8/4/2009

First, let me understand. You are wanting to create a base browse dialog that all of your other browse dialogs, correct? Or, are you just wanting to class your existing BD so that you can reuse them over and over again.



In teh case of the first, which I think you are getting at, there are times when you will have to override the property (or you are setting a property) in the Load or constructor of the class. If this is a property and you are overwriting base logic, then you may need to create an internal private, override the property, and implement your logic.



What properties specifically are you getting at here?
By Edhy Rijo - 8/4/2009

Well basically I have several forms which use the same Parent Table, I want to have a single BrowseDialog class to be reused by each form, but the key here is that each form will use different SearchFields from the same Parent Table.



So in this case for each form some SearchFields will always be reused and some will be unique, as well as the BrowseResultsLayout which will have some common fields and some unique.



Due to the similarities, I though of using a single BrowseDialog base class (like in the StrataFlix sample) but when I drop an instance of my BD class in each form and manually adjust the SearchFields and BrowseResultsLayout properties, when I run the form those properties revert back to their original value in the base class.


By Trent L. Taylor - 8/4/2009

Yeah, in this case you may have to override these properties and then re-expose the underlying property. In fact, you may want to create your own search fields and browse results property on the base class and then after the load, you will set the SF properties. This will allow the base class to initialize then in essense you will be clearing out and resetting the base properties.
By Edhy Rijo - 8/4/2009

Trent L. Taylor (08/04/2009)
In fact, you may want to create your own search fields and browse results property on the base class and then after the load, you will set the SF properties.




In the base BD class I have all fields I will use in all forms, then in my form in the BD.InitializeSearchFields() I have some code to set SearchFields("PONumber").Visible = False, and in fact this will now show that field, but will leave the dialog with an empty space in the groupbox of the search fields, so the group box will not resize automatically. Is there a way to overcome this, other than have a BD for each form?


By Trent L. Taylor - 8/6/2009

Is there a way to overcome this, other than have a BD for each form?




Yes. I never have a single BD per form and create classes for all my BD. Maybe a sample showing the issue you are fighting would help so I can see what you are doing.
By Edhy Rijo - 8/6/2009

Hi Trent,



I am setting up a simple sample that will show this scenario, please stay tune!!! Tongue
By Edhy Rijo - 8/6/2009

Hi Trent,



Attached please find the requested Sample. It is a very easy sample and follows the StrataFlix sample for the BDs.





In the BrowseDialogClassSample.UI project I created a BaseBrowseDialog.vb class and setup the SearchFields and BrowseResultsLayout properties to use all possible fields I will use in the next 2 inherited classes:



- BrowseDialogForNamesOnly.vb: This class should show the following fields:

- SearchFields: cust_Company, cust_FirstName, cust_LastName



- BrowseResultsLayout: cust_Company, cust_FirstName, cust_LastName



- BrowseDialogForPhonesOnly.vb

- SearchFields: cust_PhoneDay, cust_PhoneNight



- BrowseResultsLayout: cust_FirstName, cust_LastName, cust_PhoneDay, cust_PhoneNight



The whole idea is to have a base class BD and then use it in several form with different searchfields and BrowseResultLayout columns.



I hope you can make the changes to this sample and re-post it so we can see how this should be accomplish.



Thanks!
By Trent L. Taylor - 8/10/2009

Ok, you can take several routes on this, but here is my suggestion and the easiest route. Since you are in control of the dialogs and know what you need, you can override the OnInitializeSearchFields method, for example, and dynamically build your search list. So using the sample that you gave, if I only wanted the company field as a search field in the BrowseDialogFormnamesOnly class, then I would do this:



Protected Overrides Sub OnInitializeSearchFields(ByVal e As System.EventArgs)

Me.SearchFields.Clear()



'-- Build the desired search fields list

Dim item As New MicroFour.StrataFrame.UI.Windows.Forms.SearchFieldItem()

item.FieldName = "cust_Company"

item.AllowAdvanced = True

item.DefaultSearchStyle = MicroFour.StrataFrame.UI.BrowseDialogAllSearchTypes.BeginsWith

item.FieldLabelText = "Company:"

item.FieldName = "cust_Company"

item.FieldType = Data.DbType.AnsiString

item.InitiallyEnabled = True

item.Key = "cust_Company"

item.Visible = True



Me.SearchFields.Add(item)



MyBase.OnInitializeSearchFields(e)

End Sub




Obviously you can clean this up and add a method to generate this list, etc. But this is a quick and dirty way to get this working the way that you like. You can take a similar approach for the browse results layout.
By Edhy Rijo - 8/10/2009

Thanks a lot Trent, that is exactly the type of control I want to have for my BDs.



I have 2 more issues, if you don't mind Cool



1.- When controlling the SearchFields like this, the layout will not be properly fit, so an space will be left between the SearchFields and the ListView, is there a way to control that too? see attached image.



2.- As for the BrowseResultLayout, could you provide a quick sample code of how to remove one columns from the listview?
By Trent L. Taylor - 8/10/2009

Edhy,



Keep this one thing in mind and it should make things easier...these are just properties, classes, and collections. 100% of the control can be dynamically set and rebuilt to your liking. This is the same thing that is done via the type editors, but in your case, you would just be doing this manually.





1.- When controlling the SearchFields like this, the layout will not be properly fit, so an space will be left between the SearchFields and the ListView, is there a way to control that too? see attached image.




Yup...just set the FormLayout property to whatever you like in code:



Me.FormLayout.LeftSplitterDistance = 100




This is the property that you will set in the example that you gave. Even though it is called LeftSplitterDistance, it is used for the Top and Bottom as well.





2.- As for the BrowseResultLayout, could you provide a quick sample code of how to remove one columns from the listview?





Me.BrowseResultsLayout.BrowseColumns.Clear()



Me.BrowseResultsLayout.DisplayFieldNames.Clear()

Me.BrowseResultsLayout.DisplayFieldNames.Add("cust_Company")



Dim bc As New MicroFour.StrataFrame.UI.Windows.Forms.BrowseColumnItem()

bc.ColumnHeaderText = "Company"

bc.ColumnHeaderWidth = 200

bc.ColumnTextAlignment = Windows.Forms.HorizontalAlignment.Left

bc.FormatString = "{0}"



Me.BrowseResultsLayout.BrowseColumns.Add(bc)
By Edhy Rijo - 8/10/2009

Trent L. Taylor (08/10/2009)
Edhy, keep this one thing in mind and it should make things easier...these are just properties, classes, and collections. 100% of the control can be dynamically set and rebuilt to your liking. This is the same thing that is done via the type editors, but in your case, you would just be doing this manually.




Thanks again, Trent. Wow, this is just great to have such control over the BD and opens up a whole new ideas on how to build my applications, very cool things can be done with the BrowseDialog control. Thanks a lot for the sample code.
By Trent L. Taylor - 8/10/2009

No problem...Glad to help! Smile