Highlight of ListView items without setting the focus [duplicate]
In my situation there is a textbox that I am typing in it and then there is a listView that jumps to the item I am typing in the text box so the FOCUS should alwa开发者_高级运维ys be in the text box so I can continue typing! But as I said when it is selecting the item in the ListView I want that item to be highlighted with BLUE background as other standard highlights in Windows forms. Is there a way to do this?
thanks.
Have a look at setting the ListViewItemBackColor, you could change it as they type so it looks as though it has been selected, when it reality all it has is a blue background.
Or you could try setting the colour of the background to blue AND selecting the item and then setting the focus back to the textbox so they can continue typing, although it may not happen quickly enough so key presses may be lost but you'd have to try it and see how well it works.
This question is a duplicate, so I'm giving the same answer.
Manually setting ListViewItem.BackColor
is not good a solution, especially if you want the item to get the selected
state, because it only works on unselected items. So you had to take care of several situations to make it look right in all cases (really select the item as soon as the ListView gets focus, undo the color changes, and so on...)
It seems the only good way is to use Ownerdraw or an extended ListView like ObjectListView.
I was looking for the same and I still hope for a better/smarter solution, or at least a nice and short Ownerdraw implementation. Update - I found one: use DataGridView
instead, for details see above duplicate.
精彩评论