ComboBox links

D

Dennis D.

Preface: I have viewed the combobox control video at Microsoft.at the
movies.

I want to simulate an HTML combobox as a windows application combobox with 5
to 10 selections in each box.
In the HTML form:
<option value="help.htm">More Info</option>

Thing is: I want to put the URL description "More Info" into the combobox
list, not the URL "help.htm."
URL's have too many characters for a width restricted combobox. Is there a
better way using the IDE?
If not, what programmatic control structure should I use to incorporate the
three subs (noted below) for each linklabel of the combobox? The design
calls for three of these combo boxes positioned in a horizontal row across
the page.

The vb.net code for a single linklabel is:

Private Sub llHelp_LinkClicked(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
llHelp.LinkClicked
Try
VisitHelp()
Catch ex As Exception
MyErrors()
End Try
End Sub
----------------
Sub VisitHelp()
llHelp.LinkVisited = True
System.Diagnostics.Process.Start("help.htm")
End Sub
----------------
Private Sub MyErrors()
MessageBox.Show("The link returned an error message.")
End Sub
========
Not very efficient for use in a combobox with 5 or more selection strings.
 
C

Cor Ligthert

Dennis,

Sorry, however I think that in this way, you get not the answers you could
have got when you wrote clear problems and not as a kind of puzzles.

There is no HTML Combobox.

There is a HTML drowdown and an ASPX dropdownlist.

In a windowform there is a ComboBox.

In this way you will not get much answers in my opinion.

First of all are Combobox problems in my opinion the moist avoided to answer
in this newsgroup.

Second when the message is opened it is opened by Winform persons, and the
Webform persons skip it.

What are you after a webform or a winform application.

Cor
 
D

Dennis D.

If I succeed in creating the winapp control I'll transmit a code snippet.
Sorry, however I think that in this way, you get not the answers you could
have got when you wrote clear problems and not as a kind of puzzles.
D.
 
D

Dennis D.

Ok Cor; As Promised:
This is the skimpy version of a combobox that opens URL's in a browser.
It consists of a combobox and a listbox.
The combobox holds the url description, and the listbox holds the actual
url.
I haven't tested it further than initial construction. Development time: 30
minutes.

Public Class Pulldown
Inherits System.Windows.Forms.Form
Public link As Integer
Public linkUrl As String

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex > 0 Then
link = ComboBox1.SelectedIndex
ListBox1.SelectedIndex = link
linkUrl = ListBox1.Text
makelink(linkUrl)
End If
End Sub
----------------------
Private Sub makelink(ByRef link As String)
System.Diagnostics.Process.Start(linkUrl)
End Sub

End Class
 
D

Dennis D.

And probably throw this in to so the form loads:
Private Sub Pulldown_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub
 
C

Cor Ligthert

Dennis,

I took some time to show you how I would have probably done this.
However first the passing by ref or by value. Try to use forever by value
when you don't want to change that value and be aware that when that value
is an object, it will be changed when you change something inside.
(Therefore you can for a reference type always use a sub and have not return
something)

Because of the fact that a string is immutable it will be passed by a
reference in the value, however you cannot change it inside the routine,
because that refs changes as quick that you change something. (While the
original string stays the same).

The samples.

The first one is what I changed from your sample.
The second one is how I would probably do that when it was my goal (I don't
think it will ever be in this way, however that is not my problem, try them
both because the second one has a much nicer behaviour you can select from
both places).

You can see that I avoided any global variable beside the designer part.

\\\needs one combobox and a listbox
Private Sub Form9_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("Microsoft")
ComboBox1.Items.Add("MSDN")
ListBox1.Items.Add("http:\\www.microsoft.com")
ListBox1.Items.Add("http:\\msdn.microsoft.com")
ComboBox1.SelectedIndex = 0
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) Handles _
ComboBox1.SelectedIndexChanged
ListBox1.SelectedIndex = ComboBox1.SelectedIndex
System.Diagnostics.Process.Start(ListBox1.Text)
End Sub
///
\\\needs one combobox and a listbox
Private Sub Form10_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Text")
dt.Columns.Add("Link")
For i As Integer = 0 To 1
dt.Rows.Add(dt.NewRow)
Next
dt.Rows(0).ItemArray = New Object() _
{"Microsoft", "http:\\www.microsoft.com"}
dt.Rows(1).ItemArray = New Object() _
{"MSDE", "http:\\msdn.microsoft.com"}
ComboBox1.DataSource = dt.DefaultView
ComboBox1.DisplayMember = "Text"
ListBox1.DataSource = dt.DefaultView
ListBox1.DisplayMember = "Link"
ComboBox1.SelectedIndex = -1
ComboBox1.Text = "Select"
AddHandler ComboBox1.SelectedIndexChanged, AddressOf PosChanged
AddHandler ListBox1.SelectedIndexChanged, AddressOf PosChanged
End Sub
Private Sub PosChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs)
Dim dv As DataView = DirectCast(ComboBox1.DataSource, DataView)
Dim cp As Integer = DirectCast(BindingContext(dv),
CurrencyManager).Position
System.Diagnostics.Process.Start(dv(cp)("Link").ToString)
End Sub
///
I hope this helps?

Cor
 
D

Dennis D.

Thank you very much Cor:
Your reply will help in my quest to learn to use the language. I only have
significant time on the weekends, so this type of feedback is immensely
helpful. The project I'm working on is my first vb application, and it is
not psuedo-coded. It is being pieced together when something occurs to me
might be helpful to include. Probably the second version will be much more
structured and better coded as I learn more, especially through examples
like the ones you have provided.

Thanks again.

D.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top