473,326 Members | 2,732 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,326 software developers and data experts.

Moving item from 1 listbox to another listbox

Hi guys,

I got 2 listboxes in a window form, one on left and one on right. The
1st listbox have some items while the 2nd listbox is empty. Also there
are 2 buttons between the 2 listboxes which used to move item from/to
the 1st and 2nd listbox

My problem here is that after I bind the data to the 1st listbox (from
a dataTable, using DisplayMember and ValueMember), and I try to move 1
of the item from this 1st listbox to the 2nd listbox by:

If ListBox1.SelectedIndex <-1 Then
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End If

Item can be add to the 2nd listbox but the displayText of it becoming:

System.Data.DataRowView
Anyone can help? Thanks!! :)

Mar 20 '07 #1
3 5742
Perry,

The listbox has two methods to show items, one by using his own collection,
second by showing it from the underlying bounded collection.

They can not mix up while the second method has priority. Do you want to
achieve what you want, than you have or all the items first to set in the
listbox items and not bind or you have to move the rows in your datatables.

If it is about one datatable, than you can just add a column which tells in
what listbox it has to be.

Cor

<pe************@gmail.comschreef in bericht
news:11**********************@l77g2000hsb.googlegr oups.com...
Hi guys,

I got 2 listboxes in a window form, one on left and one on right. The
1st listbox have some items while the 2nd listbox is empty. Also there
are 2 buttons between the 2 listboxes which used to move item from/to
the 1st and 2nd listbox

My problem here is that after I bind the data to the 1st listbox (from
a dataTable, using DisplayMember and ValueMember), and I try to move 1
of the item from this 1st listbox to the 2nd listbox by:

If ListBox1.SelectedIndex <-1 Then
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End If

Item can be add to the 2nd listbox but the displayText of it becoming:

System.Data.DataRowView
Anyone can help? Thanks!! :)

Mar 20 '07 #2
Thanks for your reply Cor :)

Yea, I just got one datatable, Would you please tell me the way to
bind the data from a dataTable (which got 2 column: ID and Name. In
this case, the displaymember will be Name for Listbox1, Value will be
ID) ?

Many Thanks
On Mar 20, 4:46 pm, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Perry,

The listbox has two methods to show items, one by using his own collection,
second by showing it from the underlying bounded collection.

They can not mix up while the second method has priority. Do you want to
achieve what you want, than you have or all the items first to set in the
listbox items and not bind or you have to move the rows in your datatables.

If it is about one datatable, than you can just add a column which tells in
what listbox it has to be.

Cor

<perrycheung...@gmail.comschreef in berichtnews:11**********************@l77g2000hsb.g ooglegroups.com...
Hi guys,
I got 2 listboxes in a window form, one on left and one on right. The
1st listbox have some items while the 2nd listbox is empty. Also there
are 2 buttons between the 2 listboxes which used to move item from/to
the 1st and 2nd listbox
My problem here is that after I bind the data to the 1st listbox (from
a dataTable, using DisplayMember and ValueMember), and I try to move 1
of the item from this 1st listbox to the 2nd listbox by:
If ListBox1.SelectedIndex <-1 Then
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End If
Item can be add to the 2nd listbox but the displayText of it becoming:
System.Data.DataRowView
Anyone can help? Thanks!! :)- Hide quoted text -

- Show quoted text -

Mar 20 '07 #3
Perry,

Written here so watch typos

dim myFilterColumn as dataColumn(filter)
myDataTable.Columns.Add("myFilterColumn")
dim myDataView as new DataView(myDataTable)
dim myDataView2 as new DataView(myDataTable)
myDataView1.RowFilter = "myFilterColumn = 1"
myDataView1.RowFilter = "myFilterColumn = 2"
myDataView1(3)."myFilterColumn" = "1"
etc.

myListBox1.datasource = myDataView1
myListBox2.datasource = myDataView1
In this situation only the second name will be displayed in listbox1
<pe************@gmail.comschreef in bericht
news:11**********************@n59g2000hsh.googlegr oups.com...
Thanks for your reply Cor :)

Yea, I just got one datatable, Would you please tell me the way to
bind the data from a dataTable (which got 2 column: ID and Name. In
this case, the displaymember will be Name for Listbox1, Value will be
ID) ?

Many Thanks
On Mar 20, 4:46 pm, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
>Perry,

The listbox has two methods to show items, one by using his own
collection,
second by showing it from the underlying bounded collection.

They can not mix up while the second method has priority. Do you want to
achieve what you want, than you have or all the items first to set in the
listbox items and not bind or you have to move the rows in your
datatables.

If it is about one datatable, than you can just add a column which tells
in
what listbox it has to be.

Cor

<perrycheung...@gmail.comschreef in
berichtnews:11**********************@l77g2000hsb. googlegroups.com...
Hi guys,
I got 2 listboxes in a window form, one on left and one on right. The
1st listbox have some items while the 2nd listbox is empty. Also there
are 2 buttons between the 2 listboxes which used to move item from/to
the 1st and 2nd listbox
My problem here is that after I bind the data to the 1st listbox (from
a dataTable, using DisplayMember and ValueMember), and I try to move 1
of the item from this 1st listbox to the 2nd listbox by:
If ListBox1.SelectedIndex <-1 Then
ListBox2.Items.Add(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End If
Item can be add to the 2nd listbox but the displayText of it becoming:
System.Data.DataRowView
Anyone can help? Thanks!! :)- Hide quoted text -

- Show quoted text -


Mar 20 '07 #4

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

Similar topics

0
by: Angela | last post by:
I'm having trouble figuring out how to move a list from one listbox to another using a command button. The idea is to click on a command button and all items in listbox A will move over to listbox...
2
by: Zhang Le | last post by:
Hello, Is there a quick way to replace the content of a single item in tkinter's listbox? Currently my solution is to first delete the item, then insert a new item at the same position. I think...
2
by: Kevin Quigley | last post by:
Hi, I have an application that allows users to select items from one listbox and in doing so the item is removed from the original list and displayed in the other. I had this working in the...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
7
by: Grant Schenck | last post by:
Hello, I have a ListBox control on a form. I add members of a class to the Items collection. They show up and I can select them. The text shown is from my classes ToString override. Now,...
5
by: Kay | last post by:
Hello, I have two list boxes on my form, one initially displays with items and the other displays blank, by clicking a button, it is possible to move items from one box to another and vice a...
3
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...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
1
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.