how to remove an item from bound listbox

Jan 25 2005 12:55 AM
i have three listbox in my window form.i.e ,Author,PrimaryAuthor,Coauthor. i have bind the arraylist in Author then i sent the selected item to Primary Author And Coauthor.but at double click event,it is very difficult for me to remove the selected item from PrimaryAuthor and coauthor listbox.can you help me. my code is as follow public class Author { private int _AuthorId; private string _AuthorName; #region Constructor public Author() { _AuthorId = 0; _AuthorName = string.Empty; } #endregion #region Accessor public int AutherID {get{ return _AuthorId; }} public string AuthorName {get{ return _AuthorName; }} #endregion #region Behavior public void SetInfo(int authorid,string authername) { _AuthorId=authorid; _AuthorName=authername; } #endregion } } --------------------------------------------------------------------------------------------------------- public class Authorlist:CollectionBase { #region Accessors public Author this[int index] { get { if(index >= 0 && index < InnerList.Count) return (Author)List[index]; else throw new IndexOutOfRangeException(); } set { if(index >= 0 && index < InnerList.Count) List[index] = (Author) value; else throw new IndexOutOfRangeException(); } } #endregion #region Behavior public int Add(Author author) { return InnerList.Add(author); } public void Remove(Author author) { InnerList.Remove(author); } #endregion } } ------------------------------------------------------------------------------------------------------------ public class GetAuthorList { public static Authorlist Execute() { Authorlist authorList=new Authorlist(); Author author=new Author(); author.SetInfo(1,"Sachin"); authorList.Add(author); author=new Author(); author.SetInfo(2,"Shibu"); authorList.Add(author); author=new Author(); author.SetInfo(3,"Ajay"); authorList.Add(author); return authorList; } ----------------------------------------------------------------------------------------------------------- form code behind: public Authorlist UIAuthorList; public Authorlist UIAuthorListLB1=new Authorlist(); public Authorlist UIAuthorListLB2=new Authorlist(); private void Authors_Load(object sender, System.EventArgs e) { // Create a new entity of the type authorlist UIAuthorList =GetAuthorList.Execute(); lstAuthors.DisplayMember="AuthorName"; lstAuthors.DataSource=UIAuthorList; } private void btn_Pri_Click(object sender, System.EventArgs e) { Author author=(Author) lstAuthors.SelectedItem; lstPrimaryAu.DataSource=null; lstPrimaryAu.Items.Clear(); lstPrimaryAu.DisplayMember="AuthorName"; UIAuthorListLB1.Add(author); lstPrimaryAu.DataSource=UIAuthorListLB1; } private void btn_Co_Click(object sender, System.EventArgs e) { Author author1=(Author) lstAuthors.SelectedItem; lstCoAu.DataSource=null; lstCoAu.Items.Clear(); lstCoAu.DisplayMember="AuthorName"; lstCoAu.ValueMember= "AutherID".ToString(); UIAuthorListLB2.Add(author1); lstCoAu.DataSource=UIAuthorListLB2; } //** i got difficulty in this double click event. private void lstCoAu_DoubleClick(object sender, System.EventArgs e) { UIAuthorListLB2.RemoveAt((UIAuthorListLB2)lstCoAu.SelectedIndex); lstCoAu.DataSource=null; lstCoAu.Items.Clear(); if(UIAuthorListLB2.Count>0) lstCoAu.DisplayMember="AuthorName"; lstCoAu.DataSource=UIAuthorListLB2; }