Jump to content

Listview click

- - - - -

  • Please log in to reply
22 replies to this topic

#1
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
Hi

Once again, I'm here about a question about Listview's.

This once should be pretty simple, I need some way of being able to click on a value in the listview, and the 2 following things happen.

1) The value in the Listview is added to a textbox.

2) A function can be added such as hiding a window.

Cheers.
Francis.

#2
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
check out the selectedindexchanged event.

#3
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
I've just tryed it, though not quite sure what to do.

I need the selected value from the Listview to be added to a Textbox. When I do this, I get a conversion error.

Could you please give me some example code?

Cheers.

Francis.

#4
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
You add it to the textbox's text property, not the textbox.

#5
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
That creates an error, due to the Listview.SelectedIndexChanged is a System Array?

Do you know of any tutorials for this function?

#6
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
if (listView1.SelectedItems.Count == 1)
{
string logToGet = listView1.SelectedItems[0].Text;
}

#7
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
The code that you put doesn't seem to be in Visual Basic.

THough I have got somewhere at least. I have been using the command "ListViewValue = ListView1.SelectedItems.Item(0)" The only problem that I have with this is that due to this being subbed as System.Windows.Forms.ListViewItem it cannot be added to a textbox. Would you happen to know if there is a way of dimming it to a string without having errors?

Thanks.
Francis.

#8
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
Add .Text to Item(0)

#9
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
I've done that. ".Text" is a string, while "Listview1.SelectedItems(0)" is a "System.Windows.Forms.ListviewItem"

#10
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
and Listview1.SelectedItems(0).Text is a string.

#11
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
"Error 1 Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'String'. C:\Users\Francis\documents\visual studio 2010\Projects\Remote program\Remote program\Form1.vb 121 25 Remote program
"


That, is the error I get when "Label3.Text = ListViewValue"
Btw, "ListViewValue" = "ListView1.SelectedItems(0)"

#12
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
Have you tried ToString()?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users