C# windows - how to work with Add/Remove Lists

Posted by Madhavi under C# on 4/8/2011 | Points: 10 | Views : 6088 | Status : [Member] | Replies : 3
I am working on C# windows application. As per my requirment in the project

1) i need provide two list boxes which show available items on left and selected item on right with add / remove buttons. I want to pass selected items ( on right) to another list box which shows as readonly. Please guide me how to achieve this with code snippets. Is there any control in tool box ?

2) i want to show the status information to the user what process is going on. Ex. if it is loading something , show- Loading . If some file is opening, show - opening xyz file. I am not happy with textbox showing these status messages. Is there any better way of doing this.


Thanks in advance

Madhavi




Responses

Posted by: Karthikanbarasan on: 4/11/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi for your first query check this link...

http://www.coderanch.com/t/114274/HTML-JavaScript/passing-multiple-values-between-listbox

For your second query use a modal popup which help you to show the status each time page is loaded...

Thanks
Karthik

Thanks
Karthik
www.f5Debug.net

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: NDebata on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

As you are creating Windows Appication.

ANS 2. There is a StatusStrip Control in tool box, drag it to your form, It will be shown at the bottom of the page (dock bottom by default)
, There u can select a statuslabel in StatusStrip.

You can update the same for each mesasge u want to show.


Thanks,
Debata

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: NDebata on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

Please find the code for your first question
ADD Two listboxes named lstSource and lstDest
ADD Two Buttons named btnAdd and btnRemove in a windows form.

///////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// I am loading my list box with some sample data.
lstSource.Items.Add("Item1");
lstSource.Items.Add("Item2");
lstSource.Items.Add("Item3");
lstSource.Items.Add("Item4");
lstSource.Items.Add("Item5");
//Set these if you want to move multiple items across list boxes.
//Source List Box Name : lstSource
lstSource.SelectionMode = SelectionMode.MultiExtended;
//Destination List Box Name : lstDest
lstDest.SelectionMode = SelectionMode.MultiExtended;

}
private void btnAdd_Click(object sender, EventArgs e)
{
ListBox.SelectedObjectCollection obcol = lstSource.SelectedItems;
List<object> objlist = new List<object>();
foreach (var item in obcol)
{
lstDest.Items.Add(item);
objlist.Add(item);
}
foreach (var item in objlist)
{
lstSource.Items.Remove(item);
}
}

private void btnRemove_Click(object sender, EventArgs e)
{
ListBox.SelectedObjectCollection obcol = lstDest.SelectedItems;
List<object> objlist = new List<object>();
foreach (var item in obcol)
{
lstSource.Items.Add(item);
objlist.Add(item);
}
foreach (var item in objlist)
{
lstDest.Items.Remove(item);
}
}
}
}

Madhavi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response