I have successfully managed to get my data the way I want it in ListView and have two questions;

1 - How can I select an item on a single (or double) click of a mouse button that executes some code using that as the variable passed to it from a ListView entry?

2 - How can I change the order (ascending/descending) on the second column?

Thanks in advance!

Recommended Answers

All 3 Replies

You could use the ItemActivate event. You can sepcify in the ListView properties whether the item has to be clicked once or twice to activate, then use the ListView.FocusedItem property to see which item currently has focus.
Or you could set the MultiSelect property to false and use the SelectedIndex changed event to query the ListView.SelectedIndices colelction for the currently selected item.

I tried the first method you said;

textBox1.Text = listView1.FocusedItem.Text.ToString();

and placed it within the listView1 portion of the code.

The problem I am having is that it allows me to pass a value once to a textbox but then the program crashes when I make a different selection.

The error given states;

"Object reference not set to an instance of an object."

Some help would be greatly appreciated

My bad.

I had to turn 'MultiSelect' to 'True'

Thread is marked as solved.

Thanks for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.