i want to add items from multiple listviews to other Listview (Main Listview)when i click the same button each time select diffrent item from diffrent listview how can i do this with VB.net
See the tutorial How to pass data between two forms in VB .NET
Edited by cgeier
Well I didn't get your question straight, so I will try to break it down please correct me if I'm wrong. I think you want to transfer the selected data from let's say ListView1 to ListView2 and ListView3, the ListView2 and ListView3 can be either on the same form with ListView1 or on a different form(s). Am I correct? Please enlighten me there.
Thank u mr.M for your replay what i want to do is to transfer the selected data from listv1 and listv2 to listv3
Frist item from listv1 then first item from listv2 then second item from listv1 and so on
I've tried this out using the ListView but wasn't successful, then I change from ListView to ListBox which then I managed to do what you are trying to do. With the ListView I noticed that you can't select two listviews but with Listbox you can which made it impossible at least for me to do it using the ListView.
This is what I've done with listBox:
I've added 3 ListBoxs to my form then I double clicked the ListBox1 and added these codes:
If ListBox1.SelectedIndex = 0 Then ' The first item is selected on ListView one so let's also select the corresponding item in listbox2 as well. ListBox2.SelectedIndex = 0 ' Now let's transfer the selected items to ListBox3 one item per line. ListBox3.Items.Add(ListBox1.SelectedItem.ToString) ListBox3.Items.Add(ListBox2.SelectedItem.ToString) Else If ListBox1.SelectedIndex = 1 Then ' Same as above except for the index number now. The index number to be used now is 1 End If End If
Hope this answer your question.
Meant in ListBox1 not ListView1
Thank u Mr.M for ur time and your reply and sorry for the delay it was crazy week
i beleive i didnt clear my qustion i want when i push the button first time to check if the item from listv1 not include in listv3 then add it to listv3 when i click the button second time it check the first item in listv2 if not in listv3 it add it to listv3 then when i click the button again it check the second item in listv1 and listv2 if not in listv3 it add it to listv3 and so on
thank u and best regards
Ok. About my previous post, I think you can still use the ListView. I will work this out and I hope I will post back as you asked.
Ok as I've said, I've managed to do this but there is just one problem I faced when doing this, after a lot of challenge trying to do this.
The current problem is that yes it can check the Items on ListView3 if there are the same with the selected Item in ListView1, but it can't detect the duplication of the transferred item, mean if I transfer let's say "Item1" to ListView3 because its not there it will transfer it, but if you click the same Item again which is "item1" in this case the item will be transferred again so it does not match the items that it has transferred so I think there will be someone who mite be able to solve this. Here is the code I've used. Because of slit or complication of this I've used the counts to stop it from sending many items at a time so the counts will stop this. Declare the count as a Global Integer Variable so that it will keep there the counts.
count = 0 Dim lstV1Item As String = ListView1.FocusedItem.Text count = count +1 For Each item As ListViewItem In ListView3.Items ' Let's Check if the ListView1 selected Item matches with any Item that is on the ListView3 If item.Text.ToString.Equals(lstV1Item) = True Then ' We have a match so let's stop everything and remove it from the variable so that it won't be added by any accident means. count = 0 lstV1Item = "" Else If count >= 1 Then ' I've added this because we are in a loop it was jumping and put duplicates so this prevents that and also removes the added counts so that we can be able to stop or control adding of items or transferring of items. count = -1 ' Now let's check if our variable is not null so that we won't add the blank space on our destination. If lstV1Item = "" Then ' The variable is null, this maybe a result that there was a match that was found and we cleared or freed up the variable so that we will be able to track it like this to see if there was a match or not, so here we will leave this as is, we won't do anything here because the variable is mostly empty because there was a match detected. Else ' We have passed all the above conditions so now its time we do the transfer ListView3.Items.Add(lstV1Item) End If Else ' This do bring up a message if you add a message here I think it because of the count so I just disabled the message here and made the count be 0 but it will fire again so just ignore or don't put anything here. count = 0 End If End If Next
You can copy and past this under a button and try it out. Also I have to mention this because it what I've noticed. Suppose on ListView3 you have 3 items already there, before you press the button go below the last item you will notice a blank space there, when you click the button that space will remain there, the transferred items will be added below the blank so that another thing I didn't manage to solve.
You need to set the ListView's "View" Property to List to make it a list.
Hope this helps you, and that someone maybe able to solve the problems that I couldn't.
Ow and another thing is that I did notice that you said at the first time the item should be compared between ListView1 and ListView3 then the second Time you click the button you want to compare Items between ListView2 and ListView3,
Mmmm, at least for me this is impossible to achieve the way you want it, just re-read your third post, you want to check this automatically and move automatically from the first item to the end of the items. The reason why I say this is practically impossible at least for me to achieve it, is because its so hard to track the items in the ListView, so for that you would need to use the index but now I personally didn't find it or wasn't able to use the index which was going to be a bit easy.
So the ListView I didn't see the ItemIndex and I don't know how to find it, unlike a ListBox because you would have called for the first item you would do something like this:
ListBox1.SelectedIndex = 0
So the ListView doesn't or I didn't find this which is why I say at least for me what you want to achieve is impossible for me, which is why even on the above post you first need to select an item on listview1 manually before clicking the button, there wasn't an automatic way I could do it, but I guess someone mite be able.
If you would still continue with how I did it, where you first need to select the item before clicking the button, the in order to use the same button we will just change the button text so that we will use for now, or you can declare another variable as a global variable then if the button is clicked for the first time then, assign something in that variable which will indicate that the button has been clicked for the first time, in the following code I will use the numbers to track the button click times, so you will need to take the above post code and add it under the first time button click event. Here is the structure below, suppose my variable I named it "btnClickTime" so here is the structure you can use.
btnClickTime = btnClickTime +1 If btnClickTime = 1 Then ' The button has been clicked for the first time, so take the other code on the above post and past it here. ' This will check the ListView1 and ListView3 Else If btnClickTime = 2 Then ' The button has been click twice now. ' Use the very same code, but do the appropriate changes to suite this. ' This will check between ListView2 and ListView3 ' So on the prev post code replace ListView1 with ListView2 ' I think you only need to check these, but if you have more ListViews then you will add the code following this structure. End If End If
Hope this helps out.
thank very much i will try it and let u know regarding the duplicate issue it doesn't matter because when the items finished in listv1 and listv2 it will loop again and add them again in fact what i am doing is a specail playlist creator when the user add a video file to the playlist the app automatically added an in between video file before each one from listv1 and listv2
any how i will try your code and thank u again
Ok pleasure is all mine.
Are you able to help answer this sponsored question?
Either the question asker or someone else made a financial contribution in order to feature this question and encourage quality replies.
Good day community,
I have completed vb.net program (a school timetabling program) and I am in the process to create a website. At the moment word -press on wamp server ...
I am looking for log archival utility or approach which should be able to help me in based on below policy.
(1) whenever log file (system.log) size >30859 or file ...
When split msg variable to more lines it not give me values in lines ?
msg variable in debug give me text scanning bellow
i work in windows ...