View images + Text in ComboBox


Author
Message
Mimouni Mohamed
Mimouni Mohamed
StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)
Group: StrataFrame Users
Posts: 0, Visits: 50
Hello,

I try to put images + text in a ComboBox.

I tried with a ComboBox DrawItem but it does not work so I searched the internet and I found this code:

    Private Sub Ville_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.LIB_PAYS.DrawMode = DrawMode.OwnerDrawVariable
        Me.LIB_PAYS.DropDownStyle = ComboBoxStyle.DropDownList
    End Sub

    Private Sub LIB_PAYS_DrawItem(sender As Object, e As System.Windows.Forms.DrawItemEventArgs) Handles LIB_PAYS.DrawItem
        If e.Index <> -1 Then
            e.Graphics.DrawImage(Me.ImageList1.Images(e.Index), e.Bounds.Left, e.Bounds.Top)
            e.Graphics.DrawString(Me.LIB_PAYS.Items(e.Index).ToString, _
                                  Me.LIB_PAYS.Font, _
                                  System.Drawing.Brushes.Black, _
                                  New RectangleF(e.Bounds.X + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
            e.DrawFocusRectangle()
        End If
    End Sub

I know that my ComboBox populated with BO



but it still not working so I turn to you to find out how?
is what my code or code that I found wrong?

Here is the result that shows me:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAc4AAABTCAIAAACZC3DOAAAOIUlEQVR4nO2d31cbZRrH58/LOXuzF56zF17thbtSu7pbU1FCLVYt0CIUrArHKC0k1EK3Skmrp3u6qVST5WzWapB4dC2EQGnTrEwmDAxNJufdi/n9M/Mrv+j3c57jiZPMM+Tl9MMz78w8L/W3T2l1nGgY02K86jjCVnFJHycdx2tyXHYUvVYxYx6vO4xZ+vVZ+g2X0SdHrHFErCJuHv0OY06MU27iTTmuOIrTVvGZeQw4jKv0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1jZYEF1TLHT5lKqzzqPH8+sbm+sZmjedd7WgTRtW2e6gBAM8uqXT27ODQzExD1TaSbCertt2DDAB41nGgWmeSVat2rQMol/ey/32IQCAQnRDl8l5vb+/Y2JiZat1IVq3amnuq1Wq1WvWwo0N2d3dzudzi4uLU1NTo6OgIAAC0lqmpqcXFRa1q3Uv21Bz95pxJv9rorfvRW/edFNjBLnij4+DgYGtrK51OJxKJa9euLQAAQGtJJBLpdPr/NvJS365DmQ0AAAAASUVORK5CYII=


cordially
Mimouni

StrataFrame Team
S
StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Doing owner draw overrides all of the formatting logic for the combo box.  When you use the SF list population, we set the DataSource as a DataTable and set the DisplayMember and ValueMember.  The DisplayMember is basically ignored when you turn on owner draw, so you have to do it all manually.

You're really close, but you're problem is here:

 e.Graphics.DrawString(Me.LIB_PAYS.Items(e.Index).ToString, _
                                  Me.LIB_PAYS.Font, _
                                  System.Drawing.Brushes.Black, _
                                  New RectangleF(e.Bounds.X + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))

The items collection is just returning a System.Data.DataRow, and it's ToString() method just returns "System.Data.DataRow".  You need to cast it as a data row, pull your field, then to string the field value:

 e.Graphics.DrawString(CType(Me.LIB_PAYS.Items(e.Index), DataRow)("FieldName").ToString, _
                                  Me.LIB_PAYS.Font, _
                                  System.Drawing.Brushes.Black, _
                                  New RectangleF(e.Bounds.X + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))

Replace "FieldName" with what you need and you should be good to go.


Mimouni Mohamed
Mimouni Mohamed
StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)
Group: StrataFrame Users
Posts: 0, Visits: 50
Ben, thank you for the reply.

I applied your solution, I get an error : Unable to cast object of type 'System.Data.DataRowView' to type 'System.Data.DataRow'.
I changed DataRow and DataRowView by in this case he displays another message : LIB_PAYS is not a DataColumn DataRelation or for the table.


StrataFrame Team
S
StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)StrataFrame Developer (6.3K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You're right, the IListSource.GetList() of the DataTable returns the DataView.  And if you're building the combo box off of the SF list population, we create the table with 2 or 3 values (depending upon whether you have a columns in your drop down):

display | dropdown | value

So, try this:

e.Graphics.DrawString(CType(Me.LIB_PAYS.Items(e.Index), DataRowView)("display").ToString, _
                                  Me.LIB_PAYS.Font, _
                                  System.Drawing.Brushes.Black, _
                                  New RectangleF(e.Bounds.X + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
Mimouni Mohamed
Mimouni Mohamed
StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)StrataFrame Beginner (29 reputation)
Group: StrataFrame Users
Posts: 0, Visits: 50
Think you very match ben
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search