You are on page 1of 4

[CODE]if ((ListBox1.SelectedItems.Count == 0)) { ListBox2.Items.AddRange(ListBox1.Items); ListBox1.Items.Clear(); } else { for (Int16 i = 0; (i <= (ListBox1.SelectedItems.Count - 1)); i++) { ListBox2.Items.Add(ListBox1.SelectedItems(i)); ListBox1.Items.Remove(ListBox1.

SelectedItems(i)); } }[/CODE]

In appropriate event write if (ListBox1.Items.Count == 0 ) { Response.Write("No item to move"); } string itemremoved = ListBox1.SelectedItem.Text; ListBox1.Items.Remove(itemremoved); ListBox2.Items.Add(itemremoved);

public void addListView() { ListView newListView = new ListView(); newListView.AllowDrop = true; newListView.DragDrop += listView_DragDrop; newListView.DragEnter += listView_DragEnter; newListView.MouseDoubleClick += listView_MouseDoubleClick; newListView.MouseDown += listView_MouseDown; newListView.DragOver += listView_DragOver; newListView.Width = 200; newListView.Height = 200; newListView.View = View.Tile; newListView.MultiSelect = false; flowPanel.Controls.Add(newListView); numWO++; numberofWOLabel.Text = numWO.ToString(); }

[Category("Custom User Controls")] public class ListBoxWithTitle : ListBox { private Label titleLabel; public ListBoxWithTitle() { this.SizeChanged +=new EventHandler(SizeSet); this.LocationChanged +=new EventHandler(LocationSet); this.ParentChanged += new EventHandler(ParentSet); } public string TitleLabelText { get; set; } //Ensures the Size, Location and Parent have been set before adding text bool isSizeSet = false; bool isLocationSet = false; bool isParentSet = false; private void SizeSet(object sender, EventArgs e) { isSizeSet = true; if (isSizeSet && isLocationSet && isParentSet) { PositionLabel(); } } private void LocationSet(object sender, EventArgs e) { isLocationSet = true; if (isSizeSet && isLocationSet && isParentSet) { PositionLabel(); } } private void ParentSet(object sender, EventArgs e) { isParentSet = true; if (isSizeSet && isLocationSet && isParentSet) { PositionLabel();

} } private void PositionLabel() { //Initializes text label titleLabel = new Label(); //Positions the text 10 pixels below the Listbox. titleLabel.Location = new Point(this.Location.X, this.Location.Y + this. Size.Height + 10); titleLabel.AutoSize = true; titleLabel.Text = TitleLabelText; this.Parent.Controls.Add(titleLabel); } }

using System; namespace MyLB { /// <summary> /// Summary description for Class1. /// </summary> public class MyListBox:System.Windows.Forms.ListBox { public System.Windows.Forms.ProgressBar progress = new System.Windows.Fo rms.ProgressBar(); public MyListBox() { this.Controls.Add(progress); this.Resize+=new EventHandler(MyListBox_Resize); } private void MyListBox_Resize(object sender, System.EventArgs e) { Invalidate();

} } }

Next, in the project were you want to use this control, add this new control, na med MyListBox in the ToolBox tab. ToolBox->Add/Remove Item->Browse and locate the MyLB.dll. You should see a new c ontrol in the selected tab. Now, drag it on your form as a regular control. You should see a rectangle in th e listbox. Add the following code to see the ProgressBar working inside of the listbox: CODE private void TestProgressBar2(int num) { this.myListBox1.progress.Visible = true; myListBox1.progress.Minimum = 1; myListBox1.progress.Maximum = num; myListBox1.progress.Value = 1; myListBox1.progress.Step = 1; // Loop through for (int x = 1; x <= num; x++) { myListBox1.progress.PerformStep(); System.Threading.Thread.Sleep(1000); } this.myListBox1.Items.Add("blablabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); } You have to decide where to show the ProgressBar inside of the ListBox and how t o handle the area when adding/removing items from the listbox. -obislavu-

You might also like