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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi Check Boxes 1

Status
Not open for further replies.

admdev

Programmer
May 17, 2006
56
0
0
US
Hi all,

Hope somebody can help.

I am building an application, which has a list box populated with records from a database. The list has only one column. Now, what I want to do is build the same list but create a group of check boxes. In other words, a check box per database record. I already tried by adding the check box to the listbox, but I want to build check boxes instead. I am planning to add the check boxes to a control.

So if I have A,B,C,D, etc. in my database, I will have check boxes labeled A,B,C,D, etc.

Thanks in advance.
 


Here is one way of doing that (if I understood you correctly).

You can SQL-select the table field you use for your listbox, along with a new field of logical type, into a new table, cursor, or array.

Then you can use those two columns to populate your listbox (or you can use a grid instead). You can add a checkbox into the listbox or grid to represent your logical field. So you will have a checkbox for every record, and A,B,C,D etc. will serve as checkbox labels.

Does it sound like what you need?
 
I am not sure I understand what you mean by "build" checkboxes. Can you explain further?

pamela
 
Thanks for the replay guys.

What I am trying to do is add check box objects to a form or control based on the number of records I select from the database table.

Stella740pl- what you suggested with the grid sounds like a good option. How do I add the check box to the grid. I remember I did this a long time a go, but do not remember how I did it.

Thanks.
 
Admdev,

I'm not sure I understand you either. However, in general, you can't add checkboxes to listboxes. They are two separate controls. The nearest you can get is to use graphics to simulate the checkbox: one image for a "ticked" checkbox and another for an empty one.

However, you can add checkboxes to grids (as per Stella's reply). You can also put them in listviews.

But I don't know what you mean by "groups of checkboxes". Are you talking about some sort of hierarchical list? In that case, a treeview might be a good option.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
What I am trying to do is add check box objects to a form or control based on the number of records I select from the database table.

If you are trying to create Checkboxes on the fly based upon the number of Records selected, i.e. 100 records selected, 100 checkboxes created. This involves programming, more to do with placement on a form, than to create. May not be a good idea.

Grid is better. If using VFP9 (I think it was also in VFP8) use Cast() to create Logical fields. i.e. select custid, cast(custid as L) as lcustid, ..... from customer. Now use this cursor as your recordsource.

To add a checkbox to a grid column. Select the default Textbox in the column, click delete, then click Checkbox in form designer, then click the column. This will add the checkbox to the column. i.e.
Grid edit->column->textbox->delete->click checkbox in toolbar->click column
 


Hi Mike, and thanks.

However, in general, you can't add checkboxes to listboxes.

I didn't do this for a while, so I was not sure, but was under impression that checkboxes can be added to listboxes, too (but I do remember for sure that they can be added to grids).


admdev,

How do I add the check box to the grid.
Imaginecorp just beat me to it.
 
Stella,

Haven't seen you here for a while. I hope that means you are good and busy.

You are right about checkboxes and grids. But grids are containers, listboxes aren't. The only thing they can "contain" is text and images (at least, that's what I've always understood).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
However, in general, you can't add checkboxes to listboxes.

Yes and No. No: Not true checkboxes like you can to a grid, Yes: a "representation" of a checkbox before the Prompt, (similar to a Treeview). Though I have never done it as its a PIA, there was an article in MSDN on how to do it

Imaginecorp just beat me to it.
Sorry...
 
Imaginecorp,

a "representation" of a checkbox before the Prompt,

Do you mean using a pair of images to represent a ticked and an un-ticked checkbox respectively? That was what I was referring to in the my first message in this thread.

I've never tried to do it either, but I imagine it wouldn't look great.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 

Hi Mike,

Yes, I was not here for a while (I did log in quite often, but I was only reading some threads), and was on a leave from work, also. Now I am back to work - and to Tek-Tips, too, catching up with both.

But yes, I am good and busy, I was just busy with different things. As a matter of fact, I was on maternity leave.

Imaginecorp,

Yes and No. No: Not true checkboxes like you can to a grid, Yes: a "representation" of a checkbox before the Prompt, (similar to a Treeview). Though I have never done it as its a PIA, there was an article in MSDN on how to do it.

Isn't it what Mike mentioned about using graphics to simulate the checkbox? Or you mean something different?

Sorry...

You shouldn't be. I am even glad you responded faster to that one - I needed a few minutes to refresh my memory, and I didn't have them.
 
Stella: Yes, Mike beat me to it.

Mike: Yes, (graphics) and it definately looks kludgy, I tried it once as a test and the coding etc was definately not worth the effort. I do not remember, but I think it was also a sample in VFP6 or 7
 
Thanks guys for the reply.

I tried the image on the list some time ago, and it looked fine only to certain extent.

I will be trying the check box on the grid.

Thanks.
 
Hi all,

I am just getting back to this project as I was assigned to a different one.

I added the check box on the grid; however, when I click on it, it does not become checked.

I am using a cursor as the recordsource for the grid. The field assigned to the check box is numeric and I am setting it to zero when creating the cursor.

Thanks.
 

Numeric should be fine.

Is the cursor you use as a recordsource writable or read-only? How do you create it?

When you click on the cursor, you are trying to write into it, to change the value of your checkbox field. If it is read-only, that might be the reason of your problem.
 
I added the check box on the grid; however, when I click on it, it does not become checked.

I am using a cursor as the recordsource for the grid. The field assigned to the check box is numeric and I am setting it to zero when creating the cursor.

Are you sure you removed the original textbox from grid's column? Did you set sparse property of the column to .f.?

Also, you're right, I noticed myself that not every click on a checkbox in a grid changes its status correctly. I had to add this.value = this.value in checkbox.click event to overcome the problem.

Also, you can add a Checkbox to a Listbox, there is a sample at
 
Markros:

Also, you can add a Checkbox to a Listbox, there is a sample
This is not a real checkbox but a graphic, Definately not worth the coding... A grid works better.
 
I prefer to use grid as well, I just know about this KB, so I posted it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top