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

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT
Post New Web Links

CheckedListBox and limiting selections

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :Windows Application

Hi everyone. 

I have a checkboxlist with 17 checkable items and I want to limit the possible selected items to 6. I am able to do this, but my problem is that the items that have been selected can not be unselected again to select different items ( up until the limit of 6 ). I have been able to limit the selections using the following code: 

private void items_Check(object sender, EventArgs e)
   CheckedListBox items = (CheckedListBox)sender;

   int selecteditems = items.CheckedItems.Count;

   if (selecteditems > 4) // needs to be 4 because the control is validated after input

    items.Enabled = false;



How should I proceed if I want to limit the selectable items but give the user the possibility to unselect already selected items ? 

Appreciate all the help!

View Complete Post

More Related Resource Links

CheckedListBox displays System.Data.DataRowView on one machine

As I was writing this post I solved my problem. Now I will share the solution for anyone who may stumble across this legacy cr*p. I inherited an old VB.NET application written in the old Visual Studio .Net against the 1.0 framework. Recently we had to rebuild a couple of machines and redeploy the app. We have CheckedListBox controls bound using the DataSource property and suddenly all we could see was System.Data.DataRowView in the list on these machines. All the forums out there tell you that binding the items with the DataSource property is not supported by Microsoft and offer code fixes, which we obviously do not want to do. I installed the .Net Framework 1.0 redistributable and fixed it right up. Which is a little strange because one of the machines it still works on only has 1.1. But there you have it  I actually tested this on another machine by installing 1.1 first, which did not fix the problem, but installing 1.0 did. And another interesting thought. The executable and its class library dependency reside in a network share. After installing the 1.0 framework I had to run a Caspol.exe command to grant privs to the share or the executable could not access the library. The app functioned fine without the Caspol.exe command (except the ListBox of course) prior to installing the 1.0 framework. Strange stuff...Hope this helps someone someday.

Limiting MySites and Email during closed POC.

SharePoint 2010, Small Farm Installation. Win2008R2, SQL2008R2  Howdy, I'm wrapping up a Proof of Concept and about to deploy it to users.  Management has asked that I limit the visiting of the Mysites to only the core POC folks.  About 40 or so people, likely a slowly expanding circle. Once the POC is completed, I envision it opening up to the entire company, and creating an extranet, and a second farm for clients.  This POC will enclude Enterprise Search, Productivity Hub, and numerous collaborative type sites.  What is the best way to effectively remove rights to all but the minimal group from accessing the Mysites.  If I pull the profiles from AD for the entire company does this somehow provide rights to this area? Also, is there a way to block emails from being sent to staff, with the exception of the POC group..  I hope I'm explaining this with enough detail.  Thanks,  

Limiting Nickname / Phonetic matching to just First Name

The Nickname / Phonetic matching in SharePoint 2010 is a nice new feature, where searching for Jeff will pull up results for Geoff, Jeffrey, etc. However, it also searches surnames and pulls in people with a last name like Jefferson, Jeffery, Jeffrey When creating your query, is there any way to limit the nickname searching to just the forename? If I do a queries like "FirstName:Jeff" or "FirstName=Jeff", then it stops doing nickname/phonetic matching. I've also tried "Nickname:Jeff" and "FirstNamePhonetic:Jeff", but these do not pull up any results at all. How does the nickname/phonetic matching work internally, does it search over a number of internal field names (if so, can these be searched using the advanced property search such as FirstName:Jeff). I thought perhaps I could get the kind of search we need by combining it with logical operators, so if I want any person with a first name sounding like Jeff, and surname beginning with B, then I could do this...   LastName:B* (FirstName:Jeff* OR Jeff) ...but the Jeff on it's own without a Property name Prefix causes a Malformed Query error, I assume it cannot be applied with Logical Operators. Changing the query to...   LastName:B* FirstName:Jeff* Jeff ...brings results, but the wrong results we want as the query does not pull back people with a Forename of Geoff, presumably

