C#.NET ListBox.cs

 

     public void SetListBox(ListBox TargetBox, DataTable dt, int Col)
        {
            TargetBox.Items.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                TargetBox.Items.Add(dr[Col].ToString());
            }
        }

        public void MoveListBoxAll(ListBox SourceBox, ListBox TargetBox)
        {
            string tmpStr = "";
            for (int i = SourceBox.Items.Count; i > 0; i--)
            {
                tmpStr = SourceBox.Items[i - 1].ToString();
                TargetBox.Items.Add(tmpStr);
                SourceBox.Items.Remove(tmpStr);
            }
        }

        public void MoveListBoxBySelected(ListBox SourceBox, ListBox TargetBox)
        {
            int i = SourceBox.SelectedItems.Count;
            if (i == 0)
            {
                return;
            }
            string[] tmpStr = new string[i];
            int j = 0;
            foreach (string lbitem in SourceBox.SelectedItems)
            {
                tmpStr[j] = lbitem;
                j = j + 1;
            }

            foreach (string lbitem in tmpStr)
            {
                TargetBox.Items.Add(lbitem);
                SourceBox.Items.Remove(lbitem);
            }
        }

 

 

你可能感兴趣的:(listbox)