Category: listbox

Dec 03 2009

How can I know which item in a mult-select Microsoft Access listbox was clicked?

I have a listbox in a Microsoft Access form. The MultiSelect property is set to simple.

I want to know which item in the listbox was clicked. Keep in mind that an item may be clicked to SELECT or UNSELECT an item.

Is there a simple way to do this? If not is there a complicated way to do this?

I tried to use the SendMessage windows API but no banana because Access controls do not support an hwnd property.

Seth

Sep 24 2009

get object out of telerik radcontrol for winforms binding

Hello,

I hope that someone can help me with an issue related to binding a bindable collection class to one of the Winforms Telerik list controls.

If you bind to a plain ole windows list control like this...

dim list as new listBox

with list
    .DataSource=myCollectionClass  'this contains a collection of widgets.
    .ValueMember="WidgetID"
    .DisplayMember="WidgetName"
end with

I can then get a widget out of the list by doing this...

Dim myWidget as Widget=ctype(list.Items(0),Widget)

If you do the exact same code with for example a Telerik RadListBox (same example as above) but change line one to be

Dim list as new RadListBox.

With RadControls it seems you cannot cast to the Object type directly. Whenever I try this I get the following error...

Unable to cast object of type 'Telerik.WinControls.UI.RadListBoxItem' 
to type 'Widget'.

Can someone at the least confirm that this is a known limitation of Telerik RadControls for Winforms or let me know the proper way to do it.

Thanks. Any help will be appreciated. Any thoughts?

Seth

Sep 11 2009

Can someone tell me how to create a “drag target line” in a winforms listbox that shows whether the drop source is being dropped before or after the drop target

Hello,

I have a user control that is hosting a winforms listbox. I am re-sorting items in the list using drag and drop. I realized that I need a drag "target line" that shows whether I am dropping before or after a target.

Any suggestions. I am open to suggestions. I am not wed to the listbox. I can use another winforms control (the lighter the better) and I am also licensed for winforms telerik controls (a couple of version back). RadListBox does not do the data binding to my biz object correctly so I went with winforms version. But maybe another rad control would give me this out of the box.

For the record, my preference is to stick with the winforms listbox if it can work.

If I need to implement this behaviour myself does anyone have code samples or suggestons on how to do it. I would not have a clue on where to start?

Thanks.

Seth B Spearman

Sep 07 2009

How do you use the Find method with a generic List class to find a specific instance by name

Hello,

I have a system.collections.generic.list(of ListBox)

I would like to use the collection classes built-in Find method to find a particular ListBox by the Name of the Listbox

I found the following MSDN article

http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx

This does not work for me because it does not show how to find a SPECIFIC instance in the collection by the collection name.

The example hard codes the search String of "saurus" into the Find predicate. I want to pass in the search name. When I add a variable I the FindListBox function I created I get an error saying the signature doesn't match.

I know I can add a private method to my own class but now I am curious how to implement the Find in the Generic so I can do this.

Seth

Sep 04 2009

Listbox ClearSelected method leaves items selected

Hello,

I have several winforms listbox controls I am hosting in a user control. The behavior I want in this user control is that I only want ONE of the listboxes to have a selected item at a time.

So if I have an item in Listbox1 selected and I click an item in listbox2 listbox one should be automatically have all items deselected.

I have tried to accomplish this with the following code:

   dim listBox as listbox
   For Each listName As String In _listboxes.Keys
        If listName <> listboxName Then
            listbox = me.controls(listName)
            listbox.ClearSelected()
        End If
    Next

I am storing the names of the listboxes in a dictionary. (The number of listboxes is dynamic). listBoxName in this example is the listbox that was just click so this code avoids clearing the selection in that box.

The behaviour I get when I run this code is very unexpected. Lets say I have 3 listboxes...listbox1, listbox2, and listbox3. Let's say that item3 in listbox2 is currently selected. If I click item 4 of listbox1 then the end result of this is that item four in listbox1 is selected (as expected) but listbox2 has item 1 selected.

In short, the listBox that previously had an item select still has item 1 selected rather than being cleared of selections.

I emitted a debug.print listBox.SelectedItems.Count immediately after the ClearSelection method call and sure enough it says that 1 items is selected.

Any thoughts on how to do this or fix my code?

Seth

EDIT: BTW, I am binding the listboxes to business object collections.

Sep 04 2009

Listbox ClearSelected method leaves items selected

I have several winforms listbox controls I am hosting in a user control. The behavior I want in this user control is that I only want ONE of the listboxes to have a selected item at a time.

So if I have an item in Listbox1 selected and I click an item in listbox2 listbox one should be automatically have all items deselected.

I have tried to accomplish this with the following code:

   dim listBox as listbox
   For Each listName As String In _listboxes.Keys
        If listName <> listboxName Then
            listbox = me.controls(listName)
            listbox.ClearSelected()
        End If
    Next

I am storing the names of the listboxes in a dictionary. (The number of listboxes is dynamic). listBoxName in this example is the listbox that was just click so this code avoids clearing the selection in that box.

The behaviour I get when I run this code is very unexpected. Lets say I have 3 listboxes...listbox1, listbox2, and listbox3. Let's say that item3 in listbox2 is currently selected. If I click item 4 of listbox1 then the end result of this is that item four in listbox1 is selected (as expected) but listbox2 has item 1 selected.

In short, the listBox that previously had an item select still has item 1 selected rather than being cleared of selections.

I emitted a debug.print listBox.SelectedItems.Count immediately after the ClearSelection method call and sure enough it says that 1 items is selected.

Any thoughts on how to do this or fix my code?

Seth

EDIT: BTW, I am binding the listboxes to business object collections.