/// <summary> /// This method sorts the items in a listbox. /// </summary> /// <param name="items">The list control.</param> /// <param name="Descending">Whether to sort the list box descending. </param> public static void SortListItems(this ListItemCollection items, bool Descending) { System.Collections.Generic.List <ListItem> list = new System.Collections.Generic.List <ListItem>(); foreach (ListItem i in items) { list.Add(i); } if (Descending) { IEnumerable <ListItem> itemEnum = from item in list orderby item.Text descending select item; items.Clear(); items.AddRange(itemEnum.ToArray()); // anonymous delegate list.Sort(delegate(ListItem x, ListItem y) { return y.Text.CompareTo(x.Text); }); } else { IEnumerable <ListItem> itemEnum = from item in list orderby item.Text ascending select item; items.Clear(); items.AddRange(itemEnum.ToArray()); //list.Sort(delegate(ListItem x, ListItem y) { return x.Text.CompareTo(y.Text); }); } }
public void AddRangeAddsARange() { var list = new ListItemCollection <string>(); var toAdd = new List <string> { "Foo", "Bar" }; var toAddSecond = new List <string> { "Foo", "Bar", "Hello" }; list.AddRange(new List <ListItemInnerCollection <string> > { new ListItemInnerCollection <string>("Bob", toAdd), new ListItemInnerCollection <string>("Dave", toAddSecond), }); list.Count.Should().Be(2); list[0].Title.Should().Be("Bob"); list[0].Should().ContainInOrder(toAdd); list[0].Should().OnlyContain(s => toAdd.Contains(s)); list[0].Count.Should().Be(2); list[1].Title.Should().Be("Dave"); list[1].Should().ContainInOrder(toAddSecond); list[1].Should().OnlyContain(s => toAddSecond.Contains(s)); list[1].Count.Should().Be(3); }
public static void Test_AddRange() { var listItemCollection = new ListItemCollection(); var listItem1 = new ListItem("Hello"); var listItem2 = new ListItem("Hello", "World"); var listItem3 = new ListItem("Test", "Test"); var list = new List <ListItem> { listItem1, listItem2, listItem3 }; var listItem4 = new ListItem("Missing"); Assert.Empty(listItemCollection); listItemCollection.AddRange(list); Assert.Equal(list.Count, listItemCollection.Count); foreach (var x in list) { Assert.True(listItemCollection.Contains(x)); } Assert.False(listItemCollection.Contains(listItem4)); listItemCollection.Add(listItem4); Assert.Equal(list.Count + 1, listItemCollection.Count); foreach (var x in list) { Assert.True(listItemCollection.Contains(x)); } Assert.True(listItemCollection.Contains(listItem4)); }
public void AddRangeAddsARangeEnumerableOfTuple() { var list = new ListItemCollection <string>(); var toAdd = new List <string> { "Foo", "Bar" }; var toAddSecond = new List <string> { "Foo", "Bar", "Hello" }; list.AddRange(new List <Tuple <string, IEnumerable <string> > > { Tuple.Create("Bob", (IEnumerable <string>)toAdd), Tuple.Create("Dave", (IEnumerable <string>)toAddSecond), }); list.Count.Should().Be(2); list[0].Title.Should().Be("Bob"); list[0].Should().ContainInOrder(toAdd); list[0].Should().OnlyContain(s => toAdd.Contains(s)); list[0].Count.Should().Be(2); list[1].Title.Should().Be("Dave"); list[1].Should().ContainInOrder(toAddSecond); list[1].Should().OnlyContain(s => toAddSecond.Contains(s)); list[1].Count.Should().Be(3); }
/// <summary> /// Performs a linq style Where command on the ListItemCollection and sets the collection to the output /// </summary> /// <param name="collection"></param> /// <param name="predicate"></param> /// <returns></returns> public static void Where(this ListItemCollection collection, Func <ListItem, bool> predicate) { var l = new List <ListItem>(); foreach (ListItem li in collection) { l.Add(li); } collection.Clear(); collection.AddRange(l.Where(predicate).ToArray()); }
private void SynList() { ArrayList arrayValue = new ArrayList(TextBoxSynOrder.Text.Split(',')); ListItemCollection itemCollection = new ListItemCollection(); itemCollection.AddRange((ListItem[])new ArrayList(ListBoxLeft.Items).ToArray(typeof(ListItem))); itemCollection.AddRange((ListItem[])new ArrayList(ListBoxRight.Items).ToArray(typeof(ListItem))); ListBoxLeft.Items.Clear(); ListBoxRight.Items.Clear(); for (int i = 0; i < arrayValue.Count; i++) { ListItem item = itemCollection.FindByValue(arrayValue[i].ToString()); if (item != null) { ListBoxRight.Items.Add(item); itemCollection.Remove(item); } } ListBoxLeft.Items.AddRange((ListItem[])new ArrayList(itemCollection).ToArray(typeof(ListItem))); }
protected void Page_Load(object sender, EventArgs e) { var loader = new LocaleCountryLoader(); var result = new ListItemCollection(); var allCountries = loader.Load(); var listItems = allCountries.OrderBy(kvp => kvp.Value).Select(entry => new ListItem(entry.Value, entry.Key)).ToArray(); result.AddRange(listItems); AllCountries = result; }
public ActionResult Save(Bam.Net.Data.Tests.ListItem[] values) { try { ListItemCollection saver = new ListItemCollection(); saver.AddRange(values); saver.Save(); return(Json(new { Success = true, Message = "", Dao = "" })); } catch (Exception ex) { return(GetErrorResult(ex)); } }
private void HandleListItems(ListItemCollection destItemColl, TreeNode node, Inline nodeRun) { if (nodeRun != null) { destItemColl.Add(new ListItem(new Paragraph(nodeRun))); } if (node.ChildCount > 0) { HtmlListItemEntractionVisitor itemVisitor = new HtmlListItemEntractionVisitor(TextChannel); foreach (TreeNode child in node.ListOfChildren) { child.AcceptDepthFirst(itemVisitor); } destItemColl.AddRange(itemVisitor.ExtractedListItems); } }
private ListItemCollection InitSearchCriteria() { ListItemCollection types = new ListItemCollection(); types.AddRange ( new ListItem[] { new ListItem("Select", "Select", false), new ListItem("Name", "Name"), new ListItem("Code", "Code"), new ListItem("Producer", "Producer"), new ListItem("Barcode", "Barcode"), new ListItem("Group", "Group"), } ); return(types); }
public ListItemCollection GetHierarchyItems() { ListItemCollection lst = new ListItemCollection(); lst.AddRange(ConvertToArray(GetHierarchyItems("1"))); lst.AddRange(ConvertToArray(GetHierarchyItems("2"))); lst.AddRange(ConvertToArray(GetHierarchyItems("3"))); lst.AddRange(ConvertToArray(GetHierarchyItems("4"))); lst.AddRange(ConvertToArray(GetHierarchyItems("5"))); lst.AddRange(ConvertToArray(GetHierarchyItems("6"))); return(lst); }
public static void Test_ToEnumerable() { var listItemCollection = new ListItemCollection(); Assert.Empty(listItemCollection); Test_ToEnumerable_Implementation(listItemCollection); listItemCollection.AddRange(new[] { new ListItem("Hello"), new ListItem("Hello", "World"), new ListItem("Test", "Test") }); Test_ToEnumerable_Implementation(listItemCollection); listItemCollection.Add(new ListItem("Extra")); Test_ToEnumerable_Implementation(listItemCollection); Assert.Equal(2, listItemCollection.ToEnumerable().Count(x => x.Text == "Hello")); Assert.Equal(1, listItemCollection.ToEnumerable().Count(x => x.Value == "Extra")); Assert.Equal(0, listItemCollection.ToEnumerable().Count(x => x.Value == "Missing")); Assert.Equal(2, listItemCollection.ToEnumerable().Count(x => x.Text.Contains('t'))); }
public void UpdateDirectory() { try { var list = this; var newitems = new List <EtoSystemObjectInfo>(); newitems.AddRange(_directory.GetDirectories().Cast <EtoSystemObjectInfo>()); var formats = settings.Infos.GetFormats(); var extensions = formats.Values.SelectMany(r => r.Extensions).Select(s => "*." + s); newitems.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase)); var alFiles = _directory.GetFiles(extensions).ToList(); alFiles.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase)); newitems.AddRange(alFiles.Cast <EtoSystemObjectInfo>()); if (_directory is DiskDirectoryInfo) { //newitems.Insert (0, new WebDav.WebDavBrowser (directory, "SixteenColors", "http://sixteencolors.picoe.ca")); newitems.Insert(0, new Sixteencolors.SixteenBrowser(_directory)); } items = newitems; var theitems = new ListItemCollection(); theitems.AddRange(items.Select(r => new ListItem { Text = r.Name }).Cast <IListItem>()); Application.Instance.Invoke(delegate { if (!disposed) { DataStore = theitems; Enabled = true; } }); } catch (Exception ex) { Application.Instance.AsyncInvoke(() => MessageBox.Show(Generator, this, string.Format("Unable to load the selected file ({0})", ex))); Console.WriteLine("Cannot load directory {0}", ex); } }
public void Methods() { ListItemCollection c; ListItem i; ListItem i2; c = new ListItemCollection(); Assert.AreEqual(0, c.Count, "T1"); i = new ListItem("Item 1", "10"); c.Add(i); Assert.AreEqual(1, c.Count, "T2"); i = new ListItem("This is item 2", "20"); c.Add(i); Assert.AreEqual(2, c.Count, "T3"); Assert.AreEqual(null, c.FindByText(" is "), "T4"); Assert.AreEqual(i.Text, c.FindByText("This is item 2").Text, "T5"); Assert.AreSame(i, c.FindByText("This is item 2"), "T6"); Assert.AreEqual(1, c.IndexOf(c.FindByText("This is item 2")), "T7"); Assert.AreEqual(1, c.IndexOf(c.FindByValue("20")), "T8"); i = new ListItem("Item 3", "30"); Assert.IsFalse(c.Contains(i), "T9"); c.Add(i); Assert.IsTrue(c.Contains(i), "T10"); i = new ListItem("Forth", "40"); i2 = new ListItem("Fifth", "50"); c.AddRange(new ListItem[] { i, i2 }); Assert.AreEqual(5, c.Count, "T11"); c.RemoveAt(1); Assert.AreEqual(4, c.Count, "T12"); Assert.AreEqual(null, c.FindByText("This is item 2"), "T13"); c.Clear(); Assert.AreEqual(0, c.Count, "T13"); }
public void FormInitialize() { if (Request.QueryString.HasValue("BonusPlanID", typeof(int))) { objBonusPlan.BonusPlanID = Request.QueryString["BonusPlanID"].ToString(); BonusPlanHiddenID.Value = objBonusPlan.BonusPlanID; objBonusPlan.BonusPlanDetailGet(); DeleteFlg.Value = objSecurity.DeleteFlg.ToString(); //Delete.Visible = objSecurity.DeleteFlg.ToString() == "1" ? true : false; } DropDownList dbOptions = new DropDownList(); AtriaBase.UI.ListControl.ListPopulate(JobCodeID, "JobCode", "JobCodeID", objBonusPlan.JobCodeGet(), AtriaBase.UI.ListControl.NoItemSelectedBehavior.SelectOne); AtriaBase.UI.ListControl.ListPopulate(JobCodeCommunity, "Community", "CommunityNumber", objSecurity.CommunityUserAccessGet(), AtriaBase.UI.ListControl.NoItemSelectedBehavior.SelectAll); AtriaBase.UI.ListControl.ListPopulate(JobCategoryID, "JobCategory", "JobCategoryID", objBonusPlan.JobCategoryGet(), AtriaBase.UI.ListControl.NoItemSelectedBehavior.SelectOne); AtriaBase.UI.ListControl.ListPopulate(dbOptions, "Community", "CommunityNumber", objBonusPlan.BonusPlanToCommunityGet(), AtriaBase.UI.ListControl.NoItemSelectedBehavior.SelectOne); AtriaBase.UI.ListControl.ListPopulate(JobCodeEffectiveDt, "MonthName", "EffectiveDT", objBonusPlan.BonusPlanToJobCodeEffectiveDateGet(), AtriaBase.UI.ListControl.NoItemSelectedBehavior.SelectOne); JobCodeEffectiveDt.SelectedIndex = 2; // Default to current month var communities = dbOptions.Items.Cast <ListItem>() .Where(i => !string.IsNullOrEmpty(i.Value)) .GroupBy(g => g.Value) .Select(i => i.FirstOrDefault()) .OrderBy(i => i.Text).ToList(); communities.Insert(0, new ListItem() { Text = "Select One...", Value = "" }); ListItemCollection communitiesCollection = new ListItemCollection(); communitiesCollection.AddRange(communities.ToArray()); CommunityNumber.DataTextField = "Text"; CommunityNumber.DataValueField = "Value"; CommunityNumber.DataSource = communitiesCollection; CommunityNumber.DataBind(); }
public void AddRangeOnlyRaisesOneCollectionChangeEventForTheAdd() { var list = new ListItemCollection <string>(); var toAdd = new List <string> { "Foo", "Bar" }; var toAddSecond = new List <string> { "Foo", "Bar", "Hello" }; var eventCount = 0; IEnumerable <ListItemInnerCollection <string> > itemsAdded = null; var action = NotifyCollectionChangedAction.Reset; ((INotifyCollectionChanged)list).CollectionChanged += (s, e) => { ++eventCount; itemsAdded = e.NewItems.OfType <ListItemInnerCollection <string> >(); action = e.Action; }; list.AddRange(new List <Tuple <string, IEnumerable <string> > > { Tuple.Create("Bob", (IEnumerable <string>)toAdd), Tuple.Create("Dave", (IEnumerable <string>)toAddSecond), }); eventCount.Should().Be(1); action.Should().Be(NotifyCollectionChangedAction.Add); itemsAdded.Should().HaveCount(2); }
void Populate() { var listitems = new ListItemCollection(); listitems.AddRange(items.Select(r => r.Equals(directory.Parent) ? ".." : r.Name).Select(r => new ListItem { Text = r })); DataStore = listitems; if (!string.IsNullOrEmpty(newFileName)) { SetFileName(); } else if (olddir != null && olddir.Parent != null && olddir.Parent.Equals(directory)) { int index = items.IndexOf(olddir); if (index >= 0) { SelectedIndex = index; } } olddir = null; }
bool IPostBackDataHandler.LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection) { string str = postCollection[Configuration.HttpModule.IdPrefix + ClientID]; if (!string.IsNullOrEmpty(str)) { ListItemCollection ListaVelha = new ListItemCollection(); ListItem[] arrTemp = new ListItem[this.Items.Count]; this.Items.CopyTo(arrTemp, 0); this.Items.Clear(); ListaVelha.AddRange(arrTemp); string[] ordens = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string i in ordens) { this.Items.Add(ListaVelha.FindByValue(i)); } OnOrderChanged(); } return(true); }
public static void AddRange <T>(this ListItemCollection items, Expression <Func <T, bool> > criteria) where T : IEntity { items.AddRange((IEnumerable)Database.GetList <T>(criteria)); }
public static void AddRange <T>(this ListItemCollection items) where T : IEntity { items.AddRange((IEnumerable)Database.GetList <T>()); }
public void AddRangeOnlyRaisesOneCollectionChangeEventForTheAdd() { var list = new ListItemCollection<string>(); var toAdd = new List<string> { "Foo", "Bar" }; var toAddSecond = new List<string> { "Foo", "Bar", "Hello" }; var eventCount = 0; IEnumerable<ListItemInnerCollection<string>> itemsAdded = null; var action = NotifyCollectionChangedAction.Reset; ((INotifyCollectionChanged) list).CollectionChanged += (s, e) => { ++eventCount; itemsAdded = e.NewItems.OfType<ListItemInnerCollection<string>>(); action = e.Action; }; list.AddRange(new List<Tuple<string, IEnumerable<string>>> { Tuple.Create("Bob", (IEnumerable<string>) toAdd), Tuple.Create("Dave", (IEnumerable<string>) toAddSecond), }); eventCount.Should().Be(1); action.Should().Be(NotifyCollectionChangedAction.Add); itemsAdded.Should().HaveCount(2); }
public void AddRangeDoesntAddExistingGroups() { var list = new ListItemCollection<string>(); var toAdd = new List<string> { "Foo", "Bar" }; var toAddSecond = new List<string> { "Foo", "Bar", "Hello" }; list.AddGroup("Bob", toAdd); list.AddRange(new List<Tuple<string, IEnumerable<string>>> { Tuple.Create("Bob", (IEnumerable<string>) toAdd), Tuple.Create("Dave", (IEnumerable<string>) toAddSecond), }); list.Count.Should().Be(2); list[0].Title.Should().Be("Bob"); list[0].Should().ContainInOrder(toAdd); list[0].Should().OnlyContain(s => toAdd.Contains(s)); list[0].Count.Should().Be(2); list[1].Title.Should().Be("Dave"); list[1].Should().ContainInOrder(toAddSecond); list[1].Should().OnlyContain(s => toAddSecond.Contains(s)); list[1].Count.Should().Be(3); }
public void AddRangeAddsARange() { var list = new ListItemCollection<string>(); var toAdd = new List<string> { "Foo", "Bar" }; var toAddSecond = new List<string> { "Foo", "Bar", "Hello" }; list.AddRange(new List<ListItemInnerCollection<string>> { new ListItemInnerCollection<string>("Bob", toAdd), new ListItemInnerCollection<string>("Dave", toAddSecond), }); list.Count.Should().Be(2); list[0].Title.Should().Be("Bob"); list[0].Should().ContainInOrder(toAdd); list[0].Should().OnlyContain(s => toAdd.Contains(s)); list[0].Count.Should().Be(2); list[1].Title.Should().Be("Dave"); list[1].Should().ContainInOrder(toAddSecond); list[1].Should().OnlyContain(s => toAddSecond.Contains(s)); list[1].Count.Should().Be(3); }