|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
dataset inheritancecontrols (ChildUserControl(n)) inherit. Each ChildUserControl(n) has its own strongly typed dataset. I would like to include several (overridable) methods in UserControl(0) that act on the datasets (nothing exotic, only things that can be executed against an untyped dataset). Occasionally, I will want to override these methods and exploit the strong typing. What is the best way to go about this? I think I want to do something like this: Class UserControl0 Private mds as Dataset Private mMyString as String Protected Property DS as Dataset Get return mds End Get Set (value as Dataset) mds=value End Set End Property Protected Overridable Sub MyExample mMyString=mds.Tables(0).TableName End Sub .. .. .. .. End Class Class ChildUserControl Inherits UserControl0 Private mds as MyStronglyTypedDataset Private mMyValue as Object Public Shadows Property DS as MyStronglyTypedDataset Get Return CType(MyBase.DS,MyStronglyTypedDataset) End Get Set (Value as MyStronglyTypedDataset) MyBase.DS=CType(Value,Dataset) End Set End Property Protected Overrides Sub MyExample MyBase.MyExample mMyValue=mds.MyTable.MyColumn End Sub .. .. .. .. End Class Of course, this won't work because CType doesn't work between Dataset as MyStronglyTypedDataset. But I think you can get the idea of what I am trying to accomplish. Thanks for the help, -- Pat Pat,
I get more and more the idea that what you call a usercontrol is not a usercontrol. A usercontrol is a kind of inherited or own written textbox, combobox etc. Using the toolbox you can beside controls as well get other components as dataset, adapters which you can place under the tag user controls. Is that maybe (at least for me) the confusing part. What I now see is in my opinion a kind of strongly typed dataset. I made once a very simple for for Klaus. Is that what you are looking for? \\\needs a datagrid on a form Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim ds As New MyDataset For i As Integer = 0 To 10 ds.KlausTableAddNew(New Object() {i.ToString, ChrW(i + 65)}) Next DataGrid1.DataSource = ds.TableKlaus End Sub End Class /// \\\Dataset Public Class MyDataset Inherits DataSet Sub New() MyBase.new() Dim dt As New DataTable("TableKlaus") Me.Tables.Add(dt) dt.Columns.Add("Klaus") dt.Columns.Add("Cor") dt = New DataTable("TableCor") Me.Tables.Add(dt) dt.Columns.Add("John") dt.Columns.Add("Herfried") End Sub Public ReadOnly Property TableKlaus() As DataTable Get Return Me.Tables("TableKlaus") End Get End Property Public ReadOnly Property TableCor() As DataTable Get Return Me.Tables("TableCor") End Get End Property Public Sub KlausTableAddNew(ByVal obj As Object()) Dim dr As DataRow = Me.TableKlaus.NewRow dr.ItemArray = obj Me.TableKlaus.Rows.Add(dr) End Sub End Class /// I hope this helps a little bit? Cor Cor,
Thanks for your reply. However, I'm don't really know how to apply it to my situation, indeed even if it DOES apply. Perhaps my example was too abstract. Here is the situation: I have designed a number of UserControls that I call data entry panels. They all inherit from one base UserControl. The base control has, for example, a "Save", a "New, a "Delete", and a "Print" button, as well as a checkbox (viewed as a button) that puts the panel in or out of "Edit" mode. Since each of the "data entry panels" is used for entering data into different datasources, they each have their own strongly typed data set as well as their own textboxes and/or other appropriate controls. The base control implements many methods that are overridable by the data entry panels. For example: Class BaseUserControl Private mfInEdit As Boolean=False Protected Property InEdit As Boolean Get return mfInEdit End Get Set (Value As Boolean) If Value<>mfInEdit then RaiseEvent InEditChanging(Me, New EventArgs) mfInEdit=Value OnInEditChanged RaiseEvent InEditChanged(Me, New EventArgs) End If End Set End Property Protected Sub ColumnChanging .. .. .. End Sub Protected Overridable Sub OnInEditChanged . . . End Sub .. .. .. End Class Class DataEntryPanel1 Inherits BaseUserControl Protected Overrides Sub OnInEditChanged If InEdit Then AddHandler MyDataSet1.MyDataTable1.ColumnChanging, New DataColumnChangeEventHandler(AddressOf MyBase.ColumnChanging) Else RemoveHandler MyDataSet1.MyDataTable1.ColumnChanging, New DataColumnChangeEventHandler(AddressOf MyBase.ColumnChanging) End If End Sub .. .. .. End Class Since all the data entry panels want to do this same thing (only on different strongly typed datasets) it seems it would be nice to generalize and move the overriding InEditChanged code into the base class, for example: Protected Overridable Sub OnInEditChanged If InEdit Then AddHandler mBaseDataset.Tables(mstrTableName).ColumnChanging, New DataColumnChangeEventHandler(AddressOf MyBase.ColumnChanging) Else RemoveHandler mBaseDataset.Tables(mstrTableName).ColumnChanging, New DataColumnChangeEventHandler(AddressOf MyBase.ColumnChanging) End If End Sub Where mBaseDataset would be an untyped dataset and a property of the BaseUserControl (shadowed by the inheriting data entry panels), and mstrTableName would be a string property (value provided by the inheriting data entry panels) of the BaseUserControl. Thanks for any help, Pat Show quoteHide quote "Cor Ligthert" wrote: > Pat, > > I get more and more the idea that what you call a usercontrol is not a > usercontrol. > > A usercontrol is a kind of inherited or own written textbox, combobox etc. > Using the toolbox you can beside controls as well get other components as > dataset, adapters which you can place under the tag user controls. Is that > maybe (at least for me) the confusing part. > > What I now see is in my opinion a kind of strongly typed dataset. > > I made once a very simple for for Klaus. Is that what you are looking for? > > \\\needs a datagrid on a form > Private Sub Form1_Load(ByVal sender As Object, _ > ByVal e As System.EventArgs) Handles MyBase.Load > Dim ds As New MyDataset > For i As Integer = 0 To 10 > ds.KlausTableAddNew(New Object() {i.ToString, ChrW(i + 65)}) > Next > DataGrid1.DataSource = ds.TableKlaus > End Sub > End Class > /// > \\\Dataset > Public Class MyDataset > Inherits DataSet > Sub New() > MyBase.new() > Dim dt As New DataTable("TableKlaus") > Me.Tables.Add(dt) > dt.Columns.Add("Klaus") > dt.Columns.Add("Cor") > dt = New DataTable("TableCor") > Me.Tables.Add(dt) > dt.Columns.Add("John") > dt.Columns.Add("Herfried") > End Sub > Public ReadOnly Property TableKlaus() As DataTable > Get > Return Me.Tables("TableKlaus") > End Get > End Property > Public ReadOnly Property TableCor() As DataTable > Get > Return Me.Tables("TableCor") > End Get > End Property > Public Sub KlausTableAddNew(ByVal obj As Object()) > Dim dr As DataRow = Me.TableKlaus.NewRow > dr.ItemArray = obj > Me.TableKlaus.Rows.Add(dr) > End Sub > End Class > /// > I hope this helps a little bit? > > Cor > > > Pat,
It is called one of the worst things that you can do is when you mix data with controls. Don't ask me to give you an example for that which will than be forever as a sample from Cor on Internet. :-) CorOK. That helps a lot!!
:-) Thanks Cor,Pat Show quoteHide quote "Cor Ligthert" wrote: > Pat, > > It is called one of the worst things that you can do is when you mix data > with controls. > > Don't ask me to give you an example for that which will than be forever as a > sample from Cor on Internet. > > :-) > > Cor > > >
How to access aspx page thru the menu control only?
Reading Output from Shell Command How to Move Mouse to Control with Focus conversion issue Writing TIF to database Dataview Find method, case insensitive? open binary file and search hex string Problems with the excel find function in vb.net Remote debugging: Unable to map the debug start page URL to a machine name Moving a windows form from a windows app to a class library. |
|||||||||||||||||||||||