472,780 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

Help with best way to create a filtering record selector in a database application

I'm working on a contact management application, and need a hand with one
aspect...

Here's what I want to create:
------------------------------------
A form split into two parts. There is a datagrid on the left side that lists
names and perhaps a couple of other key fields. The user can click on a
record in the datagrid, which should automatically pull up details on that
record in the various text boxes and other controls on the right side of the
form.

The datagrid on the left side of the form should also be filterable. A
filter is entered from a textbox above the datagrid. For example,
if the user types "An" in the textbox, the datagrid only shows names
that start with "An" (e.g. "Anderson", "Anthony", "Anzar").

So I want 2 features:
1) a datagrid that is used as a record selector, and
2) a datagrid that may be filtered.
Here's my problem
------------------------------------
I can get either feature #1 or feature #2 to work, but not both at the same
time.

To get feature #1 to work, I bind the datagrid to my "contact" table,
and then I bind my various textboxes and other controls to individual fields
within the "contact" table. And then like magic,
when I select a record in the datagrid on the left side of the form,
that record is pulled up in the controls on the rigth side of the form.
I can also get feature #1 to work by putting my DataSet into a
DataViewManager,
and then binding my datagrid and my other controls to that.

To get feature #2 to work, I create a DataView object based on my "contact"
table, and then bind the datagrid to that DataView object. When I change the
RowFilter property, the grid changes just as I want. But when I select a
record in the datagrid, nothing happens on the right side of the form.
My own experiments
------------------------------------
I've tried experimenting with performing filters on the "contact" table's
DefaultView, but changing the RowFilter property doesn't seem to do
anything.

I've tried using a DataViewManager object for filtering without success (I
don't really
understand them completely).
Other notes
------------------------------------
1) I don't want all the fields from "contacts" appearing in the datagrid, so
I use a DataGridTableStyle to customize how stuff appears in the datagrid. I
don't think this effects anything adversely.

2) The datagrid, along with a couple of other controls, is tucked into a
User Control, which I've called Navigator. I don't think this effects
anything adversely either.

3) I'm using SharpDevelop, not Visual Studio (yet), so I do databinding
programmatically, not through the form designer.
Request for help
------------------------------------
I'm very experienced with C but new to C# and .Net (and I really like it). I
could really use advise on the best way to accomplish this task, but I also
wish to solicit advice on proper coding style and better program structure.
My code (without indents) from my Navigator user control, version 1
----------------------------------------------------------------------
// In this version, the filtering works, but the DataGrid stops acting as a
// record selector.
// grdPerson is the name of my DataGrid.
// My user control is called Navigator.
// The following code is used to set up the databinding.
DataView dataView;
public void SetDataBinding(DataView dataSource)
{
dataView = dataSource;
DoBinding();
}
public void SetDataBinding(DataTable dataSource, string sortByField)
{
dataView = new DataView(dataSource);
dataView.AllowDelete = false;
dataView.AllowNew = false;
dataView.Sort = sortByField + "ASC";
DoBinding();
}
void DoBinding()
{
const int NameColumnWidth = 130;
grdPerson.DataSource = dataView;
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = dataView.Table.TableName;
tableStyle.ReadOnly = true;
tableStyle.RowHeadersVisible = false;
DataGridTextBoxColumn col = new DataGridTextBoxColumn();
col.HeaderText = "Name";
col.MappingName = "ListBy";
col.Width = NameColumnWidth;
tableStyle.GridColumnStyles.Add(col);
grdPerson.TableStyles.Add(tableStyle);
currencyManager = (CurrencyManager) grdPerson.BindingContext[dataView];
currencyManager.PositionChanged += new System.EventHandler(PositionChanged);
}
// textFind is TextBox where user types in the filter.
// User types "A", grid filters to people named "A*".
// ApplyTextFilter() is called when the TextChanged event is fired.
void ApplyTextFilter()
{
string findText;
string filter;
findText = txtFind.Text;
if (findText == "")
filter = "";
else
filter = "ListBy Like '" + findText + "*'";
dataView.RowFilter = filter;
// Highlight first record in grid
if (dataView.Count > 0)
grdPerson.Select(0);
}
//
// Here is an excerpt of code from my MainForm.
// nvgPerson is an instance of my Navigator user control.
// db is an instance of a class that handles connected to my database.
// nvgPerson is bound to a DataView based on a table from db.DataSet.
// Other controls are bound directly to fields in a table in db.DataSet.
//
DataView dataView = new DataView(db.DataSet.Tables["person"]);
nvgPerson.SetDataBinding(dataView);
txtFirst.DataBindings.Add("Text", db.DataSet, "person.FirstName");
txtMiddle.DataBindings.Add("Text", db.DataSet, "person.MiddleName");
txtLast.DataBindings.Add("Text", db.DataSet, "person.LastName");
cbxSuffix.DataBindings.Add("Text", db.DataSet, "person.Suffix");
chkSpouse.DataBindings.Add("Checked", db.DataSet, "person.HasSpouse");
//
// etc
//

