Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combobox separation lines

Status
Not open for further replies.

ck1999

Technical User
Dec 2, 2004
784
0
0
US
I am trying to duplicate something I have seen in a program we use. This was purchased so therefore I cannot see the code.

The program is used as a front end for a database program to allow the user to input orders. When the user enter into certain fields a popup screen appears for the user to select from a predetermined list of options for that field.

The popup screen allows the user to either select an option from a list of choices (filled from th database). Or to add a choice.

It appears to be a combobox. Where there is a dropdown arrow so the user can select an option.

However, this is where the similarity changes. the user can then select the text and edit the text of the option chosen. Then can click on a command button "add" to add this as an option for later if needed be. It does not change the option selected but adds another option.

Also the combobox has seperation lines between each entry.

I do not know if I have explained this well enough or not.

Anyone have any ideas how to duplicate this. Working in VB5.


ck1999

 
A picture would be a great help. What it will come down to is creating your own control and then manipulating things in the on paint event for things like the lines.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
I think it maybe a combobox just not with the dropdownstyle as list.

Here is a picture of what I am trying to achieve.

image.jpg



I have also looked up about increasing the spaces between the items in the list and also about word wrapping and have found not luck on either.

ck1999
 
I have not clue what it is I am trying to mimik it. So any Ideas would be appreciated.

Can a grid control work like a combobox?

ck1999
 
This is the best way I could figure out how to do it. You have to handle it differently if you are pulling the data from a DataSource. Multiple ComboBoxes can use the same code, but each has to have the DrawMode set to OwnerDrawVariable.
Code:
    Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
        Dim cb As ComboBox = CType(sender, ComboBox)

        If cb.DataSource IsNot Nothing Then
            e.DrawBackground()
            e.Graphics.DrawLine(New Pen(Color.Black), e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)
            e.Graphics.DrawString(cb.Items(e.Index).Item(cb.DisplayMember).ToString, e.Font, New SolidBrush(e.ForeColor), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
            e.DrawFocusRectangle()
        Else
            e.DrawBackground()
            e.Graphics.DrawLine(New Pen(Color.Black), e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)
            e.Graphics.DrawString(cb.Items(e.Index).ToString, e.Font, New SolidBrush(e.ForeColor), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
            e.DrawFocusRectangle()
        End If
    End Sub

The "Add" is going to be something totally seperate.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Actually since only one line is different just do it like this.
Code:
    Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem, CB2.DrawItem
        Dim cb As ComboBox = CType(sender, ComboBox)

        e.DrawBackground()
        e.Graphics.DrawLine(New Pen(Color.Black), e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1)

        If cb.DataSource IsNot Nothing Then
            e.Graphics.DrawString(cb.Items(e.Index).Item(cb.DisplayMember).ToString, e.Font, New SolidBrush(e.ForeColor), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
        Else
            e.Graphics.DrawString(cb.Items(e.Index).ToString, e.Font, New SolidBrush(e.ForeColor), New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
        End If

        e.DrawFocusRectangle()
    End Sub

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Sorwen,
I tried your code but it give an error
user-defined type not defined.


Burnie75,
If it is a datagrid how do I get it to drop down, remove the row selector and the scroll bar. I tried DBGrid1.rRowHeadersVisible = False

but get method or datamember not found

So I do not know if this is available in vb5.

ck1999
 
On what line did you get the error?

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
It errors on compiling
at the first line

Private Sub Combo1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs)


Combobox is named combo1
ck1999
 
So if the the ComboBox is called Combo1 the full line should be:
Code:
Private Sub Combo1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Combo1.DrawItem

If it does look like that then I'm not sure as it indicates it is supported by all frameworks. Is anything underlined indicating which part is the actual problem? This is a windows form right? Is it a web form or done with the compact framework? Or did you do this in a class rather than on a form? If that was the case you would have to add a reference to System.Windows.Forms.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
I ended up going with the datagrid even though I liked the idea of the combobx better.

Thanks for all the help.

ck1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top