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
("WindowsApplic ation1+ListItem s")... What's wrong? The source code is below.
Thanks in advance!
Best regards,
HKSHK
#Region "ComboBoxVB 6"
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.ToStrin g
End Get
Set(ByVal Value As String)
Me.Item = Value
End Set
End Property
Public Overridable Shadows Function ToString() As String
Return Me.Item.ToStrin g
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(ind ex)) Is ListItems Then
Dim t As ListItems
t = Items.Item(inde x)
Return t.ItemData
Else
Return 0
End If
End Get
Set(ByVal Value As Long)
If TypeOf (Items.Item(ind ex)) Is ListItems Then
Dim t As ListItems
t = Items.Item(inde x)
t.ItemData = Value
Items.Item(inde x) = t
Else
Dim t As New ListItems(Items .Item(index), Value)
Items.Item(inde x) = t
End If
End Set
End Property
Public Sub New()
Me.DrawMode = DrawMode.OwnerD rawFixed
End Sub
Protected Overrides Sub OnDrawItem(ByVa l e As
System.Windows. Forms.DrawItemE ventArgs)
'draw background & focus rect
e.DrawBackgroun d()
e.DrawFocusRect angle()
'check if it is an item from the ListItems collection
If e.Index < 0 Then
'not an item, draw the text (indented)
e.Graphics.Draw String(Me.Text, e.Font, New SolidBrush(e.Fo reColor),
e.Bounds.Left, e.Bounds.Top)
Else
'check if item is a ListItems item
If TypeOf (Me.Items(e.Ind ex)) Is ListItems Then
'get item to draw
Dim item As ListItems = Me.Items(e.Inde x)
' draw text
e.Graphics.Draw String(item.Tex t, Font, New
SolidBrush(e.Fo reColor), e.Bounds.Left, e.Bounds.Top)
Else
' it is not an ListItems item, draw it
e.Graphics.Draw String(Me.Items (e.Index).ToStr ing(), e.Font, New
SolidBrush(e.Fo reColor), e.Bounds.Left, e.Bounds.Top)
End If
MyBase.OnDrawIt em(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 1324
Probably beacuse you're shadowing the ToString method in the ListItems
class. Try overriding it instead
/claes
"HKSHK" <hk***@gmx.ne t> wrote in message
news:44******** *************** @news.freenet.d e... 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 ("WindowsApplic ation1+ListItem s")... What's wrong? The source code is below.
Thanks in advance!
Best regards,
HKSHK
#Region "ComboBoxVB 6" 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.ToStrin g End Get Set(ByVal Value As String) Me.Item = Value End Set End Property
Public Overridable Shadows Function ToString() As String Return Me.Item.ToStrin g 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(ind ex)) Is ListItems Then Dim t As ListItems t = Items.Item(inde x) Return t.ItemData Else Return 0 End If End Get Set(ByVal Value As Long) If TypeOf (Items.Item(ind ex)) Is ListItems Then Dim t As ListItems t = Items.Item(inde x) t.ItemData = Value Items.Item(inde x) = t Else Dim t As New ListItems(Items .Item(index), Value) Items.Item(inde x) = t End If End Set End Property
Public Sub New() Me.DrawMode = DrawMode.OwnerD rawFixed End Sub
Protected Overrides Sub OnDrawItem(ByVa l e As System.Windows. Forms.DrawItemE ventArgs) 'draw background & focus rect e.DrawBackgroun d() e.DrawFocusRect angle()
'check if it is an item from the ListItems collection If e.Index < 0 Then 'not an item, draw the text (indented) e.Graphics.Draw String(Me.Text, e.Font, New SolidBrush(e.Fo reColor), e.Bounds.Left, e.Bounds.Top) Else 'check if item is a ListItems item
If TypeOf (Me.Items(e.Ind ex)) Is ListItems Then
'get item to draw Dim item As ListItems = Me.Items(e.Inde x)
' draw text e.Graphics.Draw String(item.Tex t, Font, New SolidBrush(e.Fo reColor), e.Bounds.Left, e.Bounds.Top)
Else ' it is not an ListItems item, draw it e.Graphics.Draw String(Me.Items (e.Index).ToStr ing(), e.Font, New SolidBrush(e.Fo reColor), e.Bounds.Left, e.Bounds.Top) End If
MyBase.OnDrawIt em(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 can't
get this to work in any browser on a Mac, though it works alright on a
PC. What am I missing?
|
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 be really grateful for any assistance!
Thanks
|
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 the drop down box to go back to
what the value was before the user tried to change it, but at that point I
will not know what the original value was. Or is there a drop down control
"revert" method, or is there any way of knowing what the original...
|
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 moveItem = lv.SelectedItems;
selIdx = moveItem.Index;
// ignore movedown of last item
|
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:
self.fonts=list(tkFont.families())
self.fonts.sort()
for item in self.fonts:
self.fontlist.insert(END, item) #self.fontlist is the
| |
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 new seek item in the textbox after I searched for an item
and click the seek button.. it seems it is doing nothing.
And also... what code can I use to genereate a messagebox message when a
seek item is not at all in the CSV file?
|
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 extra item
just doesn't get added to the DropDownList:
=============================================
<script runat="server">
Sub Page_Load(..........)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
|
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: 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |