View previous topic :: View next topic |
Author |
Message |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Thu Jan 08, 2009 12:35 am Post subject: selecting items in a listBox at creation time |
|
|
Greetings!
I have this listbox,
Code: |
lbox.items.add("zero");
lbox.items.add("3");
lbox.items.add("1");
lbox.items.add("fast!");
lbox.items.add("furious");
lbox.items.add("2");
lbox.items.add("+");
lbox.items.add("-");
lbox.items.add("last");
|
and, let's say that I want to highlight item 2, 5 and 7. I have tried a bunch of code, lbox.items.setSelected(2,true); etc, but nothing works. Will you give me how do I select, or hilight 2, 5 and 7? What I mean by select is that in the creation of the listBox, these items will be already highlighted before the user input.
thanks,
jose |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Thu Jan 08, 2009 8:12 pm Post subject: Re: selecting items in a listBox at creation time |
|
|
I presume you're trying to set the selection right after constructing the Controls. It was a design decision not to have a selection state until the handle is created. A solution is to set the selection in the form's load event. |
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Thu Jan 08, 2009 8:25 pm Post subject: |
|
|
Ok, I will bite: what is the code?
jose |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Fri Jan 09, 2009 7:41 pm Post subject: |
|
|
Code: | /*
Generated by Entice Designer
Entice Designer written by Christopher E. Miller
www.dprogramming.com/entice.php
*/
import dfl.all;
class MyForm: dfl.form.Form
{
// Do not modify or move this block of variables.
//~Entice Designer variables begin here.
dfl.listbox.ListBox listBox1;
//~Entice Designer variables end here.
this()
{
initializeMyForm();
listBox1.items.add("Foo");
listBox1.items.add("Bar");
listBox1.items.add("Baz");
load ~= &form_load;
//@ Other MyForm initialization code here.
}
private void form_load(Object sender, EventArgs ea)
{
listBox1.setSelected(0, true);
listBox1.setSelected(1, false);
listBox1.setSelected(2, true);
}
private void initializeMyForm()
{
// Do not manually modify this function.
//~Entice Designer 0.8.6pre4 code begins here.
//~DFL Form
text = "My Form";
clientSize = dfl.all.Size(292, 273);
//~DFL dfl.listbox.ListBox=listBox1
listBox1 = new dfl.listbox.ListBox();
listBox1.name = "listBox1";
listBox1.selectionMode = dfl.all.SelectionMode.MULTI_EXTENDED;
listBox1.bounds = dfl.all.Rect(0, 0, 120, 95);
listBox1.parent = this;
//~Entice Designer 0.8.6pre4 code ends here.
}
}
int main()
{
int result = 0;
try
{
//Application.enableVisualStyles();
//@ Other application initialization code here.
Application.run(new MyForm());
}
catch(Object o)
{
msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
result = 1;
}
return result;
}
|
|
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Tue Mar 17, 2009 11:46 pm Post subject: |
|
|
Sorry, I thought I thanked you for this. Thanks.
jic |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|