Ok so I'm trying to move items from one listbox to another by using multiple buttons i.e
I have 2 buttons cmdRight and cmdRight2 which are both disabled on form load
If the user selects a single item on the first listbox a cmdRIght button enables but cmdRight2 is still disabled , if the user selects multiple items on the first listbox a cmdRight2 button enables but cmdRight is disabled.
I've got the move buttons to work but the problem I'm having is after moving multiple items with the cmdRight2 button the cmdRight button enables (which it shouldn't it should only enable after selecting a single item in the listbox). I've tried numerous if statements etc. and yet it still happens.
I'm new to C# so any help would be appreciated.
Thank You - private void lbList1_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
if (lbList1.SelectedItems != null)
-
{
-
cmdRight.Enabled = true; //enable cmdRight
-
cmdClear.Enabled = true; //enable cmdClear
-
if (this.lbList1.SelectedItems.Count > 1)//if multiple items selected
-
{
-
cmdRight.Enabled = false;
-
cmdRight2.Enabled = true; //enable cmdRight2
-
}
-
}
-
}
-
-
private void cmdRight2_Click(object sender, EventArgs e)
-
{
-
foreach (int i in lbList1.SelectedIndices)
-
{
-
lbList2.Items.Add(lbList1.Items[i].ToString());
-
}
-
while (lbList1.SelectedItems.Count > 0)
-
{
-
lbList1.Items.Remove(lbList1.SelectedItems[0]);
-
}
-
cmdRight2.Enabled = false;
-
}
-
-
private void cmdRight_Click(object sender, EventArgs e)
-
{
-
if (lbList1.SelectedItems != null)
-
{
-
lbList2.Items.Add(lbList1.SelectedItem); //Add selected item from list1 to list2
-
lbList1.Items.Remove(lbList1.SelectedItem);//remove the selected item in list1
-
-
//cmdRight.Enabled = false; //disable cmdRight
-
}
-
}
4 2622 tlhintoq 3,525
Recognized Expert Specialist TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out. tlhintoq 3,525
Recognized Expert Specialist
As you move your items, the selectedindex keeps changing...
Thus your selectedindex event handler keeps executing...
So at some point during the moving process the criteria match and the button enables.
I also worry about this
- while (lbList1.SelectedItems.Count > 0)
-
{
-
lbList1.Items.Remove(lbList1.SelectedItems[0]);
-
}
Removing items for a list starting at zero can have unexpected results.
As soon as you remove item 0, item 1 becomes item 0 - item 2 becomes item 1 and so on.
I would recommend you remove items for the END of the list first, working backward down to 0 so you don't have the elements shifting position.
Or just remove them all at once instead of one by one -
lbList1.Items.RemoveRange(lbList1.SelectedItems);
-
--------------------------------------------------------------------------------
As you move your items, the selectedindex keeps changing...
Thus your selectedindex event handler keeps executing...
So at some point during the moving process the criteria match and the button enables.
I thought this was why but I have no idea how to fix it.
tlhintoq 3,525
Recognized Expert Specialist
Just add an extra bool as a flag
AmMoving = true;
THen only enable the button if AmMoving == false;
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Philippe Meunier |
last post by:
Hi,
I am using the .NET toolbar with VB.NET 2003.
My toolbar uses icons images that are actually PNG files and uses alpha
blending on it. So to make alpha blending work correctly with the Toolbar
and the Imagelist I had to use a tricky method with API calls that is
described like this by a MS MVP :
1) Use v6 of the common controls (have a manifest)
2) Load the PNG using GDI+
|
by: Chris |
last post by:
Hi
Can you disable particular radiobuttons in a radibuttonlist control?
I know you can disable the entire radiobutton list, but I'm interested in
disabling radio buttons within the radiobuttonlist.
Thanks
Chris
|
by: inonzuk |
last post by:
Hi everyone,
I'm new to javascript and have the following problem:
I have two image buttons:
1)
<td><a href="http://localhost/gamerules.php" target="mainwindow"><img
onMouseOver="return changeRules()" onMouseOut="return
changeRulesBack()" name="b_rules" src="images/b_rules.jpg" width=130
height=90></a></td>
2)
|
by: pmelanso |
last post by:
hello,
I want to create back and forward buttons on my web page. I didn't have
a problem with that... the thing I am having trouble with is I woudl
like to display "disabled" images when there if there isn't a page to
go back/forward...how would I go about doing that???
Pam
|
by: Lyn |
last post by:
Hi,
I hope someone can help.
I have a main form which mostly fills the Access window. In the bottom half
of this form I have a tab control to display various types of data related
to the main form record. In each page of the tab control, there are three
buttons: Add, Update, Delete. Any of these buttons will open another,
smaller form to add, update or delete the related data record.
Originally, I had placed the smaller form such...
| |
by: R.Balaji |
last post by:
Hi,
We are developing a windows application using c#.
We have created a toolbar with some toolbar buttons.
When we disable the toolbar button, the toolbar button image should be
displayed as a grey image.
But currently it blackout the image.
(eg. if I put a smiley icon, then when the toolbar is disabled it just
|
by: Mark |
last post by:
This is a solution... Often users want to keep clicking "submit" when
they are waiting for server processing. Most apps these days like to
disable the submit button to prevent this. You can't just disable the
button in the OnClick event in ASP.Net because then the Click event
won't post to the server (because you disabled it). I searched google
groups, and there is a solution to this problem, but I didn't think it
was clean enough and...
|
by: dougawells |
last post by:
Hi-
I'm wanting to have a set of radio buttons disabled when a form is
displayed, then if they check another specific radio button, those
would become enabled. I've tried setting it via
window.document.formname.radiogroup.disabled="true"; (or false) - but
that doesn't seem to work. I've seen this done with text boxes, but not
with radio buttons. Can anyone give any help?
Thanks
|
by: Geoff Cox |
last post by:
Hello,
I am not at clear how to tackle this one.
Say the note middle C is played, just once.
Then when the user clicks on a play image a series of notes are played
starting with middle C and the user the user has to say whether the
last sound is the same as the first or different. There are 4 sets of
this.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |