Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering a bandwidth of dates in a DBGrid

Status
Not open for further replies.

sparky1970

Programmer
Feb 8, 2009
5
GB
Hi all,

Does anybody know which is the easiest way of fitering a dataset so that it displays only those dates which are between those which are defined by the user?

I've got myself a DBGrid which has 8 or so columns of data, filtering hasn't been a problem up until now because I've only been interested in filtering identical multiple field values e.g. Customer, Project Number, and supplier etc. Now I want to provide a filter which will display only those lines in the table which have invoice dates which fall between those specified in two edit boxes.

Is this possible?

Thanks
Ivan
 
I think there is an example of this in your sample files.


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Calling 2ffat..............

Do you have an answer for me or not? Your last post was somewhat vague!!. What I really need is for somebody to respond who can give me more than just a hint. If you can help me then please respond, if not then lay low until the answer comes in!

Crikey, I post questions on the IET forum all the time and I always get constructive and definitive replies, what is this forum all about???
 
You know, patience is a virtue, and you definitely don't have it.

People have their jobs and other stuff to do, and they don't have to answer to your question right away, and sometimes answer requires further investigation.

This would be my answer to you.

Best regards, anyway.
 
Sorry, I've been busy.

The following code snippet is from my Builder 6 examples. This one is found in C:\Program Files\Borland\CBuilder6\Examples\DBTasks\Filter. Yours may be elsewhere depending on your version or preferences.

What this example does is creates a combo box with a listing of various filters you can apply to one of their examples. In this example, they have a sample data base with a date named, "LastInvoiceDate." Their example selects a data range and the field named, "Country," to be US.

Code:
// These strings could not be added to the ComboBox at design time because to
// do so would have hard wired us for a single country's date format.  The
// following lines will honor Windows 95 and NT's regional settings.
  ComboBox1->Items->Add("LastInvoiceDate >= '" +
                         DateToStr(EncodeDate(1994, 9, 30)) + "'");
  ComboBox1->Items->Add("Country = 'US' and LastInvoiceDate > '" +
                         DateToStr(EncodeDate(1994, 6, 30)) + "'");

Essentially, you take a date and turn it into a string to apply to the filter.
Code:
  if (ComboBox1->Text != "") {
    data->Filter = ComboBox1->Text;
    data->Filtered = true;
    fmCustView->Caption = "Customers - Filtered";
  }
  else {
    data->Filter = "";
    data->Filtered = false;
    fmCustView->Caption = "Customers - Unfiltered";
  }


Since I don't know the details about your data set, I can't get much more detailed than that.

One thing to note, since you are putting dates into edit boxes, I would check to make sure those edit boxes have a valid date before applying it to the filter.



James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top