.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

ListBox/ListView Selection

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :WPF
 
We are implementing drag/drop on ListBox/ListView items with the extended selection mode. The extended selection mode allows multiple items to be selection simultaneously by holding the shift or control key while selecting additional items.   In Windows Explorer, when an individual item among a group of selected items is clicked, all of the other items are not deselected until the up-click event. This allows an individual to select the desired group and then click and drag this group as a whole to the desired destination.   In WPF, the group appears to be deselected and the individual item selected on the down-click event. This means that in order to drag a group of items, you must hold shift, click and hold the mouse on the desired range of items and then drag the group. If the group is selected first and then the mouse released, the individually clicked item is selected when a drag attempt is made on the group.   We are using WPF, but would like to see the Windows Explorer selection functionality. Any thoughts on how to reconcile these two implementations? The most straight forward fix would be a custom control, possibly derived from ListBox/ListView, but this seems like it might be reinventing the wheel. Seems like the WPF controls are not designed properly here.   Thanks.


View Complete Post


More Related Resource Links

Owner-drawn ListView and nonstandard subitem size: selection problems.

  
Hello, I have a ListView whose first column is owner-drawn and items can be selected (I had to jump through hoops to draw the focus rectangle correctly). The problem is, my custom drawing displays the text in a wider font than normal, and only for this column. And when I click an item to select it, the right part of the text does not react, because the listview doesn't "know" there is text there (since it "thinks" the text is smaller). How can I correct this? Is there a "hit test" or "measure item" event or something, to tell the list view to consider a wider zone for clicks?

A layout, mouse selection, ListView problem/question

  
I'm having a problem with a particular layout scenario, and how it interacts with a left mouse click in certain situations. I have 3 rows in a Grid.  The first is a ListView (Master), with the Row Height set to '*'. It's ItemSource is bound to a collection in a ViewModel, and its SelectedItem is bound to a value in the ViewModel.  When the SelectedItem is null, it should take up its entire container (the other 2 rows are invisible). The second row is the GridSplitter.  It's visibility is bound to a value in the ViewModel.  It's only visible when the SelectedItem in the Master ListView is not null.  It's GridRow height is set to Auto, and it's height is explicitly set to 5 (via a style). The third row is a sub-ListView that shows Detail data for the Master SelectedItem in the top ListView.  It's GridRow Height is set to zero by default, and if an item is selected in the Master ListView, it should become visible and have a set height (400 to start, via a binding on the Height of the row). The desired effect is that when an item is selected in the Master ListView, the Detail ListView becomes visible and the GridSplitter allows you to resize the top and bottom as needed.  If necessary, the ScrollBars become visible in the Master ListView to show any items that are now obscured by the Detail ListView (via the automatic scrolling featur

Problem with listview selection

  
I have the following problem (which I have seen documented in many places with no solution).  I populate a listview.  The steps I use are: Set the ItemsSource to nothing (VB) Set the ItemsSource to the collection to be bound to Set the selected item to nothing (VB) Set the selected item to the first item in the collection The problem is that when I use the down arrow key to change selection in the listview, the first time I use the down arrow nothing happens.  After that first glitch everything works.  I have seen many "solutions" but none that work. Any ideas?? Thanks LLoyd Sheen

Retaining the selection color(default blue Color) for the selected items in ListView when focus is l

  
I am having a Listview in a form. I have added items(images) to the Listview. When i select the item(Image) in the listview , the item(image) is selected with Default selection Color(Blue). In the same form i have other form added to its container.When i tried to click on the controls of other form, the default selection color(blue) is changing to Grey color. For the lisview i am using property HideSelection = false. How i could maintain the default selection color(blue) even in focus leave of listview? Can any one please suggest me a solution or give me a piece of code. Thanks in Advance, Kumar

Drop Down Listbox SelectedIndexChanged Event not firing when I programmatically change selection

  
I have two drop down listboxes (DDL1 and DDL2).  When DDL1 has an index change, DDL2 then has a refresh of list items based off SQL Server SELECT from a table.  The database isn't the problem.  Everything works perfectly when the user selects a new item manually from DDL1.But in my code, I save the user data from the selection of DDL1 in a separate table.  And then upon rendering of the page (Page_PreRenderComplete), I do a SelectedIndex assignment of the value of what's saved in the db table.  That works just fine, it selects the DDL1 item, but DDL2 is unaffected, as if DDL1's SelectedIndexChanged event isn't called like it would be if manually changed.  How can I get around this?Thanks in advance. :)

Retaining the selection color(default blue Color) for the selected items in ListView when focus is l

  
I am having a Listview in a form. I have added items(images) to the Listview. When i select the item(Image) in the listview , the item(image) is selected with Default selection Color(Blue). In the same form i have other form added to its container.When i tried to click on the controls of other form, the default selection color(blue) is changing to Grey color. For the lisview i am using property HideSelection = false. How i could maintain the default selection color(blue) even in focus leave of listview? Can any one please suggest me a solution or give me a piece of code. Thanks in Advance, mskumar.mcp

