L
Lorenz Kahl
Hi,
unfortunately I couldn't make up a subject, that describes the problem
better. Here's what I tried to do:
I'm writing a WinForms application that consists of three layers
(assemblies / projects), the WinForms-UI / the business logic layer
(BLL) / the data access layer (DAL).
The DAL defines a typed DataSet 'MemberDataSet'. It also has a class
'MemberDALC' with a method 'GetAllMembers()' which returns a properly
filled instance of the MemberDataSet.
Next I would like to use the VS.NET designer surface to bind my controls
to this DataSet graphically(!). So I pulled a DataSet-component on the
surface and chose the externally referenced DataSet definition
DAL.MemberDataSet. Then I can bind everything as usual.
So far everything works just fine.
NOW THE PROBLEM:
The generated code of the designer instantiates a new (empty) instance
of the DataSet using the default constructor like this:
InitializeComponent()
{
this.memberDataSet1 = new DAL.MemberDataSet();
....
}
Well, that's fine - but as I said it's empty. I would like to have a
filled DataSet, when the form loads. So I did this:
private void FrmTest_Load(object sender, System.EventArgs e)
{
this.memberDataSet1 = (new MemberDALC()).GetAllMembers();
....
}
This shows no effect and all bound controls will still be shown empty,
although the memberDataSet1 actually holds the data after this function
call.
I guess my problem is that I'm lacking real experience with
WinForms-Databinding and I really just have to call an additional
'refresh', 'update' or 'redraw'-function. But I couldn't find anything.
I found two workarounds though. One is to replace the generated code in
the InitializeComponent-method to call the GetAllMembers method directly
instead of the DataSet-constructor. But I don't like messing with
auto-generated code plus VS.NET gives me several warnings afterwards.
The second way I figured out is to call Merge() on the empty DataSet
like so:
private void FrmTest_Load(object sender, System.EventArgs e) {
this.memberDataSet1.Merge((new MemberDALC()).GetAllMembers());
}
That works but looks kind of awkward to me. Any other suggestions will
be greatly appreciated. Sorry for this long post ;-)
Best regards,
Lorenz
unfortunately I couldn't make up a subject, that describes the problem
better. Here's what I tried to do:
I'm writing a WinForms application that consists of three layers
(assemblies / projects), the WinForms-UI / the business logic layer
(BLL) / the data access layer (DAL).
The DAL defines a typed DataSet 'MemberDataSet'. It also has a class
'MemberDALC' with a method 'GetAllMembers()' which returns a properly
filled instance of the MemberDataSet.
Next I would like to use the VS.NET designer surface to bind my controls
to this DataSet graphically(!). So I pulled a DataSet-component on the
surface and chose the externally referenced DataSet definition
DAL.MemberDataSet. Then I can bind everything as usual.
So far everything works just fine.
NOW THE PROBLEM:
The generated code of the designer instantiates a new (empty) instance
of the DataSet using the default constructor like this:
InitializeComponent()
{
this.memberDataSet1 = new DAL.MemberDataSet();
....
}
Well, that's fine - but as I said it's empty. I would like to have a
filled DataSet, when the form loads. So I did this:
private void FrmTest_Load(object sender, System.EventArgs e)
{
this.memberDataSet1 = (new MemberDALC()).GetAllMembers();
....
}
This shows no effect and all bound controls will still be shown empty,
although the memberDataSet1 actually holds the data after this function
call.
I guess my problem is that I'm lacking real experience with
WinForms-Databinding and I really just have to call an additional
'refresh', 'update' or 'redraw'-function. But I couldn't find anything.
I found two workarounds though. One is to replace the generated code in
the InitializeComponent-method to call the GetAllMembers method directly
instead of the DataSet-constructor. But I don't like messing with
auto-generated code plus VS.NET gives me several warnings afterwards.
The second way I figured out is to call Merge() on the empty DataSet
like so:
private void FrmTest_Load(object sender, System.EventArgs e) {
this.memberDataSet1.Merge((new MemberDALC()).GetAllMembers());
}
That works but looks kind of awkward to me. Any other suggestions will
be greatly appreciated. Sorry for this long post ;-)
Best regards,
Lorenz