Livedemo checkedlistbox

Stimulsoft Reports.NET discussion
Post Reply
Roelof
Posts: 13
Joined: Fri May 15, 2009 8:15 am
Location: The Netherlands

Livedemo checkedlistbox

Post by Roelof »

I have seen some nice demo's for using a form with a datetimepicker to select the data for a report, but I can't find one for a checkedlistbox.
I am not able to use de information coming from the checkedlistbox for selecting the data in the report.
I want to use the checkedlistbox for selecting the product groups that the user wants to display in the report. Is should be possible to select multiple groups.
How do I use the info from the checkedlistbox in the query?

Thanks for your help.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Livedemo checkedlistbox

Post by Edward »

Hi

Please open the attached report in the Designer.exe application which comes with a standard installation. This report uses NWind.mdb sample MS Access database which is also part of the standard installation.

Thank you.
Roelof
Posts: 13
Joined: Fri May 15, 2009 8:15 am
Location: The Netherlands

Livedemo checkedlistbox

Post by Roelof »

Thanks Edward,

I’m trying to understand what you did, with the “checked items” button you start an event that creates a string (lb.Control.CheckedItems) that contains the ID’s of the checked items.

I can’t see how the checked items influence the report.

You made a checklist with the product names. In the attached file I changed it to the product category. (Changed the data Bindings).

Can you help me to make the report show only the products of the selected categories?
So when I check only Beverages and Seafood I only want the products from these categories in the report. Now it shows all, independent of the selection.

Regards,

Roelof
Attachments
217.CheckedListBoxExample2.mrt
(22.31 KiB) Downloaded 321 times
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Livedemo checkedlistbox

Post by Edward »

Hi Roelof,

Here you are.

Thank you.
Attachments
227.CheckedListBoxExample.mrt
(17.18 KiB) Downloaded 338 times
Roelof
Posts: 13
Joined: Fri May 15, 2009 8:15 am
Location: The Netherlands

Livedemo checkedlistbox

Post by Roelof »

Hi Edward,

Sorry to bother you again but your example does not return the products in the checked categories. It counts the number of categories checked (n) and then returns the products in the first (n) categories.
If you check just one category it always returns category 1 independent of which category you selected. It will never show only the products of category 3.
Roelof
Posts: 13
Joined: Fri May 15, 2009 8:15 am
Location: The Netherlands

Livedemo checkedlistbox

Post by Roelof »

I have googled “cheched listbox databinding” and it looks like something complicated.
I have seen some examples in C# but haven’t been able to apply them in a Stimulsoft report. Probably because I don’t have any experience in C#.

Can anyone help me with a working example?

Thanks,

Roelof
Roelof
Posts: 13
Joined: Fri May 15, 2009 8:15 am
Location: The Netherlands

Livedemo checkedlistbox

Post by Roelof »

Just in case anyone reads this thread looking for a working example.

I’m not a programmer so there might be better ways to do it but it works.

This is how:
The CheckedListBox has an “Selected Item Changed” event that creates a string with the selected ID’s.
The OK button has an event that selects the products in the selected categories.
Attachments
225.CheckedListBoxExample07-09-09.mrt
(15.37 KiB) Downloaded 255 times
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Livedemo checkedlistbox

Post by Edward »

Hi Roelof,

Thank you for your tips :)

You are right, it was a mistake in the previous implementation of Button Click event.

Here is the right code:

Code: Select all

MyVariable = "";
for (int i=0;i<lb.Control.CheckedItems.Count;i++)
{
if (MyVariable == "") 
{
MyVariable = " where CategoryID in (";
MyVariable += Category.GetData("CategoryID",lb.Control.Items.IndexOf(lb.Control.CheckedItems[i]));
}
else
{
MyVariable += "," + Category.GetData("CategoryID",lb.Control.Items.IndexOf(lb.Control.CheckedItems[i]));
}
}
if (MyVariable != "")
{
MyVariable += ")";
}
//MessageBox.Show(MyVariable);
if (MyVariable == "") MyVariable = " where false";
Products.Connect();
Your solution is nice and simple, but the only problem with it that it always select values which were selected and then deselected again.

Anyway thank you for explanation and this another idea of implementing of that method.

Thank you.
Attachments
226.CheckedListBoxExample.mrt
(17.18 KiB) Downloaded 355 times
Roelof
Posts: 13
Joined: Fri May 15, 2009 8:15 am
Location: The Netherlands

Livedemo checkedlistbox

Post by Roelof »

Hi Edward,

You are right, your solution works better.

Thanks.
Post Reply