473,657 Members | 2,800 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 4899
Hrvoje,

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

"Hrvoje Voda" <hr*********@lu atech.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*********@lu atech.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.SelectedI ndex > 0 )
{
int ndx = clb1.SelectedIn dex;
string item = (string)clb1.Se lectedItem;
clb1.Items.Remo veAt(ndx);
clb1.Items.Inse rt(ndx - 1, item);
clb1.SelectedIn dex = ndx - 1;
}
}

private void downButton_Clic k(object sender, EventArgs e)
{
if (clb1.SelectedI ndex < clb1.Items.Coun t - 1)
{
int ndx = clb1.SelectedIn dex;
string item = (string)clb1.Se lectedItem;
clb1.Items.Remo veAt(ndx);
clb1.Items.Inse rt(ndx + 1, item);
clb1.SelectedIn dex = 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***@emailadd ress.com> wrote in message
news:ti******** *************** *********@4ax.c om...
On Thu, 13 Apr 2006 12:31:16 +0200, "Hrvoje Voda"
<hr*********@lu atech.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.SelectedI ndex > 0 )
{
int ndx = clb1.SelectedIn dex;
string item = (string)clb1.Se lectedItem;
clb1.Items.Remo veAt(ndx);
clb1.Items.Inse rt(ndx - 1, item);
clb1.SelectedIn dex = ndx - 1;
}
}

private void downButton_Clic k(object sender, EventArgs e)
{
if (clb1.SelectedI ndex < clb1.Items.Coun t - 1)
{
int ndx = clb1.SelectedIn dex;
string item = (string)clb1.Se lectedItem;
clb1.Items.Remo veAt(ndx);
clb1.Items.Inse rt(ndx + 1, item);
clb1.SelectedIn dex = 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*********@lu atech.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***@emailadd ress.com> wrote in message
news:ti******* *************** **********@4ax. com...
On Thu, 13 Apr 2006 12:31:16 +0200, "Hrvoje Voda"
<hr*********@lu atech.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.SelectedI ndex > 0 )
{
int ndx = clb1.SelectedIn dex;
string item = (string)clb1.Se lectedItem;
clb1.Items.Remo veAt(ndx);
clb1.Items.Inse rt(ndx - 1, item);
clb1.SelectedIn dex = ndx - 1;
}
}

private void downButton_Clic k(object sender, EventArgs e)
{
if (clb1.SelectedI ndex < clb1.Items.Coun t - 1)
{
int ndx = clb1.SelectedIn dex;
string item = (string)clb1.Se lectedItem;
clb1.Items.Remo veAt(ndx);
clb1.Items.Inse rt(ndx + 1, item);
clb1.SelectedIn dex = 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.SelectedIn dex = 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
1225
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 different user control also bound in a similar manner with a grid lsit used to select the current record. There is also a tab on this form with another instance of the first user control that can be set to a different record then is showing on the...
10
10736
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 = true; Where endTime is a string containing "15".
3
7386
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 Add button, and the selected items will move to the second ListBox. I've been trying to use the ListBox.SelectedObjectCollection with no success. It sounds like the logical thing to use but I can't seem to find
3
1811
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 moveItem = lv.SelectedItems; selIdx = moveItem.Index; // ignore movedown of last item
1
2398
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 in one box by dragging them to another and sort them in the latter, and it works a treat. However, I'd now like to add a couple of buttons, "<<" and ">>" between
0
1406
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 the treeview it opens a seperate form. Similar to an MDI Windows Explorer. Now, I want to prevent any for form from being moved into the area occupied by the navigation form. I used the following code do do that... Private Sub...
1
1981
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 beside it is the total for all the products you selected. The other form is list box of all the products you can select it. You can choose what product you want from the products list box, press the add button, and it should send the product and the...
3
9982
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. I.e. << < >
4
5272
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 follows; Private Sub Command18_Click() Dim item
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5636
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.