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

DFL multiple selection ListBox question

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



Joined: 26 Sep 2005
Posts: 6

PostPosted: Mon Sep 26, 2005 9:03 pm    Post subject: DFL multiple selection ListBox question Reply with quote

Hi,

I've been using DFL for a little while now, I even managed to build a system-tray client for a Java server Smile, and it works really well.

However I've come across a weird problem I just can't figure out, either by experimenting, looking at existing code or web searching.

I have a need to present a list of items and have the user choose a number of them, I then do some ODBC'ing to SQL Server (which I've got working) depending on what's selected.
The trouble is, I can't seem to get the 'multple selection' thing behaving.

(Apologies for the length of the sample code, I can't reduce it too much more without it becoming more confusing)

Code:

import std.string;

import dfl.all;

class LBTestForm: Form
{
   ListBox the_list;
   Button the_button;
   Font the_font;
   
   this()
   {
      startPosition = FormStartPosition.CENTER_SCREEN;
      formBorderStyle = FormBorderStyle.FIXED_DIALOG;
      width =250;
      height = 200;
            
      maximizeBox = false;
      text = "ListBox Test";
      the_font = new Font("Arial", 12);
      
      with (the_list = new ListBox)
      {
         bounds = Rect(10, 10, 200, 100);
         selectionMode = SelectionMode.MULTI_SIMPLE;
         font = the_font;
         parent = this;
         items.add("First thing in the list");
         items.add("then there's this one");
         items.add("oh, and one more");
         items.add("last one, I promise");
      }
      
      with (the_button = new Button)
      {
         bounds = Rect(10, the_list.bottom + 10, 90, 30);
         text = "List Info";
         font = the_font;
         parent = this;
         click ~= &button_click;
      }
      
   }
   
   private void button_click(Object sender, EventArgs ea)
   {
      int num_possible = the_list.items.count;
      msgBox("Number of items\nin the list: " ~ std.string.toString(num_possible));
      
      int num_selected = the_list.selectedItems.count;
      msgBox("Number of items\nselected: " ~ std.string.toString(num_selected));
   }
   
}

int main(char[][] args)
{
   Application.run(new LBTestForm);
   return (0);
}



I suspect I'm doing something wrong in terms of the 'selectedItems' property.

You'll see one message box pop up saying there are 4 items in the list, which is correct, then I get a 'Stack Overflow' message.
Whenever I try to access the 'selectedItems' or 'selectedIndicies' properites, it falls over.

I've had a look in the 'listview.d' example and both the 'listview.d' and 'listbox.d' DFL source files, and I think 'selectedItems' is the correct thing to use but it's hard to tell.

I'm using the Sept 10 snapshot, with a rebuilt 'dfl.lib' without the '-debug' flags, with DMD 0.131.
Just in case that was adding to the error, I rebuilt both the DFL library and my listbox tester with -'debug', but no joy.

Can anyone see what I'm doing wrong in regard to getting multiple selections from a ListBox control?

Thanks in advance.
_________________
- Brendon -
Back to top
View user's profile Send private message
Chris Miller



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

PostPosted: Tue Sep 27, 2005 7:14 am    Post subject: Reply with quote

It was a bug in DFL's ListBox.selectedItems.count, fixed in snapshot 20050927. Thanks for letting me know about it.
Back to top
View user's profile Send private message
Portis



Joined: 26 Sep 2005
Posts: 6

PostPosted: Tue Sep 27, 2005 12:59 pm    Post subject: Reply with quote

Thanks for sorting out the fix so quickly.

I've just rebuild the test case and it works just fine. Smile

I'm now able to use 'selectedItems' and iterate through the choices selected in a multi-selction ListBox.
Code:

if (the_list.selectedItems.count > 0)
{
   char[] selected_msg = "You selected:\n";
   foreach (char[] selected_item; the_list.selectedItems)
      selected_msg ~= "* '" ~ selected_item ~ "'\n";
   msgBox(selected_msg);
}

Thank you.
Very Happy
_________________
- Brendon -
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