TreeView vs ListBox vs ListView performance

  
Hi, I am currenlty using a treeview to display user searches on files, some of the searches return 10000 files, and it is taking the treeview ages to display them. Maybe I am not using the treeview correctly, or I am using the wrong control...Will it be better to use the listbox or list view?   Here is my Treview xaml and code:   void search_SearchJobListChange() { Mouse.OverrideCursor = Cursors.Wait; Application.Current.Windows[0].IsEnabled = false; try { Accordion.SelectedIndex = 1; AccordionItem item = Accordion.SelectedItem as AccordionItem; item.IsSelected = true; //A new item has been added to our hit list. Select this item tvHitList.ItemContainerGenerator.StatusChanged += new EventHandler(ItemContainerGenerator_StatusChanged); SearchJob latestJob = SearchJobsList[0]; bool b = TreeViewHelper.SetSelectedItem(tvHitList, latestJob); TreeViewHelper.SetScrollbar(tvHitList); } catch { } finally { Application.Current.Windows[0].IsEnabled = true; Mouse.OverrideCursor = Cursors.Arrow; } }   <TreeView Padding="5" Margin="1" x:Name="tvHitList" Style="{DynamicResource TreeViewControlStyle}" ItemsSource="{x:Static local:Window1.SearchJobsList}" Dock

Multiple Listbox Selection not working :(

  
I'm loading a ListBox this way, which works and shows the selected items: lstCollectionsType.SelectedValuePath = "ClientCollectionTypeID"; lstCollectionsType.DisplayMemberPath = "ClientCollectionType1"; lstCollectionsType.ItemsSource = MyClient.ClientCollectionTypes; foreach (ClientCollectionType item in MyClient.ClientCollectionTypes) { if ((bool)item.Selected) lstCollectionsType.SelectedItems.Add(item); } And when trying to save the data, I do it as shown below. But it's not getting the current selected data. It's showing the data of how it was loaded. Make sense? It's not changing what is selected. foreach (ClientCollectionType i in lstCollectionsType.Items) { if (i != null) { ClientCollectionType boo = MyClient.ClientCollectionTypes.SingleOrDefault(c => c.ClientCollectionTypeID == i.ClientCollectionTypeID); if ((bool)i.Selected) boo.Selected = true; else boo.Selected = false; } } Please help! Thank you so much for your time!

Selection Changed event is not firing for listview

  

Hi,

     In my listview i have two columns, once is check box and another one is normal column. if i select in normal column, listview's selection changed event is fring, but when i select check box(This checkbox is inside the datatemplate) listview's selection changed event is not firing. Can any one tell me how i can achieve it. If you are not understand, please give your email id, i will send my sample application to you.

 

Regards

Udayakumar S


delete multiple selection from ListView

  

Hi All

My ListView has CheckBox column to select ListView items. I don't use SelectionMode="Multiple". I would like to select multiple items and delete them by click button. For that I use a loop

If ListView1.SelectedItems.Count > 0 Then
  For i As Integer = ListView1.SelectedItems.Count - 1 To 0 Step -1
    Me.ListView1.SelectedItems.Remove(i)
  Next
End If

Me.ServiceTableAdapter.Update(Me.TestDataSet.Service)

When I select items and click Delete button nothing was deleted. How fix and get multiple delete items from ListView.

Thanks.


Nested ListView: Parent listview item auto selection on child ListViewitem select

  
 

how can i auto select paraten listview item on selecting child listview item?

<
ListView ItemContainerStyle="{StaticResource myStyle}" Name="lv_list" Margin="5" HorizontalContentAlignment="Stretch">

ListBox with a Canvas, strange selection behaviour

  

Hello,

 

I have a Listbox with a Canvas asigned to the ItemsPanelTemplate:

<ListBox x:Name="CanvasListBox" SelectionMode="Multiple" SelectionChanged="CanvasSelectionChanged">
	<ListBox.ItemsPanel>
		<ItemsPanelTemplate>
			<Canvas />
		</ItemsPanelTemplate

ListBox / ListView smooth scrolling missing

  

Why doesn't ListBox implement smooth scrolling?

 

Seems like pretty silly limitation, considering fancy eye-kandy nature of WPF.


WPF ListView Selection

  

I was designing some program and I have problem in getting the selected item name in listview.

Let me explain code.

 

//Following code used to create the ListView in WPF

 

ListView splistview1 = new ListView();

StringReader listview1 = new StringReader(@"<ListView xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Height='455' HorizontalAlignment='Left' Margin='193,32,0,0' Name='listView1' VerticalAlignment='Top' Width='572'> <ListView.View> <GridView> <GridViewColumn Header='Program Name' Width='200'/> <GridViewColumn Header='Program Path' Width='350'/> </GridView> </ListView.View> </ListView>");

XmlReader reader = XmlReader.Create(listview1);
            splistview1 = (ListView)XamlReader.Load(reader);

 

//Declaring the GridView for ListView

public GridView view = new GridView();
        public GridViewColumn name = new GridViewColumn();
        public GridViewColumn path = new GridViewColumn();

 

//The setting the ListView to GridView

 

public void SetListView()
        {
&nb

Using ASP.NET 3.5's ListView and DataPager Controls: Displaying Data with the ListView

  
Prior to ASP.NET 3.5, developers who needed to display a set of records could choose between the GridView, DataList, and Repeater controls. The GridView provides rich data features, but has a very boxy layout; the DataList and Repeater allow for a more flexible layout, but lack the "point and click" data features found in the GridView, DetailsView, and FormView controls. The ListView bridges the gap between layout flexibility and built-in data features.

This article, the first in a series of articles on the ListView and DataPager controls, looks at the ListView's many available templates and illustrates how to display data. Read on to learn more!

Maintain HTML Radio Button Selection Inside GridView After Postback

  
Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.

ListBox tricky to set in a DataGrid/GridView

  
Listboxes are very tricky to set selected items in grid - there is no real nice way to do it. It would have been great if Microsoft included a property that accepts an array or comma separated values - or anything! But they only allow each item in the list to be selected individually. The way to do this in a grid is a bit messy, but it is fairly simple to implement. When a row is created (as per the event), select the items of the listbox as per the datagrid source data:
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend