Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Go Back  Xtreme Visual Basic Talk > > > Reinventing (and drawing) the ComboBox


Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2012, 09:14 AM
NFITC1 NFITC1 is offline
Centurion
 
Join Date: Apr 2006
Posts: 102
Default Reinventing (and drawing) the ComboBox


I'm trying to make a custom combobox from scratch that multiple instances will share the listbox that holds the data on. I'm trying to draw the button face manually using GraphicsPaths and pens and brushes, but I'm having a few issues with it:

1. How do you draw that down arrow glyph in a way that doesn't look like a two-year-old sneezed on it? I'm having problems with the shape looking like the traditional one.

2. How do you position the listbox that contains the data in such a way that isn't bound by the containing form's render window?

3. I've tried to make the background look different when it has focus, but the OnPaint seems to think it always has focus and always makes the background the "focused control" background.

Is that making enough sense?
Reply With Quote
  #2  
Old 04-10-2012, 09:45 AM
DrPunk's Avatar
DrPunkReinventing (and drawing) the ComboBox DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

Quote:
that multiple instances will share the listbox that holds the data on
It would be much much easier to share a single datasource across controls.

What is it exactly that you're trying to achieve? Because I imagine there's a much easier way (unless you just want a control to look "funky"). As your questions suggest, making your own combobox isn't easy.
__________________
There are no computers in heaven!
Reply With Quote
  #3  
Old 04-10-2012, 10:10 AM
NFITC1 NFITC1 is offline
Centurion
 
Join Date: Apr 2006
Posts: 102
Default

Quote:
Originally Posted by DrPunk View Post
It would be much much easier to share a single datasource across controls.

What is it exactly that you're trying to achieve? Because I imagine there's a much easier way (unless you just want a control to look "funky").
I could share the datasource, but there's still 32 comboboxes that have to populate 32 different lists with 800 entries each. Since these 800 entries are all the same it would be more efficient to have one list that they all got the data from.

I've never had great luck with datasources. I have a List(Of String) as a datasource for these combos and if that gets changed the combos' entries don't reflect that. So I have to reassign the datasource which means waiting while 32 separate listboxes get repopulated.

I've been over this in multiple threads and that really is what has to happen.
Reply With Quote
  #4  
Old 04-10-2012, 10:16 AM
DrPunk's Avatar
DrPunkReinventing (and drawing) the ComboBox DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

Fair enough.

That just leads me on to question whether comboboxes are the best control to use here. 800 entries in a combobox makes scrolling the list of items a chore. So what's the purpose of having all the items in a combobox?
__________________
There are no computers in heaven!
Reply With Quote
  #5  
Old 04-10-2012, 10:39 AM
DrPunk's Avatar
DrPunkReinventing (and drawing) the ComboBox DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

The code below sets up one source and puts that in two comboboxes.

When the form loads it puts the numbers 1 to 100 in the list. The new bindingcontext bit is so that the selection is different in both comboboxes.

Using a BindingList means that when you click the button the new entry is automatically put into the comboboxes. Any changes to the list are automatically reflected in the comboboxes.
Code:
    Dim col As New System.ComponentModel.BindingList(Of String)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        For i = 1 To 100
            col.Add(i.ToString)
        Next

        ComboBox1.BindingContext = New BindingContext
        ComboBox2.BindingContext = New BindingContext

        ComboBox1.DataSource = col
        ComboBox2.DataSource = col
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        col.Add("New entry")
    End Sub
__________________
There are no computers in heaven!

Last edited by DrPunk; 04-10-2012 at 10:59 AM.
Reply With Quote
  #6  
Old 04-11-2012, 11:10 PM
hDC_0Reinventing (and drawing) the ComboBox hDC_0 is offline
Contributor

* Expert *
 
Join Date: Feb 2004
Posts: 559
Default Ownerdrawn Combobox and cascading combobox group

Before this thread wanders too far astray I want to address the question in the first post:
Quote:
How do you draw that down arrow glyph in a way that doesn't look like a two-year-old sneezed on it..
You probably need to use "ButtonRenderer.DrawButton".
Check out his (possibly helpful) code:
Code:
'to set up for ownerdrawn combobox arrow
Private _ButtonArea as New Rectangle
Public Sub New()
  ' This call is required by the designer.
  InitializeComponent()
  ' Add any initialization after the InitializeComponent() call.
  MyBase.SetStyle(ControlStyles.Opaque Or ControlStyles.UserPaint, True)
  MyBase.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
  MyBase.DropDownStyle = ComboBoxStyle.DropDownList
  ' Cache the button's modified ClientRectangle (see Note)
  With _ButtonArea
    .X = Me.ClientRectangle.X - 1
    .Y = Me.ClientRectangle.Y - 1
    .Width = Me.ClientRectangle.Width + 2
    .Height = Me.ClientRectangle.Height + 2
  End With
End Sub
'then hook into the OnPaint event:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  If Me.DroppedDown Then
    ButtonRenderer.DrawButton(Me.CreateGraphics, _
        ButtonArea, VisualStyles.PushButtonState.Pressed)
  Else
    ButtonRenderer.DrawButton(Me.CreateGraphics, _
        ButtonArea, VisualStyles.PushButtonState.Normal)
  End If
..this is basic ownerdrawn controls stuff from here.

Now, continuing with the other "fork" that we are onto now.

There's talk of "32 comboboxes that have to populate 32 different lists with 800 entries each"!
Owww! Pity the poor user who comes across any such ui!
You don't just have a hooking-data-source-into-controls issue you definitely have a user interface issue.

What you may be trying to do is something like cascading combobox selection (or on webpages it's know as a "cascading dropdowns").
Here is a very simple example (they can get very complex with "branching" to different auto-populated drop down lists requiring some involved business layer logic).

Here's my user interface advice (which may help with the data source linking as well):
Narrow the choice depth and/or initial selection number.

This can be done in a variety of ways but they all require re-thinking the user interface keeping the set of "typical users" in mind.

First of all are their "categories" of users?
(each of whom might have a particular searching pattern, or usage pattern).

Like for a supermarket shopper - Is this someone who is a vegan? a strictly organic person?
a cost conscious shopper or a pre-packaged convenience food shopper?
Each categorization will reduce the amount of supermarket product indices that have to be crawled through.

Many dataset "refining" control-based interfaces have "basic" and "advanced" forms/pages.
Let the basic interface have a whole bunch of "pre-sets" with a limited number of alternate options.

Then for the advanced page I would use a customized treeview control or advanced treeview control (1, 2) with collapsible sections.
Try to split those 800 items list into categories, which become one-level-up collapsible, section-ized sub-lists.

Anyway there are many ways help the user "visual parse" a set cascading selections
rather than just throwing lots of combobox controls at him/her.

It's just intimidating and unnecessary if you think a little about
how to arrange things better..

Last edited by hDC_0; 04-11-2012 at 11:28 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
 
Reinventing (and drawing) the ComboBox
Reinventing (and drawing) the ComboBox
 
-->