StrataFrame Forum
Back
Login
Login
Home
»
Updates and Information
»
StrataFrame Users Contributed Samples
»
View images + Text in ComboBox
View images + Text in ComboBox
Post Reply
Like
2
View images + Text in ComboBox
View
Flat Ascending
Flat Descending
Threaded
Options
Subscribe to topic
Print This Topic
RSS Feed
Goto Topics Forum
Author
Message
Mimouni Mohamed
Mimouni Mohamed
posted 11 Years Ago
ANSWER
Post Details
Share Post
Group: StrataFrame Users
Posts: 0,
Visits: 50
Think you very match ben
Reply
Like
2
StrataFrame Team
S
StrataFrame Team
posted 11 Years Ago
ANSWER
Post Details
Share Post
S
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))
Reply
Like
3
Mimouni Mohamed
Mimouni Mohamed
posted 11 Years Ago
ANSWER
Post Details
Share Post
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
.
Reply
Like
3
StrataFrame Team
S
StrataFrame Team
posted 11 Years Ago
ANSWER
Post Details
Share Post
S
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.
Reply
Like
2
Mimouni Mohamed
Mimouni Mohamed
posted 11 Years Ago
ANSWER
Topic Details
Share Topic
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
:
cordially
Mimouni
Reply
Like
2
GO
Merge Selected
Merge into selected topic...
Merge into merge target...
Merge into a specific topic ID...
Open Merge
Post Reply
Like
2
Similar Topics
Post Quoted Reply
Reading This Topic
Login
Login
Remember Me
Reset Password
Resend Validation Email
Login
Explore
Messages
Mentions
Search