Move the checkeditem from checkbox list to another checkbox

Posted by Murugavelmsc under C# on 9/12/2013 | Points: 10 | Views : 4622 | Status : [Member] | Replies : 4
Hi Expert,

I have developing a windows application with two checkboxlist and button.

select the item from checkbox list 1 and click button means it move to another checkboxlist with checkstatus

Please help me...

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/



Responses

Posted by: Bandi on: 9/12/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
If you want to move checked checkedlistbox items to listbox you can do as follows:
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 CheckedListBoxSample
{
public partial class Form1 : Form
{
private System.Windows.Forms.CheckedListBox inputCheckedListBox;
private System.Windows.Forms.ListBox displayListBox;

public Form1()
{
this.inputCheckedListBox = new System.Windows.Forms.CheckedListBox();
this.displayListBox = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// inputCheckedListBox
//
this.inputCheckedListBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.inputCheckedListBox.FormattingEnabled = true;
this.inputCheckedListBox.Items.AddRange(new object[] {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H"});
this.inputCheckedListBox.Location = new System.Drawing.Point(17, 12);
this.inputCheckedListBox.Name = "inputCheckedListBox";
this.inputCheckedListBox.Size = new System.Drawing.Size(202, 188);
this.inputCheckedListBox.TabIndex = 0;
this.inputCheckedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.inputCheckedListBox_ItemCheck);
//
// displayListBox
//
this.displayListBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.displayListBox.FormattingEnabled = true;
this.displayListBox.ItemHeight = 20;
this.displayListBox.Location = new System.Drawing.Point(236, 12);
this.displayListBox.Name = "displayListBox";
this.displayListBox.Size = new System.Drawing.Size(190, 184);
this.displayListBox.TabIndex = 1;
//
// CheckedListBoxTestForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(438, 211);
this.Controls.Add(this.displayListBox);
this.Controls.Add(this.inputCheckedListBox);
this.Name = "CheckedListBoxTestForm";
this.Text = "CheckedListBoxTest";
this.ResumeLayout(false);
}
private void inputCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
{
string item = inputCheckedListBox.SelectedItem.ToString();

if (e.NewValue == CheckState.Checked)
displayListBox.Items.Add(item);
else
displayListBox.Items.Remove(item);
}

}
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Satyapriyanayak on: 9/12/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
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 checkbox_list
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
checkedListBox2.Items.Add(checkedListBox1.SelectedItem);
int i = 0;
i = checkedListBox1.SelectedIndex;
checkedListBox1.Items.RemoveAt(i);
}

private void Form1_Load(object sender, EventArgs e)
{
checkedListBox1.Items.Add("Raj");
checkedListBox1.Items.Add("Ravi");
checkedListBox1.Items.Add("Rahul");
checkedListBox1.Items.Add("Raju");
checkedListBox1.Items.Add("Rohit");
checkedListBox1.Items.Add("Rajesh");
}
}
}


If this post helps you mark it as answer
Thanks

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

Posted by: Bandi on: 9/12/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Drag, Drop and Move Items from One CheckedListBox to Another using Windows Forms
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 CheckedListBoxEx
{
public partial class Form1 : Form
{
int itemIndex;

public Form1()
{
InitializeComponent();
checkedListBoxA.MouseDown += new MouseEventHandler(checkedListBox_MouseDown);
checkedListBoxA.DragOver += new DragEventHandler(checkedListBox_DragOver);
checkedListBoxA.DragDrop += new DragEventHandler(checkedListBox_DragDrop);
checkedListBoxB.MouseDown += new MouseEventHandler(checkedListBox_MouseDown);
checkedListBoxB.DragOver += new DragEventHandler(checkedListBox_DragOver);
checkedListBoxB.DragDrop += new DragEventHandler(checkedListBox_DragDrop);
checkedListBoxA.AllowDrop = true;
checkedListBoxB.AllowDrop = true;
}

private void Form1_Load(object sender, EventArgs e)
{
checkedListBoxA.Items.Add("Item 1");
checkedListBoxA.Items.Add("Item 2");
checkedListBoxA.Items.Add("Item 3");
checkedListBoxA.Items.Add("Item 4");
checkedListBoxA.Items.Add("Item 5");
checkedListBoxA.Items.Add("Item 6");
}

private void checkedListBox_MouseDown(object sender, MouseEventArgs e)
{
CheckedListBox clb = sender as CheckedListBox;
itemIndex = clb.IndexFromPoint(e.X, e.Y);
if (itemIndex >= 0 & e.Button == MouseButtons.Left)
{
clb.DoDragDrop(clb.Items[itemIndex], DragDropEffects.Move);
}
}

private void checkedListBox_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(System.String)))
{
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
}

private void checkedListBox_DragDrop(object sender, DragEventArgs e)
{
CheckedListBox clbSender = sender as CheckedListBox;
clbSender.Items.Add(e.Data.GetData(typeof(System.String)).ToString());

if (clbSender.Name == "checkedListBoxA")
checkedListBoxB.Items.RemoveAt(itemIndex);
else
checkedListBoxA.Items.RemoveAt(itemIndex);
}



}
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Bandi on: 9/26/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
"Mark As Answer"

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Login to post response