listview select item backcolor - c#

Do I programmatically have to manage the backcolor\highlight color on a Listview's item when selected through code?
So if I do this: listView1.Items[1].Selected = true;
Do I also need to do this, so it looks highlight, as it does when selected with a mouse click: listView1.Items[1].BackColor = Color.Blue;
(and clear it when the selection changes)
I would have thought that Selected = true would also do the 'backcolor\highlighting' that happens through the mouse click. Am I missing something?

Has the control got focus? If not the default setting is to hide the selection when the control doesn't have focus - see the HideSelection property.

You do not need to handle the highlighting code yourself, but the item will only appear highlighted if the ListView control has focus. Add listView1.Select() after you select the item and see if that helps.
Otherwise, you'll need to set the HideSelection property on the ListView to false.

Related

Selected ListViewItem is not highlighted on TabPage, after selected TabPage changed forth and back

I am currently facing a strange behavior of the C#.Net ListView when used on a TabControl's TabPage.
Background:
I have said TabControl with three TabPages, the ListView is on the first one.
Scenario:
I select one Item in the ListView and its "Selected" property is set to "true"
I change to another TabPage
I change back to the first TabPage with the ListView containing the selected Item
Result:
The former selected Item in the ListView is not highlighted any longer. Iterating over all Items shows that its "Selected" property is still set to "true".
As soon as I click into the ListView control, I can see the selected Item being highlighted for a short moment, before loosing its highlighting again due to me having clicked somwhere else and therefore deselecting it.
But neither one of Refresh, Invalidate, RedrawItems, Focus or Select on the ListView leads to the selected Item being highlighted again.
Has anyone of you experienced the same issue and found a proper way to solve this?
My current solution is to clear the List of SelectedItems on the ListView as soon as the corresponding TabPage is re-focused, hence deselecting every Item and forcing the user to re-select what he wants to be selected.
But since I also noticed that ListBoxes can savely store their selection and display it properly, I would wish for the same feature on the ListView.
Thanks,
Thomas

UWP programmatically remove visualstate for specific listviewitem

My style is defined for the listview.
Listview items will have focus behaviour.
I have 3 types in my ListView.
One is unselectable and will also not having focus behaviour (used property IsHitTestVisible = false)
One is selectable, can have focus colors (works correctly)
One should be selectable but only should not having a focus state.
IsEnabled changes the transparancy and is unselectable so no option.
IsHitTestVisible doesnt change the transparancy but make the item also unclickable.
Do anyone have an example how I can remove only the focus behaviour but keep the rest for a specific item?
You can create a ViewCellRenderer for your listview. For Reference you can use this link:
http://blog.wislon.io/posts/2017/04/11/xamforms-listview-selected-colour

Is there any way to change the background color of the ComboBox control with DropDownList in Windows Forms

Is there any way to change the background color of the ComboBox control with DropDownStyle = DropDownList in Windows Forms?
If I just do
this.comboBox.BackColor = Color.Red;
nothing changed.
I need to highlight this ComboBox when the user doesn't choose any item (I can't provide the default item in my case).
Thanks in advance.
You also need set DrawMode to OwnerDrawFixed

In WinForms, how can I create a delete button in a DevExpress GridControl?

I'm trying to create a delete button at the right of every row in a DevExpress GridControl, like this:
What I've done is added another column and set its ColumnEdit property to an instance of RepositoryItemButtonEdit. I handle the ButtonClick event, to delete a row.
I can determine which row I'm on from this code:
myGridView.GetRow(myGridView.FocusedRowHandle);
Because I don't want a text editor on my button, I set the TextEditStyle to HideTextEditor.
By default, the button shows an ellipsis.
To remove the ellipsis, I adjusted the Buttons property on the RepositoryItemButtonEdit. I set the Kind to Glyph and set the image to my X icon.
Unfortunately that seems to simply remove the button altogether.
Does anyone know a better way to do this, or a way to show a button with an image on it, in each grid row?
I discovered that there is actually a delete button kind. So, I do everything as in the question, but instead of choosing the kind Glyph, I choose Delete, and I don't need to select an image.
I have summarized what I found in the DevExpress forum:
Use the ButtonEdit control and set the TextEditStyle property to HideTextEditor. The Repository Item has a Buttons collection through which you can add a caption, image etc.
In the Buttons collection, change the "Kind" property to "Glyph".
You can use the CustomRowCellEdit event to conditionally apply editors on a cell-by-cell basis.
Make sure you set the Button's Kind property to "Glyph" and set the Caption property to whatever text you'd like:
DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit buttonEdit =
new DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit();
buttonEdit.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
buttonEdit.Buttons[0].Caption = "X";
buttonEdit.TextEditStyle =
DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
e.RepositoryItem = buttonEdit;
You should handle the GridView's CustomRowCellEdit event, construct a new RepositoryItemButtonEdit and assign it to the e.RepositoryItem property.
Let me know if that works.

Disable ability to deselect an item

Is there a way to disable the ability to delect an item in ListView?
I have a SplitPage and when I deselect the selected item in ListView on the left the content on the right disappears because of lost databindings. I do not want that. I tried setting the ListView selectedItem back to the last one selected but the the back button in snap mode does not work
You can set the selection mode to none and set your ItemTemplate to a restyled ToggleButton. Then you can bind the Enabled property of each button to the item view model and control the enabledness of each of them buttons separately.

Categories

Resources