Doing something with a combobox selection

  • Thread starter Thread starter Hogan's Goat
  • Start date Start date
H

Hogan's Goat

Hi, another newbie question here. Believe it or not, I've got something
that's pretty slick in that it gets the name of all running apps and
populates a combobox. What I want to do is test to make sure I can do
something with it, so I just want to put it out to a label I ahve on the
form (this is just for a test, the label won't be in the finished product,
I gess I could use a message box as well).

Here's my code:

Private Sub btnGetIt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGetIt.Click
Dim objProcess As Process
For Each objProcess In System.Diagnostics.Process.GetProcesses
If objProcess.MainWindowTitle <> "" Then
cboProcessesList.Items.Add(objProcess.MainWindowTitle)
End If
Next
lblSelectedApp.Text = cboProcessesList.SelectedText.ToString
End Sub

OK, I know that last line before the End Sub is lame, but I just want to be
able to put the selected app out to a label. I figure, if I can do that I
can do a lot with it. It's late here (after midnight) and I'm low on
ideas.
 
* "Hogan's Goat said:
Hi, another newbie question here. Believe it or not, I've got something
that's pretty slick in that it gets the name of all running apps and
populates a combobox. What I want to do is test to make sure I can do
something with it, so I just want to put it out to a label I ahve on the
form (this is just for a test, the label won't be in the finished product,
I gess I could use a message box as well).

Here's my code:

Private Sub btnGetIt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGetIt.Click
Dim objProcess As Process
For Each objProcess In System.Diagnostics.Process.GetProcesses
If objProcess.MainWindowTitle <> "" Then
cboProcessesList.Items.Add(objProcess.MainWindowTitle)
End If
Next
lblSelectedApp.Text = cboProcessesList.SelectedText.ToString

'SelectedText' returns a 'String', you don't need to call 'ToString'.

Maybe you want to use this code instead:

\\\
lblSelectedApp.Text = cboProcessesList.SelectedItem.ToString()
///
OK, I know that last line before the End Sub is lame, but I just want to be
able to put the selected app out to a label. I figure, if I can do that I
can do a lot with it. It's late here (after midnight) and I'm low on
ideas.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Dilbert's words of wisdom #18: Never argue with an idiot. They drag you down
to their level then beat you with experience.
 
Here's a cheerful little earful from Herfried K. Wagner [MVP]:
'SelectedText' returns a 'String', you don't need to call 'ToString'.

Maybe you want to use this code instead:

\\\
lblSelectedApp.Text = cboProcessesList.SelectedItem.ToString()
///

Thanks, I'm not sure what the difference is but I do see where I screwed
up. I'm changing the label text from the button that retrieves the
process title, when I should be assigning it to an OnChange or OnSelect
event in the combobox. The work flow is this:
- Click the button to get the list of processes to populate the
combobox.
- Click the dropdown to select the process you want.
- Do something with the process (stuff it into a variable, or in this
case send it to a label).

Ja oder nein?
 
Back
Top