Basic Binding and Filtering Problem

G

Guest

I'm caught in a Catch-22 position with a fairly basic ADO.Net problem. I have
bound a data adapter called "DateTableDataAdapter" to a simple Microsoft
Access table called "DateTable" with a couple of datetime columns, a memo
column called Synopsis, a text column called Title with unique values and
another text column called Type with non-unique values.

Here's the dilemma. I need to bind a datagrid,monthcalendar and a textbox to
the adapter so that when you click on a particular date in the datagrid, the
monthcalendar reflects the current date in one of the datetimecolumns and the
textbox displays the data in the Synopsis column. I also need to be able to
filter the results by the Type column, so that I can exclude all results of
Type "B" or "C" or whatever with the click of a button, for example. The
problem is that I can't do both at the same time.

If I access the data through a dataset, the grid and monthcalendar bind
properly and stay in sync, but changing the filter on the dataset table's
defaultview doesn't have any effect - it doesn't raise an error when I change
the filter programmatically, yet nothing happens. On the other hand, if I use
a dataview, filtering works but the monthcalendar and textbox don't stay in
sync with the grid. What gives?

Any feedback would be appreciated...this is a really crucial problem for the
small project I'm working on right now.

Thanks,

-- Steve
 
B

Bart Mermuys

Hi,

Dok said:
I'm caught in a Catch-22 position with a fairly basic ADO.Net problem. I
have
bound a data adapter called "DateTableDataAdapter" to a simple Microsoft
Access table called "DateTable" with a couple of datetime columns, a memo
column called Synopsis, a text column called Title with unique values and
another text column called Type with non-unique values.

Here's the dilemma. I need to bind a datagrid,monthcalendar and a textbox
to
the adapter so that when you click on a particular date in the datagrid,
the
monthcalendar reflects the current date in one of the datetimecolumns and
the
textbox displays the data in the Synopsis column. I also need to be able
to
filter the results by the Type column, so that I can exclude all results
of
Type "B" or "C" or whatever with the click of a button, for example. The
problem is that I can't do both at the same time.

If I access the data through a dataset, the grid and monthcalendar bind
properly and stay in sync,

If you want Controls to navigate dependent then bind them to the same
DataSource.

You can bind them all to a DataTable, all to a DataSet or all to a DataView.

DataTable.DefaultView will only work if you bound to a DataTable, not
DataSet.

Since you also want filtering, i woud use (the same) DataView for all
Controls and then filter that.

HTH,
Greetings
 
G

Guest

Bart Mermuys said:
Hi,



If you want Controls to navigate dependent then bind them to the same
DataSource.

You can bind them all to a DataTable, all to a DataSet or all to a DataView.

DataTable.DefaultView will only work if you bound to a DataTable, not
DataSet.

Since you also want filtering, i woud use (the same) DataView for all
Controls and then filter that.

HTH,
Greetings

Thanks Bart - The problem is that I already have the controls and the grid
bound to the same dataview, yet they don't stay in sync.

-- Steve
 
B

Bart Mermuys

Hi,

Dok said:
Thanks Bart - The problem is that I already have the controls and the grid
bound to the same dataview, yet they don't stay in sync.

If they are bound to the same DataView and remain bound to the same
DataView, and you still have this problem, then show what bindings you are
making (code) and explain when exactly the controls get out of sync, does it
only happen after the grid shows an empty list ?

HTH,
Greetings
 
G

Guest

Bart Mermuys said:
Hi,



If they are bound to the same DataView and remain bound to the same
DataView, and you still have this problem, then show what bindings you are
making (code) and explain when exactly the controls get out of sync, does it
only happen after the grid shows an empty list ?

HTH,
Greetings


Hey Bart - I don't have any code written beyond filling the data adapter.
That's all it takes to keep the controls and grid in sync when all of them
are bound to a dataset; the grid is filled immediately as soon as the form is
loaded and clicking on individual records updates the controls properly. I've
tried binding the controls and the grid to the same dataview instead and
filling the data adapter during the form's load event in the exact same way,
but then it doesn't stay in sync. In both cases the grid immediately fills up
with a few thousand items upon the window's creation, but the controls only
update when navigating the records in the grid if they're all bound to the
same dataset, not the same dataview. It is possible to navigate the records
in the same way with either a dataset or a dataview, but there's no
synchronization with the other controls with the latter. They're out of sync
right from the beginning, as soon as the form loads and it stays that way no
matter how many records you navigate through in the datagrid. An empty list
is not a factor because the table the grid is bound to always has a few
thousand records in it.

