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

Top 5 Contributors of the Month
Gaurav Pal

Home >> Interview Question >> WPF >> Post New Question Subscribe to Interview Questions

How can I sort items in a ListBox (or any other ItemsControl)?

Posted By :Gowthammanju     Posted Date :July 31, 2011    Points :40   Category :WPF 
Sorting can be done via a mechanism on the ItemsCollection object, so it applies equally to all ItemsControls. ItemsCollection has a SortDescriptions property that can hold any number of System.ComponentModel.SortDescription instances. Each SortDescription describes which property of the items should be used for sorting and whether the sort is ascending or descending. For example, the following code sorts a bunch of ContentControl items based on their Content property:

// Clear any existing sorting first


// Sort by the Content property


new SortDescription("Content", ListSortDirection.Ascending));

You can also find related Interview Question to How can I sort items in a ListBox (or any other ItemsControl)?  below: 

What is Quick Sort?

The quick sort algorithm is of the divide and conquer type. That means it works by reducing a sorting problem into several easier sorting problems and solving each of them. A dividing value is chosen from the input data, and the data is partitioned into three sets: elements that belong before the dividing value, the value itself, and elements that come after the dividing value. The partitioning is performed by exchanging elements that are in the first set but belong in the third with elements that are in the third set but belong in the first Elements that are equal to the dividing element can be put in any of the three sets the algorithm will still work properly. (More...)

what is Merge Sort?

The merge sort is a divide and conquer sort as well. It works by considering the data to be sorted as a sequence of already-sorted lists (in the worst case, each list is one element long). Adjacent sorted lists are merged into larger sorted lists until there is a single sorted list containing all the elements. The merge sort is good at sorting lists and other data structures that are not in arrays, and it can be used to sort things that don't fit into memory. It also can be implemented as a stable sort. (More...)

What is Radix Sort?

The radix sort takes a list of integers and puts each element on a smaller list, depending on the value of its least significant byte. Then the small lists are concatenated, and the process is repeated for each more significant byte until the list is sorted. The radix sort is simpler to implement on fixed-length data such as ints. (More...)

How can I add icons to menu items?

Unfortunately there is no built-in feature for this.You need configure the menu items to be owner-drawn (set OwnerDraw to True) and then use GDI+ to draw both the text and graphics (handle the MeasureItem and DrawItem events). Microsoft's "Got Dot Net" site (www.gotdotnet.com) is a good place to start for information about implementing owner-drawn controls. (More...)

How can you sort the value of the array in descending order?

First call Sort() and then Reverse() methods. (More...)

What is the difference between ListBox (Filled with data) and DropDownList (Filled with data), in terms of SelectedIndex property?

The default value of the SelectedIndex property of the Listbox is -1, which indicates that no item is selected in the Listbox. However, the DropDownList control overrides this property and sets the default value to 0, which indicates the first item in the list. (More...)

What is the lifespan for items stored in ViewState?

Item stored in ViewState exist for the life of the current page. This includes postbacks. Viewstate become nothing once it redirects or transfer to another page. (More...)

What is the lifespan for items stored in viewstate

Item stored in ViewState exist for the life of the current
page. This includes postbacks (to the same page). (More...)

How to Update SharePoint List Items without Creating New Versions?

SystemUpdate method avoids updating modified and modifier fields.
here is the sample below.
SPSite site = new SPSite("http://mossportal/");
SPWeb web = site.OpenWeb();
SPList leaveslist = web.Lists["My Leaves"];
SPListItem collection = leaveslist.Items[0];
collection["Earned_x0020_Leaves"] = "1";
collection.Update(); (More...)

How do you return SharePoint List items using SharePoint web services?

In order to retrieve list items from a SharePoint list through Web Services, you should use the lists.asmx web service by establishing a web reference in Visual Studio. The lists.asmx exposes the GetListItems method, which will allow the return of the full content of the list in an XML node. It will take parameters like the GUID of the name of the list you are querying against, the GUID of the view you are going to query, etc.
Side Question: I got asked how I built queries with the lists.asmx web service. In order to build queries with this service, one of the parameters that the GetListItems method exposes is the option to build a CAML query. There are other ways to do this as well, but that was how I answered it. (More...)

When retrieving List items using SharePoint Web Services, how do you specify explicit credentials to be passed to access the list items?

In order to specify explicit credentials with a Web Service, you generally instantiate the web service, and then using the credentials properties of the Web Service object you use the System.Net.NetworkCredential class to specify the username, password, and domain that you wish to pass when making the web service call and operations.

How can you sort the elements of the array in descending order?

By calling Sort() and then Reverse() methods. (More...)

How can you sort the elements of the Array in descending order?

We can sort the array in descending order by calling
Array.Sort() and then by calling Array.Reverse() method. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

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