473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Listbox problem

Dear Group,
I am doing Drag and Drop function and see this problem
if I select 3 from listBox1 and drag to listBox2, the value in listBox1 is
not updated, even I move (or use up and down keyboard) to select number 4,
the selectedItem.ToString() still shows 3
Am i doing something wrong?

Here is the file
****
using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

namespace Controls

{

/// <summary>

/// Summary description for Dragdrop.

/// </summary>

public class Dragdrop : System.Windows.Forms.Form

{

private System.Windows.Forms.ListBox listBox2;

private System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.TextBox textBox2;

private System.Windows.Forms.ListBox listBox1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Dragdrop()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.listBox2 = new System.Windows.Forms.ListBox();

this.textBox1 = new System.Windows.Forms.TextBox();

this.textBox2 = new System.Windows.Forms.TextBox();

this.listBox1 = new System.Windows.Forms.ListBox();

this.SuspendLayout();

//

// listBox2

//

this.listBox2.AllowDrop = true;

this.listBox2.Location = new System.Drawing.Point(232, 32);

this.listBox2.Name = "listBox2";

this.listBox2.Size = new System.Drawing.Size(112, 160);

this.listBox2.TabIndex = 1;

this.listBox2.DragDrop += new
System.Windows.Forms.DragEventHandler(this.listBox 2_DragDrop);

this.listBox2.DragEnter += new
System.Windows.Forms.DragEventHandler(this.listBox 2_DragEnter);

this.listBox2.SelectedIndexChanged += new
System.EventHandler(this.listBox2_SelectedIndexCha nged);

//

// textBox1

//

this.textBox1.Location = new System.Drawing.Point(136, 56);

this.textBox1.Name = "textBox1";

this.textBox1.Size = new System.Drawing.Size(72, 20);

this.textBox1.TabIndex = 2;

this.textBox1.Text = "textBox1";

//

// textBox2

//

this.textBox2.Location = new System.Drawing.Point(136, 88);

this.textBox2.Name = "textBox2";

this.textBox2.Size = new System.Drawing.Size(72, 20);

this.textBox2.TabIndex = 3;

this.textBox2.Text = "textBox2";

//

// listBox1

//

this.listBox1.Location = new System.Drawing.Point(8, 40);

this.listBox1.Name = "listBox1";

this.listBox1.Size = new System.Drawing.Size(120, 134);

this.listBox1.TabIndex = 4;

this.listBox1.MouseDown+=new MouseEventHandler(listBox1_MouseDown);

this.listBox1.SelectedIndexChanged +=new
EventHandler(listBox1_SelectedIndexChanged);

//

// Dragdrop

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(368, 214);

this.Controls.Add(this.listBox1);

this.Controls.Add(this.textBox2);

this.Controls.Add(this.textBox1);

this.Controls.Add(this.listBox2);

this.Name = "Dragdrop";

this.Text = "Dragdrop";

this.Load += new System.EventHandler(this.Dragdrop_Load);

this.ResumeLayout(false);

}

#endregion

private void listBox2_SelectedIndexChanged(object sender, System.EventArgs
e)

{
}

private void listBox2_DragEnter(object sender, DragEventArgs e)

{

if (e.Data.GetDataPresent(typeof(string)))

{e.Effect=DragDropEffects.Move ; }

else

{e.Effect=DragDropEffects.None;}

}

private void listBox2_DragDrop(object sender,DragEventArgs e)

{

listBox2.Items.Add((string)e.Data.GetData(typeof(s tring)));

}

private void Dragdrop_Load(object sender, System.EventArgs e)

{

this.listBox1.Items.Add("1");

this.listBox1.Items.Add("2");

this.listBox1.Items.Add("3");

this.listBox1.Items.Add("4");

}

private void listBox1_MouseDown(object sender,MouseEventArgs e)

{

try

{
textBox1.Text = listBox1.SelectedIndex.ToString();

textBox2.Text=listBox1.Items[listBox1.SelectedIndex].ToString();

DragDropEffects effect =
listBox1.DoDragDrop(listBox1.Items[listBox1.SelectedIndex].ToString(),DragDr
opEffects.Move);

if (effect ==DragDropEffects.Move)

{

listBox1.Items.RemoveAt(listBox1.SelectedIndex);

}

}

catch{};

}

private void listBox1_SelectedIndexChanged(object sender, System.EventArgs
e)

{

textBox1.Text = listBox1.SelectedItem.ToString();

}

//private void DoDragDrop(string

}

}

***

TIA

L.Peter
Nov 16 '05 #1
0 1419

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

Similar topics

5
by: Brian | last post by:
Hi, All, I'm using MS.net 2003 and using a windows.forms.listbox control for my window application but I don't know why the Horizontal Scrollbar could NOT be shown even if I set...
5
by: Bill | last post by:
I have have two list boxes. One is a listing of all possible variables. We'll call this listbox A. The other is a listing of all the selected variables. We'll call this listbox B. If a person...
2
by: Simon P | last post by:
Hello group, I'm in desperate need of help. Here goes : I have the following tables : CONTACTS (ContactID, FirstName, LastName, Company, etc.), SHOWS (ShowID, ShowDescription) and SHOWDETAILS...
1
by: Josema | last post by:
Hi to all, I have a class (persons) that derives from collection base: and another class (person) with this properties: -ID -Name When i have complete filled the object Persons with all...
1
by: MrNobody | last post by:
Hi, I'm doing something where I add custom objects to a ListBox which have aToString() method overriden so it displays what I want. When adding instances of these custom objects to the ListBox I...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
4
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you...
8
by: nirdeshonline | last post by:
Hi, I have added a simple listbox in windows form under c# 2.0. It contains a collection of approx 10 strings as list items. Now when i resize the form whole listbox flickers. Please tell me...
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
15
by: Doogie | last post by:
I have a .net app that a user currently enters a number in a text box, hits a button and a data call is executed. She wants the ability to enter in multiple numbers (up to 100). So to make...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.