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 =
True".

//
// Detail
//

When the application first starts up, the Listview has focus. No
selection has been clicked, but a simple rectangle outlines the first
record.

http://i11.photobucket.com/albums/a1...3/01_Start.jpg
If I press Cursor Up, nothing highlights. If I press Cursor Down, the
2nd row highlights and the Focus rectangle moves to 2nd row:

http://i11.photobucket.com/albums/a1...CursorDown.jpg

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.

http://i11.photobucket.com/albums/a1.../03_Editor.jpg

//
// 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;
_ListView.Refresh();
}
}

//
// Code (Image) for Previous click:
//

http://i11.photobucket.com/albums/a1...r_Previous.jpg

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
row.

http://i11.photobucket.com/albums/a1..._AfterEdit.jpg

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

http://i11.photobucket.com/albums/a1...5_CursorUp.jpg

Help!

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.