By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,267 Members | 1,808 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,267 IT Pros & Developers. It's quick & easy.

Listview Rectangle Focus problem

P: n/a
I've tried working with the SelectedIndices and Items[##].Selected
attributes to get the problem to go away, but not having any luck.

Questions I have are:

1) How do you move (using code) the focus Rectangle when your Selected
Index changes ?
2) If there are no selected rows, can that focus rectangle be removed?
3) What other quirks exist in this simple example I might need to code
for ?

On the Listview, I'm using "MultiSelect = True" and "FullRowSelect =

// Detail

When the application first starts up, the Listview has focus. No
selection has been clicked, but a simple rectangle outlines the first
If I press Cursor Up, nothing highlights. If I press Cursor Down, the
2nd row highlights and the Focus rectangle moves to 2nd row:

Double clicking the row launches my Editor Form, in this example I
double click the 2nd Row item.

I pass the ListView object from the Main Form to the Editor. In my
Editor, I have [Previous] [Next] buttons. I click the "Previous"
button and the Main ListView changes focus to the 1st record.

// Code for Previous click:

private void cmdPrevious_Click(object sender, System.EventArgs e)
if (_ListView.SelectedIndices[0] > 0 )
int iNewIndex = _ListView.SelectedIndices[0]-1;

// Remove Current Highlighted Record
_ListView.Items[_ListView.SelectedIndices[0]].Selected = false;

// Highlight Previous record
_ListView.Items[iNewIndex].Selected = true;

// Code (Image) for Previous click:

I finish the Edit and close the Editor Form, the Main Form now has the
first row highlighted -AND- the focus Rectangle is still on the 2nd

Pressing Cursor Down does nothing. Pressing Cursor Up moves the focus
Rectangle to the 1st Row and it remains highlighted.


Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Tinkering around with it some more, I finally discovered the solution
in case it helps anyone else in the future.

Had to add one more item call:

_ListView.Items[iNewIndex].Focused = true;

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.