I'm stumped because there's very little code involved and no change in any
other variables beyond changing the binding of the controls to the same
dataview instead of the same dataset, yet the behavior is vastly different in
the two examples, and not what I'd expect based on the .Net documentation.

Thanks for your help,

-- Steve
 
B

Bart Mermuys

Hi,

Dok said:
[snip]
Hey Bart - I don't have any code written beyond filling the data adapter.
That's all it takes to keep the controls and grid in sync when all of them
are bound to a dataset; the grid is filled immediately as soon as the form
is
loaded and clicking on individual records updates the controls properly.
I've
tried binding the controls and the grid to the same dataview instead and
filling the data adapter during the form's load event in the exact same
way,
but then it doesn't stay in sync. In both cases the grid immediately fills
up
with a few thousand items upon the window's creation, but the controls
only
update when navigating the records in the grid if they're all bound to the
same dataset, not the same dataview. It is possible to navigate the
records
in the same way with either a dataset or a dataview, but there's no
synchronization with the other controls with the latter. They're out of
sync
right from the beginning, as soon as the form loads and it stays that way
no
matter how many records you navigate through in the datagrid. An empty
list
is not a factor because the table the grid is bound to always has a few
thousand records in it.

I'm stumped because there's very little code involved and no change in any
other variables beyond changing the binding of the controls to the same
dataview instead of the same dataset,

I don't know what is going on either, from what you are describing it still
sounds like the same DataView isn't used, though i realize you clearly state
you are using the same DataView.

You know, when you bind to a DataSet it will (internally) use a DataView too
(DataSet nor DataTable are directly bindable). So maybe you can go this
way. Bind everything to a DataSet (since that's working) and then use the
following code to filter:

CurrencyManager cm = (CurrencyManager)BindingContext[yourDataSet,
"YourTableName"];
DataView dv = (DataView)cm.List;
dv.RowFilter = "...";

Other then that, also be carefull because DateTimePicker, CheckBox and other
Controls may have problems with null values or empty lists, so you might
just want to try with only a grid and TextBoxes until you know it's working.

HTH,
Greetings
 
G

Guest

Bart Mermuys said:
Hi,

Dok said:
[snip]
Hey Bart - I don't have any code written beyond filling the data adapter.
That's all it takes to keep the controls and grid in sync when all of them
are bound to a dataset; the grid is filled immediately as soon as the form
is
loaded and clicking on individual records updates the controls properly.
I've
tried binding the controls and the grid to the same dataview instead and
filling the data adapter during the form's load event in the exact same
way,
but then it doesn't stay in sync. In both cases the grid immediately fills
up
with a few thousand items upon the window's creation, but the controls
only
update when navigating the records in the grid if they're all bound to the
same dataset, not the same dataview. It is possible to navigate the
records
in the same way with either a dataset or a dataview, but there's no
synchronization with the other controls with the latter. They're out of
sync
right from the beginning, as soon as the form loads and it stays that way
no
matter how many records you navigate through in the datagrid. An empty
list
is not a factor because the table the grid is bound to always has a few
thousand records in it.

I'm stumped because there's very little code involved and no change in any
other variables beyond changing the binding of the controls to the same
dataview instead of the same dataset,

I don't know what is going on either, from what you are describing it still
sounds like the same DataView isn't used, though i realize you clearly state
you are using the same DataView.

You know, when you bind to a DataSet it will (internally) use a DataView too
(DataSet nor DataTable are directly bindable). So maybe you can go this
way. Bind everything to a DataSet (since that's working) and then use the
following code to filter:

CurrencyManager cm = (CurrencyManager)BindingContext[yourDataSet,
"YourTableName"];
DataView dv = (DataView)cm.List;
dv.RowFilter = "...";

Other then that, also be carefull because DateTimePicker, CheckBox and other
Controls may have problems with null values or empty lists, so you might
just want to try with only a grid and TextBoxes until you know it's working.

HTH,
Greetings


Thanks Bart, I'll give that code a shot and see what happens. You know, it
very well might be a problem with null values like you said because many of
the initial records have null values for their date columns. I'll check that
out too. I can tell this is one of those frustrating programming problems
where the culprit is something that's gone unnoticed because it's
embarrassingly simple, LOL - I hate those most of all, hah hah. This little
problem has held me up more that some of the complicated code I was writing
for the same project. Thanks for your help :D

--- Steve
 

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