Creating and sharing new sharepoint site to internet, limiting user access

I am a new hire into an existing business as I.T. I know the networking, I know the computers. The owner now wants me to learn Sharepoint among some other things. They currently use WSS 3.0. I have been reading up on this for the last month. I think I am ready to extend the current site to make it an Internet site so the employees can login. Some other things we would like to do I have read up on and it looks like they can be done, things such as inventory tracking in collaboration with QuickBooks and creating a website / portal for clients to have a unique login on and can see the status of their jobs in custom SharePoint lists. As far as I can tell the clients need an AD account. However, apart from that I am not sure what to do. A little background.  The company has multiple clients, and we ship things out daily to those clients.  We use Sharepoint to track the status of the jobs as they progress through the stages ultimately going to delivery. There is one common page that lists all the jobs by all clients that is updated constantly. We would like to allow multiple (different) clients/logins and have a page customized for each client.  For example, you are a client and go to www.companyname.com/sharepointsite.html.  From there you would get to a portal page with a login. Once logged in you will be presented with the Shar

Data source Selections

Hi Am in the middle of building a site that has a main banner. I have set the banner up with a fade out/in effect and used an xml datasource for the data. Am trying to get it so that when the XmlDataSource reads the Xml file it dosnt select the current active banner. Below is the code for both my Xml and the Banner.   Thanks <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" /> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Advert.xml" /> <asp:Timer runat="server" Interval="10000" ID="SlideShowTimer" /> <asp:UpdatePanel runat="server" ID="SlideShow" UpdateMode="Conditional"> <ContentTemplate> <asp:AdRotator ID="AdRotator1" runat="Server" AdvertisementFile="~/Advert.xml" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="SlideShowTimer" EventName="Tick" /> </Triggers> </asp:UpdatePanel> <cc1:UpdatePanelAnimationExtender runat="server" ID="UPextender" TargetControlID="SlideShow" BehaviorID="animation"> <Animat

Limiting records returned by AutoCompleteExtender

Hi all,   I am using AutoCompleteExtender on a text box as follows <cc1:AutoCompleteExtender ID="aacId" runat="server" DelimiterCharacters="" Enabled="True"                        CompletionListCssClass="autocompleteplus_listItem" CompletionListHighlightedItemCssClass="autocompleteplus_highlightedListItem"                        CompletionListItemCssClass="autocompleteplus_listItem" CompletionListElementID="autocompleteplus_completionListElement"                        ServiceMethod="GetCompletionListId" ServicePath=""                         TargetControlID="txtCandidateId" MinimumPrefixLength="2"                         CompletionSetCount="10"> My problem i

Limiting Search Scopes to Articles, .docs, .xls, etc.

We have a customized site with a number of workarounds, which has necessitated using multiple pages to display data. EG, a contributor might use an "AnnouncementUPLOAD.aspx" page to add data displayed through a Web Part on "Announcement.aspx". I know I can Security Trim at the page and DocLib levels which would carry over into what's revealed by Search, but I'm curious if I can handle this through Scopes. So, if I ran a search for "George Washington", I'd want to return: items in DocLibs (ie Office Documents) items from Announcements, but NOT the full Announcement List. (ie not the http://.../pages/Announcement.aspx page, but the http://.../lists/Announcement.aspx page.) Doable? Thanks!

How can I limit the number of parameter selections?

HI I'm wondering if I can limit the number of parameter selections. For excample, user must  select 2 years in YEAR dropdownlist. Many thanks.

Excel pivot table report filter selections from a cube

There are two filters added to the report filter, Date (8/31/2010) and Product (Product A), from a cube I have.  Everything works just fine.  Once the cube is refreshed each day to include the new data, for some reason, only the selection of Date, 8/31/2010, stays but the selection of Product changes to All Products.  Both dimensions are fully processed but the surrogate keys for existing records do not change.  I checked the MDX captured in Profiler and in the where clause, the date selection is passed from the pivot table but the product selection is lost and all products is passed in.  Any thoughts? TIA. 

