473,503 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

moving selected item

How to move up and down a selected item in listcheckedBox?

Hrcko
Apr 13 '06 #1
4 4892
Hrvoje,

You change the CheckedListBox.SelectedIndex or CheckedListBox.SelectedItem
properties.
--
HTH
Stoitcho Goutsev (100)

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:e1**********@ss405.t-com.hr...
How to move up and down a selected item in listcheckedBox?

Hrcko

Apr 13 '06 #2
On Thu, 13 Apr 2006 12:31:16 +0200, "Hrvoje Voda" <hr*********@luatech.com>
wrote:
How to move up and down a selected item in listcheckedBox?

Hrcko


// paste this code in a new windows form containing a list box
// and two buttons

private void TestDialog_Load(object sender, EventArgs e)
{
string item = "Item";

for (int i = 0; i < 10; i++)
{
clb1.Items.Add(item + i.ToString());
}
}

private void upButton_Click(object sender, EventArgs e)
{
if (clb1.SelectedIndex > 0 )
{
int ndx = clb1.SelectedIndex;
string item = (string)clb1.SelectedItem;
clb1.Items.RemoveAt(ndx);
clb1.Items.Insert(ndx - 1, item);
clb1.SelectedIndex = ndx - 1;
}
}

private void downButton_Click(object sender, EventArgs e)
{
if (clb1.SelectedIndex < clb1.Items.Count - 1)
{
int ndx = clb1.SelectedIndex;
string item = (string)clb1.SelectedItem;
clb1.Items.RemoveAt(ndx);
clb1.Items.Insert(ndx + 1, item);
clb1.SelectedIndex = ndx + 1;
}
}

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Apr 14 '06 #3
There is just one problem.
When i move a checked item a checkedstate is lost.
How can i prevent this from happening?
"Otis Mukinfus" <ph***@emailaddress.com> wrote in message
news:ti********************************@4ax.com...
On Thu, 13 Apr 2006 12:31:16 +0200, "Hrvoje Voda"
<hr*********@luatech.com>
wrote:
How to move up and down a selected item in listcheckedBox?

Hrcko


// paste this code in a new windows form containing a list box
// and two buttons

private void TestDialog_Load(object sender, EventArgs e)
{
string item = "Item";

for (int i = 0; i < 10; i++)
{
clb1.Items.Add(item + i.ToString());
}
}

private void upButton_Click(object sender, EventArgs e)
{
if (clb1.SelectedIndex > 0 )
{
int ndx = clb1.SelectedIndex;
string item = (string)clb1.SelectedItem;
clb1.Items.RemoveAt(ndx);
clb1.Items.Insert(ndx - 1, item);
clb1.SelectedIndex = ndx - 1;
}
}

private void downButton_Click(object sender, EventArgs e)
{
if (clb1.SelectedIndex < clb1.Items.Count - 1)
{
int ndx = clb1.SelectedIndex;
string item = (string)clb1.SelectedItem;
clb1.Items.RemoveAt(ndx);
clb1.Items.Insert(ndx + 1, item);
clb1.SelectedIndex = ndx + 1;
}
}

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com

Apr 14 '06 #4
On Fri, 14 Apr 2006 13:31:23 +0200, "Hrvoje Voda" <hr*********@luatech.com>
wrote:
There is just one problem.
When i move a checked item a checkedstate is lost.
How can i prevent this from happening?
"Otis Mukinfus" <ph***@emailaddress.com> wrote in message
news:ti********************************@4ax.com.. .
On Thu, 13 Apr 2006 12:31:16 +0200, "Hrvoje Voda"
<hr*********@luatech.com>
wrote:
How to move up and down a selected item in listcheckedBox?

Hrcko


// paste this code in a new windows form containing a list box
// and two buttons

private void TestDialog_Load(object sender, EventArgs e)
{
string item = "Item";

for (int i = 0; i < 10; i++)
{
clb1.Items.Add(item + i.ToString());
}
}

private void upButton_Click(object sender, EventArgs e)
{
if (clb1.SelectedIndex > 0 )
{
int ndx = clb1.SelectedIndex;
string item = (string)clb1.SelectedItem;
clb1.Items.RemoveAt(ndx);
clb1.Items.Insert(ndx - 1, item);
clb1.SelectedIndex = ndx - 1;
}
}

private void downButton_Click(object sender, EventArgs e)
{
if (clb1.SelectedIndex < clb1.Items.Count - 1)
{
int ndx = clb1.SelectedIndex;
string item = (string)clb1.SelectedItem;
clb1.Items.RemoveAt(ndx);
clb1.Items.Insert(ndx + 1, item);
clb1.SelectedIndex = ndx + 1;
}
}

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com


In your code under where I wrote "cbl.SelectedIndex = ndx + 1" set the check to
checked.

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Apr 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1215
by: Glenn | last post by:
I have a list of records in a third party grid: when an item is selected, a user control (bound to a control module level dataset) is filled with the selected record. I have another form with a...
10
10710
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
3
7358
by: Dany P. Wu | last post by:
Hi everyone, One of my Windows forms contain two listbox controls, with Add and Remove buttons between them. The idea is to allow users to select multiple items from one ListBox, click the...
3
1799
by: Michael Meckelein | last post by:
Hello, I run into trouble move down a selected item in a listbox. The code moving down the item is the following one: for (int j = lv.SelectedItems.Count-1; j >=0; j--) { ListViewItem...
1
2381
by: OwlHoot | last post by:
I am using Thomas Fuchs's amazing drag-and-drop JavaScript library available at: http://wiki.script.aculo.us/scriptaculous/show/DragAndDrop to allow the user to select a subset of items listed...
0
1398
by: Jeff Waskiewicz | last post by:
Here is what I am trying to accomplish. I have an MDI application on the left side of the client area I have a borderless form that holds a treeveiw for navigation. When an item is selected from...
1
1970
by: MayhemMickells | last post by:
Alright soo, I'm working on this program for my programming class using VB 2005 and it's driving me insane. See the program is like this. The main form has a list box for selected products and...
3
9968
by: Brian Simmons | last post by:
Hi All, I search on codeproject and google but didn't find what I was looking for. Anybody know of a good implementation where you have 2 listboxes and you want to move items between the 2. ...
4
5264
by: rsmolik | last post by:
Hi, I have a list box that allows you to select multiple values and then transfers the selected values to a table. I have almost cracked this but I am having a small problem; My code is as...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.