473,722 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DataGridTableSt yle 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
programmaticall y, 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(dataSo urce);
dataView.AllowD elete = false;
dataView.AllowN ew = false;
dataView.Sort = sortByField + "ASC";
DoBinding();
}
void DoBinding()
{
const int NameColumnWidth = 130;
grdPerson.DataS ource = dataView;
DataGridTableSt yle tableStyle = new DataGridTableSt yle();
tableStyle.Mapp ingName = dataView.Table. TableName;
tableStyle.Read Only = true;
tableStyle.RowH eadersVisible = false;
DataGridTextBox Column col = new DataGridTextBox Column();
col.HeaderText = "Name";
col.MappingName = "ListBy";
col.Width = NameColumnWidth ;
tableStyle.Grid ColumnStyles.Ad d(col);
grdPerson.Table Styles.Add(tabl eStyle);
currencyManager = (CurrencyManage r) grdPerson.Bindi ngContext[dataView];
currencyManager .PositionChange d += new System.EventHan dler(PositionCh anged);
}
// 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.RowFil ter = filter;
// Highlight first record in grid
if (dataView.Count > 0)
grdPerson.Selec t(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.Dat aSet.Tables["person"]);
nvgPerson.SetDa taBinding(dataV iew);
txtFirst.DataBi ndings.Add("Tex t", db.DataSet, "person.FirstNa me");
txtMiddle.DataB indings.Add("Te xt", db.DataSet, "person.MiddleN ame");
txtLast.DataBin dings.Add("Text ", db.DataSet, "person.LastNam e");
cbxSuffix.DataB indings.Add("Te xt", db.DataSet, "person.Suffix" );
chkSpouse.DataB indings.Add("Ch ecked", db.DataSet, "person.HasSpou se");
//
// 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.DataS ource = viewManager;
grdPerson.DataM ember = table;
this.viewManage r = viewManager;
DataGridTableSt yle tableStyle = new DataGridTableSt yle();
tableStyle.Mapp ingName = table;
tableStyle.Read Only = true;
tableStyle.RowH eadersVisible = false;
DataGridTextBox Column col = new DataGridTextBox Column();
col.HeaderText = "Name";
col.MappingName = "ListBy";
col.Width = NameColumnWidth ;
tableStyle.Grid ColumnStyles.Ad d(col);
grdPerson.Table Styles.Add(tabl eStyle);
currencyManager = (CurrencyManage r) grdPerson.Bindi ngContext[viewManager,
table];
}
void ApplyTextFilter ()
{
string findText;
string filter;
findText = txtFind.Text;
if (findText == "")
filter = "";
else
filter = "ListBy Like '" + findText + "*'";
viewManager.Dat aViewSettings["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.Dat aSet = db.DataSet;
viewManager.Dat aViewSettings["person"].Sort = "ListBy ASC";
nvgPerson.SetDa taBinding(viewM anager, "person");
txtFirst.DataBi ndings.Add("Tex t", viewManager, "person.FirstNa me");
txtMiddle.DataB indings.Add("Te xt", viewManager, "person.MiddleN ame");
txtLast.DataBin dings.Add("Text ", viewManager, "person.LastNam e");
cbxSuffix.DataB indings.Add("Te xt", viewManager, "person.Suffix" );
chkSpouse.DataB indings.Add("Ch ecked", viewManager, "person.HasSpou se");
//
// etc
//

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

Patrick
Nov 16 '05 #1
0 3643

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

Similar topics

9
4353
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 predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
7
2266
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, records info about a person. The second table, Case, records information about a person's case, almost like a human resources database. The primary key of the table, person, is his/ her social security number. The primary key of the other...
6
4994
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 for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
17
3411
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 it's "On Click" Event proceedure to Loop through my Database and find any records that fall within a Certain Date...if a record is found...it then emails me that a record
17
3553
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 populated when a user scans a label. The other is ScanDate - a date/time field that should equal the date/time of the scan (e.g. 7/31/2006 5:00:00 AM).
15
2576
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 determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
4
12438
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
5
2513
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 startdate and enddate, all in the same query.
1
1706
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 many database tables with relationship and need the cycle time of projects. i have a huge database based on date and time need to create
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.