I am trying to find the selected SubItem of a ListView.
I have a ListView with the following properties
View = Details
FullRowSelect = True
GridLines = True
ShowItemToolTips = True
MultiSelect = False
I then add 3 columns and multiple rows, each with 2 subitems to populate each of the columns. I end up with a ListView looking something like this
Header1 | Header2 | Header3
==========+============+===========
Item 1 | Sub1Item1 | Sub2Item1
Item 2 | Sub1Item2 | Sub2Item2
Item 3 | Sub1Item3 | Sub2Item3
If I hover over a particular item, say Sub2Item2 it will give me the appropriate ToolTip "Sub2Item2". However I want to catch an event either a mouse click or a mouse hover and get the associated SubItem so I can use it's Tag property to do further processing.
I have checked the args for ItemMouseHover() event and can't find anything to do this, nor can I after searching around online.
[Edit to clarify] I am trying to hook an event such as SelectedIndexChange or MouseUp (any mouse click related event is fine) and get the current selected SubItem. Think of it like a spreadsheet, when I click a cell (SubItem) I want to get the cell itself (SubItem) not the entire row (ListViewItem)
I think the ListView.HitTest method is what you're looking for.
In your case SelectedItems property should work until Hover comes into consideration. for hover event there is a property called HoverSelection.
Related
I have a Combobox with several items (C# Labels because I want to change individual text colors). Within callbacks, when editing some textboxes, I change the color and/or text of the items. When I click on the combobox I see that the items in the list have the correct color/text. However, the color/text changes of the selected item are not directly reflected in the shown combobox text. How can I achieve that?
I tried to set the Text property of the combobox itself: no effect. Also setting the selected item to an empty Label and then set it back to the correct Label has no effect. If I set SelectedIndex to -1 and then back to the correct selected index it works and the shown text is updated, but this triggers the SelectionChanged callback which I do not want. I could first detach the SelectionChanged callback from the combobox and then attach it again, but this is in my opinion very ugly programming.
Maybe I am missing something simple...
Edit
I tried binding, following the suggestion of SLak:
List<Label> labels;
MyComboBox.ItemsSource = labels;
The result is still the same. Suppose index 0 is selected. When I change the corresponding Label:
labels[0].Contents = "new content";
then it is not reflected in the selected text of the combobox. When I click the combobox I can see the new text in the unfolded list, but only when I change the selection and then go back to index 0 the new text is shown by the combobox as the selected item. That synchronization should be autmatically.
In ListView there are 3 option of SelectionMode
1.Single - only one item can be selected.
2.Multiple - you can select muliple items, one after the other.
3.Extended - You can select multiple items and used Ctrl or Shift key.
I'm need to select some items in ListView as text in TextBox.
i.e. press with the left button of mouse, until the mouse is up.
and mark all between items as Selected.
How can I make it?
Thanks
1.Single: SelectionMode="Single"?
2 Mutiple : i think use binding
enter link description here
3
enter link description here
Or You try this line SelectionMode="Muti..."
Firstly, the porpose of this problem is to display listView of TextBlocks for allow use ItemsSource of ListView for display text for several reasone.
behind each textBlock that contains a word, there are in the ViewModel class named Word. that contains the text of the word and property of IsSelected.
I solve this problem, by adding 3 EventSetter event to the ListViewItem,
1.PreviewMouseLeftDown
2.MouseEnter
3.PreviewMouseLeftUp
and adding a flag of IsInSelection, and two object Word that present the control in the view,1.firstSelectionWord, 2.lastSelectionWord.
and, when the first event raise, i update the current control to be Selected.
and set a flag IsInSelection to true. and set firstSelectionWord = lastSelectionWord = current word pressed.
in the MouseEnter event i checked if IsInSelection is true, and them mark also the current control to Selected=true. set the lastSelectionWord = current word pressed.
and call a method that mark all the Word between them as selected.
in the PreviewMouseLeftUp function, i set the IsInSelection = false.
A customer has asked for a user interface which combines a number of different elements. It's basically a list. Selecting an entry in the list causes a dialog to expand in-place:
Item 1
Item 2
Item 3
After selecting Item 2
Item 1
------------------------------------
| Item 2 |
| text box button |
| button |
| |
| text box button |
------------------------------------
Item 3
I know you can make some fairly complex listviews http://www.codeproject.com/KB/list/ObjectListView.aspx
How would some of you GUI experts do this? Is there a name for this type of layered interface that I could just search on to learn more about it? Can I just extend listviewitem with my in-line form? I think I just need a pointer as to how to start. I've done some forms programming but this is beyond my current knowledge.
Thanks
Edit --
Dash's comment set me on the right track as I think it's an accordion control that I'm looking for. Since he didn't provide an answer I don't know how to mark this as answered...
If you're using WinForms, there's an implementation called DropDownPanel on CodeProject that looks like what you want.
This answer to a similar question describes a possible solution using TableLayoutPanel, which you may also be interested in.
I suggest TableLayoutPanel with 6 rows and 1 column with this orientation:
Row1: Flat button with text=Item1
Row2: A panel corresponding Item1(visible false else button in row1 pressed)
....
and so on.
Note:
First row2,4,6 visible=false
When any button in row1,3,5 is pressed depend on position single row 2,3,4 visible =true else visible=false.
Have you looked at the WPF expander control? You could incorporate this into your list to create a composite control which would satisfy the 'layering' you wish to create.
Is it possible to create a DataGridColumn that can contain both TextBlock and Checkbox. Let's say for example that I have defined a Datagrid with 7 Columns one of which is a DataGridCheckBoxColumn on the dataGrid and the others have TextBlocks. Then when I check the checkbox in a row I want all the cells on that row from TextBlocks to become Checkboxes while the rest rows remain unaffected (I am using VS2008).
You could expose a property on your bound object and link everything accordingly:
Property ---+<---> CheckBoxCol
|
+----> TemplateCol >> Trigger ----- TextBlock
|
+--------- CheckBox
So the Checkbox in one column affects said property and the templates of the other columns contain DataTriggers which check is the property is true or false and show the according content.
I've a got strange situation. I've got a datagrid, and in one of the columns is a datepicker and checkbox. The checkbox if selected will disable the datepicker.
*****************************
* | *
* DatePicker | Checkbox *
* | *
*****************************
I've had a stab at this, and a poke around but can't seem to find where I'd access the datepicker row object to disable it. ItemArray seems to enumerate the column values fine, but I need direct access so I can set IsEnabled
object selected = the_datagrid.SelectedItem;
Why don't you just bind DatePicker.IsEnabled to CheckBox.IsChecked?
It should be possible to poke around in the visual tree to find the DatePicker next to the checkbox that the user clicked. Another solution would be to add a bool property that the checkbox sets if checked and that controls IsEnabled of the DataPicker. The DatePicker and Checkbox should have the same DataContext since they are on the same row.