Limiting Column SUM()


(This is a follow up to an issue I posted about previously.)

I have a table of Activities, Users, and RSVPs, where RSVPs signify a user's intention of attending a particular activity, along with any number of guests.

In some cases, there will be a limit to the number of RSVPs (including guests) allowed for a particular activity. So I need to limit SUM(RsvpGuests) to this value.

I've come up with the following stored procedure but SQL isn't my specialty and I'm looking for some constructive criticism. One weakness I can see is that this procedure will fail to add the RSVP if another thread exceeds the limit at around the same time. But I don't really see anything better. A trigger was suggested but that may be beyond my abilities (and I wasn't able to get answers to some of my questions about triggers).

ALTER PROCEDURE dbo.tc_RsvpsUpdate
	@ActivityID				int,
	@UserID					uniqueidentifier,
	@Guests					int,
	@ExceededBy				int OUTPUT

Filtering with Multiple selections (Checkbox list control)

I have a scenario where there is a large list of 2000+ items, these items each have a name associated to it.

I now need to be able to filter this list by selecting the names from a Checkbox list, the problem is I cannot figure out how to get it to work when multiple values are selected.

The current setup is Using a DVWP to display the items a Datasource control of all the names and then the ASP.NET Checkbox list control to act as a filter

Can anyone help?

How to Create Grouped Checkedlistbox



I need to create a grouped checklistbox dynamically from the database, I was able to do it using an TreeView Control, But I need to move it to a Checklistbox. Below is the logic in VB.NET for the TreeView

#Region "Generate Tree View"
    Private Sub CreateRootnodes()
            Dim ds As New DataSet()
            ds = optiongroups.GetAllOptionGroups()

How to add a CheckedListBox at runtime to a groupbox along with setting some items checkstate to Che



I am adding a CheckedListBox to a groupbox at runtime. The items in CheckedListBox comes from db. Also based on certain conditions i need to set a particular item to be checked.

How to do that?

Please help...



Regards TurbulentGeek "Mark as answer if it helped you...";

People Picker: limiting the results


Hey all,

After succesfully setting up User Profile Synchronization with our AD using a Connection Filter I am now trying to configure the people picker.

I understood that the people picker queries the whole AD. Since I only need those accounts in a particular OU I have set the setsiteuseraccountdirectorypath to "OU=Employees,DC=company,DC=com"

With this setting I do not have other accounts, such as admins and service account. So far so good. :)

Now, some of these accounts are disabled and some do not have an Exchange mailbox and I want those accounts filtered out.

I have a AD Browser tool that can handle LDAP queries. I tried this LDAP query in this tool and the results were just what I've expected:


When I use this LDAP query for the property peoplepicker-searchadcustomquery it does not work.

I also tried the property peoplepicker-searchadcustomfilter but that leaves me with zero results.
Can someone help me out?

code SQL to populate gridview with multiple random list box selections, How to


I could use some help in coding a query.

I have a list box that allows for multiple selections (holding down the control key) the selection quantity is basically unlimited, but realistically should never be more than 50 to 100 items from the listing of about 3000 items.

I need to collect the list of selected items from the drop down list and retrieve each of their full records from the item master and populate a gridview.

Any help would be greatly appreciated.


Thanks again,



Add Total Problem while grouping and limiting number of rows in a page



I have a report in which first column is CITY and consists of 5 data (5 cities),all other columns are grouped w.r.t CITY, i.e in one city there can be 100s of other column data, last column of report is INCOME. If I right click on [INCOME] field and select ADD TOTAL then it gives citywise total, but I limited only 10 records per page and pagebreak  option is selected at end of the CITY group. When perform the same operation now it gives pagewise sum not the groupwise, please rectify my approach if I am wrong else suggest the solution.

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