FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

selecting items in a listBox at creation time

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Thu Jan 08, 2009 12:35 am    Post subject: selecting items in a listBox at creation time Reply with quote

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
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Jan 08, 2009 8:12 pm    Post subject: Re: selecting items in a listBox at creation time Reply with quote

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
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Thu Jan 08, 2009 8:25 pm    Post subject: Reply with quote

Ok, I will bite: what is the code? Smile

jose
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Jan 09, 2009 7:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Tue Mar 17, 2009 11:46 pm    Post subject: Reply with quote

Sorry, I thought I thanked you for this. Thanks.

jic
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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