dataset inheritance

G

Guest

I have designed a user control (UserControl0) from which several other user
controls (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,
 
C

Cor Ligthert

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
 
G

Guest

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
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top