Help with creating custom ComboBox

D

David Clegg

I need to be able to change many attributes on a ComboBox (e.g
background and border colour), and as this isn't currently supported by
the native framework ComboBox, I've attempted a quick and dirty
implementation myself. I know .NET CF Service Pack 2 improves the
situation somewhat, is still not flexible enough for our needs.

Because I didn't want to re-invent the wheel, I thought it would be
easiest to descend from Control, paint the textbox and drop down arrow
portion myself, and use an internal ListBox (actually ListBoxEx from
SmartDeviceFramework to be precise) for the drop down list. The listbox
is shown or hidden depending on the what the combobox dropdown state
should be. I also delegate any public combobox properties, methods and
events to the internal listbox (although I've currently only
implemented the ones our app directly accesses).

I thought I had this custom combobox nailed, but yesterday discovered I
have problems with the listbox only painting within the confines of
it's parent control. For example, if the combobox is on a panel the
listbox will not paint beyond the bounds of the panel, whereas a
standard combobox dropdown list would.

Is there an easier way to achieve my goal?

I can post my compete combobox implementation if it will help to see
the error in my ways, but it will have to come with a huge "Ugly Code"
disclaimer :)

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"When I first heard that Marge was joining the police academy, I
thought it would be fun and zany, like that movie -- Spaceballs. But
instead it was dark and disturbing like that movie, Police Academy." -
Homer Simpson
 
R

rish

David,

I actually built something very similar specifically for the purpose of
emulating the dropdown on the Pocket PC's File Explorer (background color,
decorating image to sit beside the text, listbox or tree dropdown, floating
down arrow, etc).
The problem you are experiencing can be solved this way:

protected void ShowDropdown()
{
if(!combo_label_control.TopLevelControl.Controls.Contains(combo_list_control))
{
combo_label_control.TopLevelControl.Controls.Add(combo_list_control);
}
combo_list_control.BringToFront();
combo_list_control.Show();
}

protected void HideDropdown()
{
if(combo_label_control.TopLevelControl.Controls.Contains(combo_list_control)
{
combo_label_control.TopLevelControl.Controls.Remove(combo_list_control);
}
}

rish
 
D

David Clegg

rish said:
The problem you are experiencing can be solved this way:

Thanks, that solves the problem nicely. One question though. Why do you
remove the control when hiding the list, rather than setting its
..Visible property? Is it more efficient that way?

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Marge, it takes two people to lie. One to lie and one to listen." -
Homer Simpson
 
R

rish

David,

Depending upon your viewpoint, the list does not belong to the top-level
control. It is a matter of semantics. The need to push the list to the
top-level control is to make it float above the rest not because it is
really the top-level control's immediate subordinate.There are arguments
that could be made to either side and in all cases since the label for the
dropdown is (undoubtedly) tracking the list control it really doesn't
matter.

Certainly from a standpoint of reducing the sheer number of operations it
makes sense. Just be mindful of any "blind" operations done to the
top-level control immediate subordinate level of controls, you could end up
netting the list when you don't mean to.

rish

PS.
The HideDropdown method should have also had a call to the Visibility
property or the Hide method. This typo will become evident immediately if
you are electing to leave it in the Controls collection.
 
D

David Clegg

Thanks for the explanation, and for the help.

So far my new and improved custom combobox seems to be holding up to
the rigours of its little CF inhabited world, and is mostly behaving as
expected (a couple of minor niggles to work out, but nothing I can't
handle).

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Oh, yeah, what are you gonna do? Release the dogs? Or the bees? Or the
dogs with bees in their mouth and when they bark, they shoot bees at
you?" - Homer Simpson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top