My code (without indents) from my Navigator user control, version 2
----------------------------------------------------------------------
// In this version, the DataGrid works as a record selector,
// but I can't get it to filter.
ViewManager viewManager;
public void SetDataBinding(DataViewManager viewManager, string table)
{
const int NameColumnWidth = 130;
grdPerson.DataSource = viewManager;
grdPerson.DataMember = table;
this.viewManager = viewManager;
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = table;
tableStyle.ReadOnly = true;
tableStyle.RowHeadersVisible = false;
DataGridTextBoxColumn col = new DataGridTextBoxColumn();
col.HeaderText = "Name";
col.MappingName = "ListBy";
col.Width = NameColumnWidth;
tableStyle.GridColumnStyles.Add(col);
grdPerson.TableStyles.Add(tableStyle);
currencyManager = (CurrencyManager) grdPerson.BindingContext[viewManager,
table];
}
void ApplyTextFilter()
{
string findText;
string filter;
findText = txtFind.Text;
if (findText == "")
filter = "";
else
filter = "ListBy Like '" + findText + "*'";
viewManager.DataViewSettings["person"].RowFilter = filter;
}
//
// Here is an excerpt of code from my MainForm.
// nvgPerson is an instance of my Navigator user control.
// db is an instance of a class that handles connected to my database.
//
DataViewManager viewManager = new DataViewManager();
viewManager.DataSet = db.DataSet;
viewManager.DataViewSettings["person"].Sort = "ListBy ASC";
nvgPerson.SetDataBinding(viewManager, "person");
txtFirst.DataBindings.Add("Text", viewManager, "person.FirstName");
txtMiddle.DataBindings.Add("Text", viewManager, "person.MiddleName");
txtLast.DataBindings.Add("Text", viewManager, "person.LastName");
cbxSuffix.DataBindings.Add("Text", viewManager, "person.Suffix");
chkSpouse.DataBindings.Add("Checked", viewManager, "person.HasSpouse");
//
// etc
//

-----------------------------------
Thanks!

Patrick
Nov 16 '05 #1
0 3546

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
7
by: Megan | last post by:
Hi everybody- I inherited a database that somehow uses a bound combo box as a record selector. Let me give you some background. The form is based on data from 2 tables. The first table, Person,...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
17
by: Liam.M | last post by:
Hey guys, Forgive me if my question my be alittle silly, but I would very much appreciate and assistance that could be given! My situation is as follows: I have created a Button, and set...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
5
by: Sam | last post by:
Hi, I have one table like : MyTable {field1, field2, startdate, enddate} I want to have the count of field1 between startdate and enddate, and the count of field2 where field2 = 1 between...
1
by: access baby | last post by:
Hi Below mention is the reply from Salad on my query i created a crosstab query and form not based on any table of qurey but this doesnt work . I somehow have missed something actually i have too...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.