PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Basic Binding and Filtering Problem
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Basic Binding and Filtering Problem
![]() |
Basic Binding and Filtering Problem |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Hi,
"Dok" <Dok@discussions.microsoft.com> wrote in message news:9B3B4D2A-AB10-4E08-97E5-E9F3995FEFF9@microsoft.com... > 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 > 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 > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
"Bart Mermuys" wrote: > Hi, > > "Dok" <Dok@discussions.microsoft.com> wrote in message > news:9B3B4D2A-AB10-4E08-97E5-E9F3995FEFF9@microsoft.com... > > 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 > > > 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 > > > > > 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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Hi,
"Dok" <Dok@discussions.microsoft.com> wrote in message news:4F649C2D-A369-4795-A5BD-2BC8E2827E92@microsoft.com... > > > "Bart Mermuys" wrote: > >> Hi, >> >> "Dok" <Dok@discussions.microsoft.com> wrote in message >> news:9B3B4D2A-AB10-4E08-97E5-E9F3995FEFF9@microsoft.com... >> > 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 >> >> > 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 >> > >> >> >> > > 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 > > -- Steve |
|
|
|
#5 |
|
Guest
Posts: n/a
|
"Bart Mermuys" wrote: > Hi, > > "Dok" <Dok@discussions.microsoft.com> wrote in message > news:4F649C2D-A369-4795-A5BD-2BC8E2827E92@microsoft.com... > > > > > > "Bart Mermuys" wrote: > > > >> Hi, > >> > >> "Dok" <Dok@discussions.microsoft.com> wrote in message > >> news:9B3B4D2A-AB10-4E08-97E5-E9F3995FEFF9@microsoft.com... > >> > 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 > >> > >> > 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 > >> > > >> > >> > >> > > > > 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 > > > > > > -- Steve > > > > 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 |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Hi,
"Dok" <Dok@discussions.microsoft.com> wrote in message news:641029F7-E251-4EFF-8D5C-424A09C7937F@microsoft.com... > > [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 >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 |
|
|
|
#7 |
|
Guest
Posts: n/a
|
"Bart Mermuys" wrote: > Hi, > > "Dok" <Dok@discussions.microsoft.com> wrote in message > news:641029F7-E251-4EFF-8D5C-424A09C7937F@microsoft.com... > > > > [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 ![]() --- Steve |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


