I have a WinForm that is a Base class. It has many controls on it and a lot
of generic code behind.
When I inherit the form I override 5 methods and now each child form has the
same look and feel and functionality. This part all works fine.
(I learned this morning that if you override a method that also has an Event
Handler then you should NOT include the event handler a 2nd time. I had a
devil of a time figuring out why a block of code was running twice!)
My question concerns one of my child methods.
It is very generic except for one thing - each child form declares a Private
variable named "list" which is a strongly typed collection of business
objects. This variable is used in the child procedure.
Is there any way to "move" this generic procedure to the Base class and yet
still know which strongly typed collection to use? When I try to copy the
code to the Base class VS underlines the "list" variable - which I would
expect since the Base form does not see the variable declared in the child.
Thanks for clarifying this for me.
--
Joe Fallon 7 1258
Joe,
I would recommend a Template Method Pattern.
The generic routine would be in the base class, when ever it needed the
"list" it would use an overridable List Property, that each derived class
would override to return the strongly typed list. Of course this means that
each strongly typed collection needs to have a common interface or base
class...
Public Class Base
Protected Overridable Readonly Property List As ICollection
Public Sub Generic()
For each item as object in List
' do something interesting with the item.
Next
End Sub
End Class
Public Class Derived : Inherits Base
Private m_list As StronglyTypedCo llection
Protected Overrides Readonly Property List As ICollection
Get
Return m_list
End Get
End Sub
End Class
You could make List public if it makes sense to expose the collection
publicly from Base, normally I use the Template Method Pattern as an
implementation detail, so its Protected. Instead of a overridable property,
you could define it as a overridable Sub or Function.
Hope this helps
Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:u7******** ******@TK2MSFTN GP12.phx.gbl... I have a WinForm that is a Base class. It has many controls on it and a
lot of generic code behind. When I inherit the form I override 5 methods and now each child form has
the same look and feel and functionality. This part all works fine.
(I learned this morning that if you override a method that also has an
Event Handler then you should NOT include the event handler a 2nd time. I had a devil of a time figuring out why a block of code was running twice!)
My question concerns one of my child methods. It is very generic except for one thing - each child form declares a
Private variable named "list" which is a strongly typed collection of business objects. This variable is used in the child procedure.
Is there any way to "move" this generic procedure to the Base class and
yet still know which strongly typed collection to use? When I try to copy the code to the Base class VS underlines the "list" variable - which I would expect since the Base form does not see the variable declared in the
child. Thanks for clarifying this for me.
-- Joe Fallon
Jay,
Thanks for responding. I am having trouble getting it working so here are
some more details:
Ican get it to work if I specify the type of collection but that defeats the
purpose!
The Base form has this:
AcctROC is a ReadOnlyCollect ion of CSLA business objects.
All ROCs inherit from ReadOnlyCollect ionBase
So I can have a CostCenterROC or a VendorROC, etc.
Protected Overridable ReadOnly Property List() As AcctROC
Get
'override this
End Get
End Property
Protected Overridable Sub
Protected Overridable Sub DoSomething
'use the sort method specific to each ROC. (This is NOT a method in
ReadOnlyCollect ionBase.)
List.Sort
End Sub
In the Acct child form:
Private mlist As AcctROC
Protected Overrides ReadOnly Property List() As AcctROC
Get
Return mlist
End Get
End Property
The problem is I have declared the type of collection too specifically.
But if I use ReadOnlyCollect ionBase or ICollection I can't get back the
correct type of object (AcctROC) in order to use its methods.
FYI - I am just trying to learn this pattern. I can always just go back to
using the method in each child class.
Thanks for helping!
--
Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:eW******** ******@tk2msftn gp13.phx.gbl... Joe, I would recommend a Template Method Pattern.
The generic routine would be in the base class, when ever it needed the "list" it would use an overridable List Property, that each derived class would override to return the strongly typed list. Of course this means
that each strongly typed collection needs to have a common interface or base class...
Public Class Base
Protected Overridable Readonly Property List As ICollection
Public Sub Generic() For each item as object in List ' do something interesting with the item. Next End Sub
End Class
Public Class Derived : Inherits Base
Private m_list As StronglyTypedCo llection
Protected Overrides Readonly Property List As ICollection Get Return m_list End Get End Sub
End Class
You could make List public if it makes sense to expose the collection publicly from Base, normally I use the Template Method Pattern as an implementation detail, so its Protected. Instead of a overridable
property, you could define it as a overridable Sub or Function.
Hope this helps Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message news:u7******** ******@TK2MSFTN GP12.phx.gbl... I have a WinForm that is a Base class. It has many controls on it and a lot of generic code behind. When I inherit the form I override 5 methods and now each child form has the same look and feel and functionality. This part all works fine.
(I learned this morning that if you override a method that also has an Event Handler then you should NOT include the event handler a 2nd time. I had
a devil of a time figuring out why a block of code was running twice!)
My question concerns one of my child methods. It is very generic except for one thing - each child form declares a Private variable named "list" which is a strongly typed collection of business objects. This variable is used in the child procedure.
Is there any way to "move" this generic procedure to the Base class and yet still know which strongly typed collection to use? When I try to copy
the code to the Base class VS underlines the "list" variable - which I would expect since the Base form does not see the variable declared in the child. Thanks for clarifying this for me.
-- Joe Fallon
Joe, The problem is I have declared the type of collection too specifically. But if I use ReadOnlyCollect ionBase or ICollection I can't get back the correct type of object (AcctROC) in order to use its methods.
Remember in the base class you need to treat your collection generically,
you should not need to get to specific AcctROC methods or even care that you
specifically have a AcctROC object.
Where specifically are the you attempting to use methods of a AcctROC
object? in the AcctForm or in the base form?
If I'm reading you correctly you have
AcctForm which has a AcctROC
CostCenterForm which has a CostCenterROC
VendorForm which has a VendorROC
Just as each of your forms inherit from your Base Form which has generic
code, you may need to introduce a Base collection that is sandwiched between
AcctROC & ReadOnlyCollect ion that has generic methods. In other words, both
the Form & the Collection may need template methods to get this to work...
Can you post the "generic" routine you are dealing with, with an explanation
of how it is different in each specific form?
Hope this helps
Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Jay, Thanks for responding. I am having trouble getting it working so here are some more details: Ican get it to work if I specify the type of collection but that defeats
the purpose!
The Base form has this: AcctROC is a ReadOnlyCollect ion of CSLA business objects. All ROCs inherit from ReadOnlyCollect ionBase So I can have a CostCenterROC or a VendorROC, etc.
Protected Overridable ReadOnly Property List() As AcctROC Get
'override this
End Get
End Property
Protected Overridable Sub
Protected Overridable Sub DoSomething 'use the sort method specific to each ROC. (This is NOT a method in ReadOnlyCollect ionBase.) List.Sort End Sub
In the Acct child form: Private mlist As AcctROC
Protected Overrides ReadOnly Property List() As AcctROC
Get
Return mlist
End Get
End Property
The problem is I have declared the type of collection too specifically. But if I use ReadOnlyCollect ionBase or ICollection I can't get back the correct type of object (AcctROC) in order to use its methods.
FYI - I am just trying to learn this pattern. I can always just go back to using the method in each child class.
Thanks for helping! -- Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:eW******** ******@tk2msftn gp13.phx.gbl... Joe, I would recommend a Template Method Pattern.
The generic routine would be in the base class, when ever it needed the "list" it would use an overridable List Property, that each derived
class would override to return the strongly typed list. Of course this means that each strongly typed collection needs to have a common interface or base class...
Public Class Base
Protected Overridable Readonly Property List As ICollection
Public Sub Generic() For each item as object in List ' do something interesting with the item. Next End Sub
End Class
Public Class Derived : Inherits Base
Private m_list As StronglyTypedCo llection
Protected Overrides Readonly Property List As ICollection Get Return m_list End Get End Sub
End Class
You could make List public if it makes sense to expose the collection publicly from Base, normally I use the Template Method Pattern as an implementation detail, so its Protected. Instead of a overridable property, you could define it as a overridable Sub or Function.
Hope this helps Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message news:u7******** ******@TK2MSFTN GP12.phx.gbl... I have a WinForm that is a Base class. It has many controls on it and
a lot of generic code behind. When I inherit the form I override 5 methods and now each child form
has the same look and feel and functionality. This part all works fine.
(I learned this morning that if you override a method that also has an Event Handler then you should NOT include the event handler a 2nd time. I
had a devil of a time figuring out why a block of code was running twice!)
My question concerns one of my child methods. It is very generic except for one thing - each child form declares a Private variable named "list" which is a strongly typed collection of business objects. This variable is used in the child procedure.
Is there any way to "move" this generic procedure to the Base class
and yet still know which strongly typed collection to use? When I try to copy
the code to the Base class VS underlines the "list" variable - which I
would expect since the Base form does not see the variable declared in the
child. Thanks for clarifying this for me.
-- Joe Fallon
Jay,
"Remember in the base class you need to treat your collection generically,
you should not need to get to specific AcctROC methods or even care that you
specifically have a AcctROC object."
I think this is the key. I did post the common method for each ROC:
list.Sort
Because I DO need to have a specific type of ROC in the base class I am
violating the quote above.
This tells me that my first idea was the correct one and that each child
class needs to implement its own method because of the need for strong
typing.
I think I have learned something from this discussion and have clarified
some ideas.
I really didn't think there was a way to do what I as trying to do, but I
wanted to confirm it.
Thanks.
FYI - here is the full routine inside each child form but note that
list.Sort is a specific instance of a ROC like AcctROC when in Acct form and
VendorROC when in vendor form.
(Also note that I used one of YOUR old suggestions about how to add sort
icons to a list view!)
My original goal:
If it wasn't for the List variable I could have all this code in the Base
class instead of copying to each child form.
Protected Overridable Sub dvDisplay_Colum nClick(ByVal sender As Object,
ByVal e As System.Windows. Forms.ColumnCli ckEventArgs) Handles
dvDisplay.Colum nClick
Try
'remove sort icon from old column.
If SortColumn <> -1 Then
dvDisplay.Colum ns.Item(SortCol umn).Text =
dvDisplay.Colum ns.Item(SortCol umn).Text.TrimE nd(Chr(32), Chr(32), Chr
(32), ChrW(&H25B2), ChrW(&H25BC))
End If
If e.Column <> SortColumn Then
'do the sort
SortColumn = e.Column
List.Sort = CType(sender,
DataListView.Da taListView).Col umns(SortColumn ).Text
mSortDirection = "ASC"
'add sort icon to new column.
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25B2)
Else
If mSortDirection = "ASC" Then
mSortDirection = "DESC"
list.Sort = CType(sender,
DataListView.Da taListView).Col umns(SortColumn ).Text & " DESC"
'add down icon
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25BC)
Else
mSortDirection = "ASC"
list.Sort = CType(sender,
DataListView.Da taListView).Col umns(SortColumn ).Text
'add up icon
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25B2)
End If
End If
dvDisplay.DataS ource = list
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub
--
Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l... Joe, The problem is I have declared the type of collection too specifically. But if I use ReadOnlyCollect ionBase or ICollection I can't get back the correct type of object (AcctROC) in order to use its methods. Remember in the base class you need to treat your collection generically, you should not need to get to specific AcctROC methods or even care that
you specifically have a AcctROC object.
Where specifically are the you attempting to use methods of a AcctROC object? in the AcctForm or in the base form?
If I'm reading you correctly you have AcctForm which has a AcctROC CostCenterForm which has a CostCenterROC VendorForm which has a VendorROC
Just as each of your forms inherit from your Base Form which has generic code, you may need to introduce a Base collection that is sandwiched
between AcctROC & ReadOnlyCollect ion that has generic methods. In other words,
both the Form & the Collection may need template methods to get this to work...
Can you post the "generic" routine you are dealing with, with an
explanation of how it is different in each specific form?
Hope this helps Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Jay, Thanks for responding. I am having trouble getting it working so here
are some more details: Ican get it to work if I specify the type of collection but that defeats the purpose!
The Base form has this: AcctROC is a ReadOnlyCollect ion of CSLA business objects. All ROCs inherit from ReadOnlyCollect ionBase So I can have a CostCenterROC or a VendorROC, etc.
Protected Overridable ReadOnly Property List() As AcctROC Get
'override this
End Get
End Property
Protected Overridable Sub
Protected Overridable Sub DoSomething 'use the sort method specific to each ROC. (This is NOT a method in ReadOnlyCollect ionBase.) List.Sort End Sub
In the Acct child form: Private mlist As AcctROC
Protected Overrides ReadOnly Property List() As AcctROC
Get
Return mlist
End Get
End Property
The problem is I have declared the type of collection too specifically. But if I use ReadOnlyCollect ionBase or ICollection I can't get back the correct type of object (AcctROC) in order to use its methods.
FYI - I am just trying to learn this pattern. I can always just go back
to using the method in each child class.
Thanks for helping! -- Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in
message news:eW******** ******@tk2msftn gp13.phx.gbl... Joe, I would recommend a Template Method Pattern.
The generic routine would be in the base class, when ever it needed
the "list" it would use an overridable List Property, that each derived class would override to return the strongly typed list. Of course this means that each strongly typed collection needs to have a common interface or
base class...
Public Class Base
Protected Overridable Readonly Property List As ICollection
Public Sub Generic() For each item as object in List ' do something interesting with the item. Next End Sub
End Class
Public Class Derived : Inherits Base
Private m_list As StronglyTypedCo llection
Protected Overrides Readonly Property List As ICollection Get Return m_list End Get End Sub
End Class
You could make List public if it makes sense to expose the collection publicly from Base, normally I use the Template Method Pattern as an implementation detail, so its Protected. Instead of a overridable property, you could define it as a overridable Sub or Function.
Hope this helps Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message news:u7******** ******@TK2MSFTN GP12.phx.gbl... > I have a WinForm that is a Base class. It has many controls on it
and a lot > of generic code behind. > When I inherit the form I override 5 methods and now each child form has the > same look and feel and functionality. This part all works fine. > > (I learned this morning that if you override a method that also has
an Event > Handler then you should NOT include the event handler a 2nd time. I
had a > devil of a time figuring out why a block of code was running twice!) > > My question concerns one of my child methods. > It is very generic except for one thing - each child form declares a Private > variable named "list" which is a strongly typed collection of
business > objects. This variable is used in the child procedure. > > Is there any way to "move" this generic procedure to the Base class and yet > still know which strongly typed collection to use? When I try to
copy the > code to the Base class VS underlines the "list" variable - which I would > expect since the Base form does not see the variable declared in the child. > > Thanks for clarifying this for me. > > -- > Joe Fallon > > > >
Joe,
I haven't given up on this question, its been a busy week, and I haven't had
the time to look at it yet, I should have time this weekend...
Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:ew******** ******@TK2MSFTN GP11.phx.gbl... Jay, "Remember in the base class you need to treat your collection generically, you should not need to get to specific AcctROC methods or even care that
you specifically have a AcctROC object."
I think this is the key. I did post the common method for each ROC: list.Sort
Because I DO need to have a specific type of ROC in the base class I am violating the quote above. This tells me that my first idea was the correct one and that each child class needs to implement its own method because of the need for strong typing.
I think I have learned something from this discussion and have clarified some ideas. I really didn't think there was a way to do what I as trying to do, but I wanted to confirm it.
Thanks.
FYI - here is the full routine inside each child form but note that list.Sort is a specific instance of a ROC like AcctROC when in Acct form
and VendorROC when in vendor form. (Also note that I used one of YOUR old suggestions about how to add sort icons to a list view!)
My original goal: If it wasn't for the List variable I could have all this code in the Base class instead of copying to each child form.
Protected Overridable Sub dvDisplay_Colum nClick(ByVal sender As Object, ByVal e As System.Windows. Forms.ColumnCli ckEventArgs) Handles dvDisplay.Colum nClick Try
'remove sort icon from old column.
If SortColumn <> -1 Then
dvDisplay.Colum ns.Item(SortCol umn).Text = dvDisplay.Colum ns.Item(SortCol umn).Text.TrimE nd(Chr(32), Chr(32), Chr (32), ChrW(&H25B2), ChrW(&H25BC))
End If
If e.Column <> SortColumn Then
'do the sort
SortColumn = e.Column
List.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text
mSortDirection = "ASC"
'add sort icon to new column.
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25B2)
Else
If mSortDirection = "ASC" Then
mSortDirection = "DESC"
list.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text & " DESC"
'add down icon
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25BC)
Else
mSortDirection = "ASC"
list.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text
'add up icon
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25B2)
End If
End If
dvDisplay.DataS ource = list
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub
-- Joe Fallon "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:%2******** **********@TK2M SFTNGP10.phx.gb l... Joe, The problem is I have declared the type of collection too
specifically. But if I use ReadOnlyCollect ionBase or ICollection I can't get back
the correct type of object (AcctROC) in order to use its methods. Remember in the base class you need to treat your collection
generically, you should not need to get to specific AcctROC methods or even care that you specifically have a AcctROC object.
Where specifically are the you attempting to use methods of a AcctROC object? in the AcctForm or in the base form?
If I'm reading you correctly you have AcctForm which has a AcctROC CostCenterForm which has a CostCenterROC VendorForm which has a VendorROC
Just as each of your forms inherit from your Base Form which has generic code, you may need to introduce a Base collection that is sandwiched between AcctROC & ReadOnlyCollect ion that has generic methods. In other words, both the Form & the Collection may need template methods to get this to
work... Can you post the "generic" routine you are dealing with, with an explanation of how it is different in each specific form?
Hope this helps Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Jay, Thanks for responding. I am having trouble getting it working so here are some more details: Ican get it to work if I specify the type of collection but that
defeats the purpose!
The Base form has this: AcctROC is a ReadOnlyCollect ion of CSLA business objects. All ROCs inherit from ReadOnlyCollect ionBase So I can have a CostCenterROC or a VendorROC, etc.
Protected Overridable ReadOnly Property List() As AcctROC Get
'override this
End Get
End Property
Protected Overridable Sub
Protected Overridable Sub DoSomething 'use the sort method specific to each ROC. (This is NOT a method in ReadOnlyCollect ionBase.) List.Sort End Sub
In the Acct child form: Private mlist As AcctROC
Protected Overrides ReadOnly Property List() As AcctROC
Get
Return mlist
End Get
End Property
The problem is I have declared the type of collection too
specifically. But if I use ReadOnlyCollect ionBase or ICollection I can't get back
the correct type of object (AcctROC) in order to use its methods.
FYI - I am just trying to learn this pattern. I can always just go
back to using the method in each child class.
Thanks for helping! -- Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:eW******** ******@tk2msftn gp13.phx.gbl... > Joe, > I would recommend a Template Method Pattern. > > The generic routine would be in the base class, when ever it needed the > "list" it would use an overridable List Property, that each derived class > would override to return the strongly typed list. Of course this
means that > each strongly typed collection needs to have a common interface or base > class... > > Public Class Base > > Protected Overridable Readonly Property List As ICollection > > Public Sub Generic() > For each item as object in List > ' do something interesting with the item. > Next > End Sub > > End Class > > Public Class Derived : Inherits Base > > Private m_list As StronglyTypedCo llection > > Protected Overrides Readonly Property List As ICollection > Get > Return m_list > End Get > End Sub > > End Class > > You could make List public if it makes sense to expose the
collection > publicly from Base, normally I use the Template Method Pattern as an > implementation detail, so its Protected. Instead of a overridable property, > you could define it as a overridable Sub or Function. > > Hope this helps > Jay > > > "Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message > news:u7******** ******@TK2MSFTN GP12.phx.gbl... > > I have a WinForm that is a Base class. It has many controls on it and a > lot > > of generic code behind. > > When I inherit the form I override 5 methods and now each child
form has > the > > same look and feel and functionality. This part all works fine. > > > > (I learned this morning that if you override a method that also
has an > Event > > Handler then you should NOT include the event handler a 2nd time.
I had a > > devil of a time figuring out why a block of code was running
twice!) > > > > My question concerns one of my child methods. > > It is very generic except for one thing - each child form declares
a > Private > > variable named "list" which is a strongly typed collection of business > > objects. This variable is used in the child procedure. > > > > Is there any way to "move" this generic procedure to the Base
class and > yet > > still know which strongly typed collection to use? When I try to copy the > > code to the Base class VS underlines the "list" variable - which I would > > expect since the Base form does not see the variable declared in
the > child. > > > > Thanks for clarifying this for me. > > > > -- > > Joe Fallon > > > > > > > > > >
Jay,
Thanks.
I thought you might have concluded I have put this to bed.
(I sort of did - but I would be interested in learning if there really is
some neat trick that could resolve this.)
--
Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl... Joe, I haven't given up on this question, its been a busy week, and I haven't
had the time to look at it yet, I should have time this weekend...
Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message news:ew******** ******@TK2MSFTN GP11.phx.gbl... Jay, "Remember in the base class you need to treat your collection
generically, you should not need to get to specific AcctROC methods or even care that you specifically have a AcctROC object."
I think this is the key. I did post the common method for each ROC: list.Sort
Because I DO need to have a specific type of ROC in the base class I am violating the quote above. This tells me that my first idea was the correct one and that each child class needs to implement its own method because of the need for strong typing.
I think I have learned something from this discussion and have clarified some ideas. I really didn't think there was a way to do what I as trying to do, but
I wanted to confirm it.
Thanks.
FYI - here is the full routine inside each child form but note that list.Sort is a specific instance of a ROC like AcctROC when in Acct form and VendorROC when in vendor form. (Also note that I used one of YOUR old suggestions about how to add sort icons to a list view!)
My original goal: If it wasn't for the List variable I could have all this code in the
Base class instead of copying to each child form.
Protected Overridable Sub dvDisplay_Colum nClick(ByVal sender As Object, ByVal e As System.Windows. Forms.ColumnCli ckEventArgs) Handles dvDisplay.Colum nClick Try
'remove sort icon from old column.
If SortColumn <> -1 Then
dvDisplay.Colum ns.Item(SortCol umn).Text = dvDisplay.Colum ns.Item(SortCol umn).Text.TrimE nd(Chr(32), Chr(32), Chr (32), ChrW(&H25B2), ChrW(&H25BC))
End If
If e.Column <> SortColumn Then
'do the sort
SortColumn = e.Column
List.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text
mSortDirection = "ASC"
'add sort icon to new column.
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25B2)
Else
If mSortDirection = "ASC" Then
mSortDirection = "DESC"
list.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text & " DESC"
'add down icon
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25BC)
Else
mSortDirection = "ASC"
list.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text
'add up icon
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25B2)
End If
End If
dvDisplay.DataS ource = list
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub
-- Joe Fallon "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in
message news:%2******** **********@TK2M SFTNGP10.phx.gb l... Joe, > The problem is I have declared the type of collection too specifically. > But if I use ReadOnlyCollect ionBase or ICollection I can't get back the > correct type of object (AcctROC) in order to use its methods.
Remember in the base class you need to treat your collection generically, you should not need to get to specific AcctROC methods or even care
that you specifically have a AcctROC object.
Where specifically are the you attempting to use methods of a AcctROC object? in the AcctForm or in the base form?
If I'm reading you correctly you have AcctForm which has a AcctROC CostCenterForm which has a CostCenterROC VendorForm which has a VendorROC
Just as each of your forms inherit from your Base Form which has
generic code, you may need to introduce a Base collection that is sandwiched between AcctROC & ReadOnlyCollect ion that has generic methods. In other words, both the Form & the Collection may need template methods to get this to work... Can you post the "generic" routine you are dealing with, with an explanation of how it is different in each specific form?
Hope this helps Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. > Jay, > Thanks for responding. I am having trouble getting it working so
here are > some more details: > Ican get it to work if I specify the type of collection but that defeats the > purpose! > > The Base form has this: > AcctROC is a ReadOnlyCollect ion of CSLA business objects. > All ROCs inherit from ReadOnlyCollect ionBase > So I can have a CostCenterROC or a VendorROC, etc. > > Protected Overridable ReadOnly Property List() As AcctROC > Get > > 'override this > > End Get > > End Property > > Protected Overridable Sub > > Protected Overridable Sub DoSomething > 'use the sort method specific to each ROC. (This is NOT a method
in > ReadOnlyCollect ionBase.) > List.Sort > End Sub > > In the Acct child form: > Private mlist As AcctROC > > Protected Overrides ReadOnly Property List() As AcctROC > > Get > > Return mlist > > End Get > > End Property > > The problem is I have declared the type of collection too specifically. > But if I use ReadOnlyCollect ionBase or ICollection I can't get back the > correct type of object (AcctROC) in order to use its methods. > > FYI - I am just trying to learn this pattern. I can always just go back to > using the method in each child class. > > Thanks for helping! > -- > Joe Fallon > > > "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message > news:eW******** ******@tk2msftn gp13.phx.gbl... > > Joe, > > I would recommend a Template Method Pattern. > > > > The generic routine would be in the base class, when ever it
needed the > > "list" it would use an overridable List Property, that each
derived class > > would override to return the strongly typed list. Of course this means > that > > each strongly typed collection needs to have a common interface or base > > class... > > > > Public Class Base > > > > Protected Overridable Readonly Property List As
ICollection > > > > Public Sub Generic() > > For each item as object in List > > ' do something interesting with the item. > > Next > > End Sub > > > > End Class > > > > Public Class Derived : Inherits Base > > > > Private m_list As StronglyTypedCo llection > > > > Protected Overrides Readonly Property List As ICollection > > Get > > Return m_list > > End Get > > End Sub > > > > End Class > > > > You could make List public if it makes sense to expose the collection > > publicly from Base, normally I use the Template Method Pattern as
an > > implementation detail, so its Protected. Instead of a overridable > property, > > you could define it as a overridable Sub or Function. > > > > Hope this helps > > Jay > > > > > > "Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message > > news:u7******** ******@TK2MSFTN GP12.phx.gbl... > > > I have a WinForm that is a Base class. It has many controls on
it and a > > lot > > > of generic code behind. > > > When I inherit the form I override 5 methods and now each child form has > > the > > > same look and feel and functionality. This part all works fine. > > > > > > (I learned this morning that if you override a method that also has an > > Event > > > Handler then you should NOT include the event handler a 2nd
time. I had > a > > > devil of a time figuring out why a block of code was running twice!) > > > > > > My question concerns one of my child methods. > > > It is very generic except for one thing - each child form
declares a > > Private > > > variable named "list" which is a strongly typed collection of business > > > objects. This variable is used in the child procedure. > > > > > > Is there any way to "move" this generic procedure to the Base class and > > yet > > > still know which strongly typed collection to use? When I try
to copy > the > > > code to the Base class VS underlines the "list" variable - which
I would > > > expect since the Base form does not see the variable declared in the > > child. > > > > > > Thanks for clarifying this for me. > > > > > > -- > > > Joe Fallon > > > > > > > > > > > > > > > > > >
Joe and Jay,
Do you know of a sample in the SDK or on the net demonstrating the
techiniques you are talking about here?
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message
news:ew******** ******@TK2MSFTN GP11.phx.gbl... Jay, "Remember in the base class you need to treat your collection generically, you should not need to get to specific AcctROC methods or even care that
you specifically have a AcctROC object."
I think this is the key. I did post the common method for each ROC: list.Sort
Because I DO need to have a specific type of ROC in the base class I am violating the quote above. This tells me that my first idea was the correct one and that each child class needs to implement its own method because of the need for strong typing.
I think I have learned something from this discussion and have clarified some ideas. I really didn't think there was a way to do what I as trying to do, but I wanted to confirm it.
Thanks.
FYI - here is the full routine inside each child form but note that list.Sort is a specific instance of a ROC like AcctROC when in Acct form
and VendorROC when in vendor form. (Also note that I used one of YOUR old suggestions about how to add sort icons to a list view!)
My original goal: If it wasn't for the List variable I could have all this code in the Base class instead of copying to each child form.
Protected Overridable Sub dvDisplay_Colum nClick(ByVal sender As Object, ByVal e As System.Windows. Forms.ColumnCli ckEventArgs) Handles dvDisplay.Colum nClick Try
'remove sort icon from old column.
If SortColumn <> -1 Then
dvDisplay.Colum ns.Item(SortCol umn).Text = dvDisplay.Colum ns.Item(SortCol umn).Text.TrimE nd(Chr(32), Chr(32), Chr (32), ChrW(&H25B2), ChrW(&H25BC))
End If
If e.Column <> SortColumn Then
'do the sort
SortColumn = e.Column
List.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text
mSortDirection = "ASC"
'add sort icon to new column.
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25B2)
Else
If mSortDirection = "ASC" Then
mSortDirection = "DESC"
list.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text & " DESC"
'add down icon
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25BC)
Else
mSortDirection = "ASC"
list.Sort = CType(sender, DataListView.Da taListView).Col umns(SortColumn ).Text
'add up icon
dvDisplay.Colum ns.Item(SortCol umn).Text &= " " & ChrW(&H25B2)
End If
End If
dvDisplay.DataS ource = list
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub
-- Joe Fallon "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:%2******** **********@TK2M SFTNGP10.phx.gb l... Joe, The problem is I have declared the type of collection too
specifically. But if I use ReadOnlyCollect ionBase or ICollection I can't get back
the correct type of object (AcctROC) in order to use its methods. Remember in the base class you need to treat your collection
generically, you should not need to get to specific AcctROC methods or even care that you specifically have a AcctROC object.
Where specifically are the you attempting to use methods of a AcctROC object? in the AcctForm or in the base form?
If I'm reading you correctly you have AcctForm which has a AcctROC CostCenterForm which has a CostCenterROC VendorForm which has a VendorROC
Just as each of your forms inherit from your Base Form which has generic code, you may need to introduce a Base collection that is sandwiched between AcctROC & ReadOnlyCollect ion that has generic methods. In other words, both the Form & the Collection may need template methods to get this to
work... Can you post the "generic" routine you are dealing with, with an explanation of how it is different in each specific form?
Hope this helps Jay
"Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Jay, Thanks for responding. I am having trouble getting it working so here are some more details: Ican get it to work if I specify the type of collection but that
defeats the purpose!
The Base form has this: AcctROC is a ReadOnlyCollect ion of CSLA business objects. All ROCs inherit from ReadOnlyCollect ionBase So I can have a CostCenterROC or a VendorROC, etc.
Protected Overridable ReadOnly Property List() As AcctROC Get
'override this
End Get
End Property
Protected Overridable Sub
Protected Overridable Sub DoSomething 'use the sort method specific to each ROC. (This is NOT a method in ReadOnlyCollect ionBase.) List.Sort End Sub
In the Acct child form: Private mlist As AcctROC
Protected Overrides ReadOnly Property List() As AcctROC
Get
Return mlist
End Get
End Property
The problem is I have declared the type of collection too
specifically. But if I use ReadOnlyCollect ionBase or ICollection I can't get back
the correct type of object (AcctROC) in order to use its methods.
FYI - I am just trying to learn this pattern. I can always just go
back to using the method in each child class.
Thanks for helping! -- Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:eW******** ******@tk2msftn gp13.phx.gbl... > Joe, > I would recommend a Template Method Pattern. > > The generic routine would be in the base class, when ever it needed the > "list" it would use an overridable List Property, that each derived class > would override to return the strongly typed list. Of course this
means that > each strongly typed collection needs to have a common interface or base > class... > > Public Class Base > > Protected Overridable Readonly Property List As ICollection > > Public Sub Generic() > For each item as object in List > ' do something interesting with the item. > Next > End Sub > > End Class > > Public Class Derived : Inherits Base > > Private m_list As StronglyTypedCo llection > > Protected Overrides Readonly Property List As ICollection > Get > Return m_list > End Get > End Sub > > End Class > > You could make List public if it makes sense to expose the
collection > publicly from Base, normally I use the Template Method Pattern as an > implementation detail, so its Protected. Instead of a overridable property, > you could define it as a overridable Sub or Function. > > Hope this helps > Jay > > > "Joe Fallon" <jf******@nospa mtwcny.rr.com> wrote in message > news:u7******** ******@TK2MSFTN GP12.phx.gbl... > > I have a WinForm that is a Base class. It has many controls on it and a > lot > > of generic code behind. > > When I inherit the form I override 5 methods and now each child
form has > the > > same look and feel and functionality. This part all works fine. > > > > (I learned this morning that if you override a method that also
has an > Event > > Handler then you should NOT include the event handler a 2nd time.
I had a > > devil of a time figuring out why a block of code was running
twice!) > > > > My question concerns one of my child methods. > > It is very generic except for one thing - each child form declares
a > Private > > variable named "list" which is a strongly typed collection of business > > objects. This variable is used in the child procedure. > > > > Is there any way to "move" this generic procedure to the Base
class and > yet > > still know which strongly typed collection to use? When I try to copy the > > code to the Base class VS underlines the "list" variable - which I would > > expect since the Base form does not see the variable declared in
the > child. > > > > Thanks for clarifying this for me. > > > > -- > > Joe Fallon > > > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: KK |
last post by:
Windows Forms Inheritance, Incomplete?
I was playing around with Windows Forms
and found out this Forms Inheritance feature.
The moment I saw that, I felt this can be
used effectively if the application
contains couople of forms which have
a consistant look and also shares
SOME similar functionality between the forms.
|
by: KK |
last post by:
** Posting it here cause after couple of days no body responded.**
I was playing around with Windows Forms
and found out this Forms Inheritance feature.
The moment I saw that, I felt this can be
used effectively if the application
contains couople of forms which have
a consistant look and also shares
SOME similar functionality between the forms.
|
by: Dave Theese |
last post by:
Hello all,
The example below demonstrates proper conformance to the C++ standard.
However, I'm having a hard time getting my brain around which language rules
make this proper...
The error below *should* happen, but my question to the community is *why*
does it happen? Any answer will be appreciated, but a section and paragraph
number from the C++ Standard would be especially appreciated.
|
by: __PPS__ |
last post by:
Hello everybody, today I had another quiz question
"if class X is privately derived from base class Y what is the scope of
the public, protected, private members of Y will be in class X"
By scope they meant public/protected/private access modifiers :)
Obviously all members of the base privately inherited class will be
private, and that was my answer. However, the teacher checked my
answers when I handed in, and the problem was that I had...
|
by: Matthew Louden |
last post by:
I want to know why C# doesnt support multiple inheritance? But why we can
inherit multiple interfaces instead? I know this is the rule, but I dont
understand why. Can anyone give me some concrete examples?
| |
by: Ben Blank |
last post by:
I'm writing a family of classes which all inherit most of their methods and
code (including constructors) from a single base class. When attempting to
instance one of the derived classes using parameters, I get CS1501 (no method
with X arguments). Here's a simplified example which mimics the
circumstances:
namespace InheritError {
// Random base class.
public class A {
protected int i;
|
by: VR |
last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some
WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages,
my MasterPage does not have a form tag itself so, cannot be called a WebForm
itself, the child pages will implement forms).
I created a Master.aspx page and removed all HTML from it, added some code
to the .aspx.vb file to add controls to my page. Then I created a Child.aspx
and changed the...
|
by: Noah Roberts |
last post by:
Is there anything that says that if you virtually inherit from one
class you have to virtually inherit from anything you inherit from?
|
by: RSH |
last post by:
I have a simple question regarding inheritance in a web form.
I have a DropDownList in an aspx form. It is called DropDownList1
I have a class that will be overriding the render event so I have a snippet
of this class:
Public Class CustomDDL
Inherits DropDownList
|
by: RSH |
last post by:
Hi,
I am working on some general OOP constructs and I was wondering if I could
get some guidance.
I have an instance where I have a Base Abstract Class, and 4 Derived
classes. I now need to make a list class that will store the objects. My
question is how do I go about creating the list class...I am assuming it
should be a standalone class that uses an arraylist to store the objects.
If I go that route how do I instantiate the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |