Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Offline filtering dataset with databinding to text boxes
 

Offline filtering dataset with databinding to text boxes

I am working on a smart client Winforms application (C#) modelled on TaskVision. I have have one combo box (Projects) and several text boxes (demographic data). I am
binding the text boxes to the dataset (DsPersons). When selecting a
project in the combobox, the relevant (matching) dataset is retrieved. In TaskVision, a datagrid is populated with data related to the Combobox selection. I am adapting this to populate textboxes.

When in offline mode, all the Person' information is stored in one xml
file regardless of the project. This file holds the ID the projects
matching the options selectable in the Projects combobox. Therefore in
offline mode I am needing to filter the dataset to bind only the
filtered subset to the controls based on the project selection.

Below is more detail of my problem. Hopefully someone can assist.

I can databind and I can cycle through records.
However all records are displayed rather than just those related to
the Project displayed in the combo box.

How do apply a filter where databinding has been utililised?

My binding code is below:
-----------------------------------------------------------
txtFirstName.DataBindings.Add("Text",m_DataLayer.DsPerson,
"Person.FirstName");
txtsurname.DataBindings.Add ("Text",m_DataLayer.DsPerson,
"Person.Surname");
txtTelH.DataBindings.Add ("Text",m_DataLayer.DsPerson,"Person.Email");
 
//Get a reference to the BindingManagerBase for the Person table.
bm = BindingContext[m_DataLayer.DsPerson, "Person"];
   
drvPerson =(DataRowView)bm.Current;   

-----------------------------------------------------------
I have tried to use the below code which would satisfy a filter for a
datagrid:
m_DataLayer.DSPerson.Person.DefaultView.RowFilter = "ProjectID =" +
m_ProjectID;
This has no effect.

I have tried binding to a dataview which permitted the control
databinding but an error is thrown ("Cannot create Child list for
field Person") at the point of setting binding context to the datview.
If one leaves the Binding context to the dataset then the controls are
bound to the dataview and the binding context to the dataset and
therefore the datataset cycles but not the dataview when the "Next"
navigation button is selectd to cycle through records (using the code
bm.Position += 1).

Is it possible to achieve binding to a filitered dataset when using
binding?

Thanks in advance.

Grant
MigrationUser 1  Sunday, September 19, 2004 7:16 PM
OK I found it - Always simple when you got it.

You can bind to the dataview but just need a Null as second parameter when calling BindingContext.

Code that works is below:
dvw = null;
dvw = new DataView (m_DataLayer.DsPersons.Person,m_ResourceManager.GetString("ProjectID") + m_ProjectID,null,DataViewRowState.CurrentRows);
pbPosition.Maximum = dvw.Count;

txtFirstName.DataBindings.Add("Text",dvw, "FirstName");
txtsurname.DataBindings.Add ("Text",dvw, "Surname");
txtTelH.DataBindings.Add ("Text",dvw,"Email");

//Get a reference to the BindingManagerBase for the Person table.
bm = BindingContext[dvw, null];
drvPerson =(DataRowView)bm.Current;
MigrationUser 1  Monday, September 27, 2004 5:40 AM

You can use google to search for other answers

Custom Search

More Threads

• How to access Issue Vision from Remote PC
• IssueList outlook control
• Modeling ASP.net security
• Anyone know of a good .Net CF developers forum?
• How long did the initial version of this application take to develop?
• Merging Cells in Listview/Datagridview etc...?
• Direct ADO instead of Web Service
• Is taskvision free?
• Make a Master-Detail form in VB.Net.
• Problems Creating an Installer Package