Hi guys,
I have a problem with the combo box I'm writing on.
What I want is custom items, which are fine so far, but when I select
one the combo box shows the project name
("WindowsApplication1+ListItems")... What's wrong? The source code is below.
Thanks in advance!
Best regards,
HKSHK
#Region "ComboBoxVB6"
Public Class ComboBoxVB6
Inherits System.Windows.Forms.ComboBox
Public Class ListItems
Public Item As Object
Public ItemData As Long
Public Sub New(ByVal Item As Object, ByVal ItemData As Long)
Me.Item = Item
Me.ItemData = ItemData
End Sub
Public Property Text() As String
Get
Return Me.Item.ToString
End Get
Set(ByVal Value As String)
Me.Item = Value
End Set
End Property
Public Overridable Shadows Function ToString() As String
Return Me.Item.ToString
End Function
End Class
Public Function AddItem(ByVal item As Object) As Integer
Return AddItem(item, 0)
End Function
Public Function AddItem(ByVal Item As Object, ByVal ItemData As Long) As
Integer
Dim t As New ListItems(Item, ItemData)
Return Items.Add(t)
End Function
Public Property ItemData(ByVal index As Integer) As Long
Get
If TypeOf (Items.Item(index)) Is ListItems Then
Dim t As ListItems
t = Items.Item(index)
Return t.ItemData
Else
Return 0
End If
End Get
Set(ByVal Value As Long)
If TypeOf (Items.Item(index)) Is ListItems Then
Dim t As ListItems
t = Items.Item(index)
t.ItemData = Value
Items.Item(index) = t
Else
Dim t As New ListItems(Items.Item(index), Value)
Items.Item(index) = t
End If
End Set
End Property
Public Sub New()
Me.DrawMode = DrawMode.OwnerDrawFixed
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As
System.Windows.Forms.DrawItemEventArgs)
'draw background & focus rect
e.DrawBackground()
e.DrawFocusRectangle()
'check if it is an item from the ListItems collection
If e.Index < 0 Then
'not an item, draw the text (indented)
e.Graphics.DrawString(Me.Text, e.Font, New SolidBrush(e.ForeColor),
e.Bounds.Left, e.Bounds.Top)
Else
'check if item is a ListItems item
If TypeOf (Me.Items(e.Index)) Is ListItems Then
'get item to draw
Dim item As ListItems = Me.Items(e.Index)
' draw text
e.Graphics.DrawString(item.Text, Font, New
SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top)
Else
' it is not an ListItems item, draw it
e.Graphics.DrawString(Me.Items(e.Index).ToString() , e.Font, New
SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top)
End If
MyBase.OnDrawItem(e)
End If
End Sub
Public Overrides Function ToString() As String
Dim t As ListItems
t = SelectedItem
Return t.ToString
End Function
End Class
#End Region 1 1309
Probably beacuse you're shadowing the ToString method in the ListItems
class. Try overriding it instead
/claes
"HKSHK" <hk***@gmx.net> wrote in message
news:44***********************@news.freenet.de... Hi guys,
I have a problem with the combo box I'm writing on. What I want is custom items, which are fine so far, but when I select one the combo box shows the project name ("WindowsApplication1+ListItems")... What's wrong? The source code is below.
Thanks in advance!
Best regards,
HKSHK
#Region "ComboBoxVB6" Public Class ComboBoxVB6 Inherits System.Windows.Forms.ComboBox
Public Class ListItems Public Item As Object Public ItemData As Long
Public Sub New(ByVal Item As Object, ByVal ItemData As Long) Me.Item = Item Me.ItemData = ItemData End Sub
Public Property Text() As String Get Return Me.Item.ToString End Get Set(ByVal Value As String) Me.Item = Value End Set End Property
Public Overridable Shadows Function ToString() As String Return Me.Item.ToString End Function End Class
Public Function AddItem(ByVal item As Object) As Integer Return AddItem(item, 0) End Function Public Function AddItem(ByVal Item As Object, ByVal ItemData As Long) As Integer Dim t As New ListItems(Item, ItemData) Return Items.Add(t) End Function
Public Property ItemData(ByVal index As Integer) As Long Get If TypeOf (Items.Item(index)) Is ListItems Then Dim t As ListItems t = Items.Item(index) Return t.ItemData Else Return 0 End If End Get Set(ByVal Value As Long) If TypeOf (Items.Item(index)) Is ListItems Then Dim t As ListItems t = Items.Item(index) t.ItemData = Value Items.Item(index) = t Else Dim t As New ListItems(Items.Item(index), Value) Items.Item(index) = t End If End Set End Property
Public Sub New() Me.DrawMode = DrawMode.OwnerDrawFixed End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs) 'draw background & focus rect e.DrawBackground() e.DrawFocusRectangle()
'check if it is an item from the ListItems collection If e.Index < 0 Then 'not an item, draw the text (indented) e.Graphics.DrawString(Me.Text, e.Font, New SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top) Else 'check if item is a ListItems item
If TypeOf (Me.Items(e.Index)) Is ListItems Then
'get item to draw Dim item As ListItems = Me.Items(e.Index)
' draw text e.Graphics.DrawString(item.Text, Font, New SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top)
Else ' it is not an ListItems item, draw it e.Graphics.DrawString(Me.Items(e.Index).ToString() , e.Font, New SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top) End If
MyBase.OnDrawItem(e) End If
End Sub
Public Overrides Function ToString() As String Dim t As ListItems t = SelectedItem
Return t.ToString End Function
End Class #End Region This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lkrubner |
last post by:
I've got a function, you can see it below, that is being called
onmouseup in the textarea on my main form. The idea is to find a
selection if possible and store that text in a global variable. I...
|
by: Tim::.. |
last post by:
Can someone please tell me how I go about preselecting an item in a drop
drown list when I click the Edit Command in a datagrid?
I have tried the following but it doesn't work for me!
I would...
|
by: John Walker |
last post by:
Hi,
On an ASP.NET page I have a drop down list control. When the user pulls
down the list and makes a selection, I perform validation, and if the
validation fails I want the selected item in...
|
by: Michael Meckelein |
last post by:
Hello,
I run into trouble move down a selected item in a listbox. The code moving
down the item is the following one:
for (int j = lv.SelectedItems.Count-1; j >=0; j--)
{
ListViewItem...
|
by: Kevin Walzer |
last post by:
I'm trying to set the active item in a Tkinter listbox to my
application's currently-defined default font.
Here's how I get the fonts loaded into the listbox:
...
|
by: Ray |
last post by:
Hello World,
I made a Windowsform that reads data from a CSV file.
It works fine, but when I have read the data of a record I have to re-Debug
the form to read another record.
So when I put a...
|
by: rn5a |
last post by:
I am binding a DropDownList with records existing in a database table.
I want to add an extra item *SELECT COMPANY* at index 0 so that by
default, it gets selected. This is how I tried it but the...
|
by: coldfusionstudent |
last post by:
i wish to show/appear and dissappear text box based on a the drop down item selected.
what do i have to add?
thanks
under Comm_DEV
drop down selection.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |