Hi,
New to the forums and have a question. I've only been developing for about five months now so I apologize if this seems oversimplistic. ...I am writing a program on an idea I had on a whim. It's based on the fact that a store (Wal-Mart) is laid out in a logical manner and you can shop efficiently if your shopping list is in order. What I have are two listboxes, the left one contains all the items I might buy and as you double click on each item it will place it into the right listbox. What I was needing is a way to custom sort the items as they are added into the right listbox based on a few criteria (location in store and type). Here's the code I originally came up with: - Public Class Form1
-
-
-
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
-
-
ListBox2.Items.Add(ListBox1.SelectedItem)
-
ListBox1.Items.Remove(ListBox1.SelectedItem)
-
-
End Sub
-
-
-
Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.DoubleClick
-
-
ListBox1.Items.Add(ListBox2.SelectedItem)
-
ListBox2.Items.Remove(ListBox2.SelectedItem)
-
-
End Sub
-
-
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
-
-
Dim shopItems As Integer = ListBox2.Items.Count
-
Dim items As String = ""
-
-
For i As Integer = 0 To shopItems - 1
-
-
-
items &= ListBox2.Items.Item(i).ToString & vbCrLf
-
-
Next
-
-
If Not IO.File.Exists("C:\" & Today.Month & "-" & Today.Day & "-" & Today.Year & ".txt") Then
-
-
IO.File.WriteAllText("C:\" & Today.Month & "-" & Today.Day & "-" & Today.Year & ".txt", items)
-
-
Else
-
-
MsgBox("File already exists!")
-
-
End If
-
-
End Sub
-
-
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
-
-
Me.Close()
-
-
End Sub
-
-
End Class
Now, I've come up with an alternative solution by placing each type of item on a tab with two listboxes each and can then output them into a file based on which listbox group they are in, but my curiousity has been peaked and I was wondering if there is a way to do custom sorting within a listbox.
Here's the other code for the workaround: - Public Class Form2
-
-
Private Sub lbFood_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbFood.DoubleClick
-
-
lbFoodList.Items.Add(lbFood.SelectedItem)
-
lbFood.Items.Remove(lbFood.SelectedItem)
-
-
End Sub
-
-
Private Sub lbFoodList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbFoodList.DoubleClick
-
-
lbFood.Items.Add(lbFoodList.SelectedItem)
-
lbFoodList.Items.Remove(lbFoodList.SelectedItem)
-
-
End Sub
-
-
Private Sub lbToilitries_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbToiletries.DoubleClick
-
-
lbToiletriesList.Items.Add(lbToiletries.SelectedItem)
-
lbToiletries.Items.Remove(lbToiletries.SelectedItem)
-
-
End Sub
-
-
Private Sub lbToilitriesList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbToiletriesList.DoubleClick
-
-
lbToiletries.Items.Add(lbToiletriesList.SelectedItem)
-
lbToiletriesList.Items.Remove(lbToiletriesList.SelectedItem)
-
-
End Sub
-
-
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
-
-
Dim toiletryItems As Integer = lbToiletriesList.Items.Count
-
Dim foodItems As Integer = lbFoodList.Items.Count
-
Dim cleaningItems As Integer = lbCleaningList.Items.Count
-
Dim miscItems As Integer = lbMiscList.Items.Count
-
Dim items As String = ""
-
-
items &= "Toiletries (Pharmacy area): " & vbCrLf
-
-
For i As Integer = 0 To toiletryItems - 1
-
-
items &= lbToiletriesList.Items.Item(i).ToString & vbCrLf
-
-
Next
-
-
items &= vbCrLf & "Cleaning Items:" & vbCrLf
-
-
For i As Integer = 0 To cleaningItems - 1
-
-
items &= lbCleaningList.Items(i).ToString & vbCrLf
-
-
Next
-
-
items &= vbCrLf & "Food: " & vbCrLf
-
-
For i As Integer = 0 To foodItems - 1
-
-
items &= lbFoodList.Items.Item(i).ToString & vbCrLf
-
-
Next
-
-
items &= vbCrLf & "Misc Items:" & vbCrLf
-
-
For i As Integer = 0 To miscItems - 1
-
-
items &= lbMiscList.Items.Item(i).ToString & vbCrLf
-
-
Next
-
-
If Not IO.Directory.Exists("C:\Documents and Settings\All Users\Desktop\Shopping List") Then
-
-
IO.Directory.CreateDirectory("C:\Documents and Settings\All Users\Desktop\Shopping List")
-
-
End If
-
-
IO.File.WriteAllText("C:\Documents and Settings\All Users\Desktop\Shopping List\" & txtSave.Text & ".txt", items)
-
-
End Sub
-
-
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
-
-
Me.Close()
-
-
End Sub
-
-
Private Sub lbCleaning_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbCleaning.DoubleClick
-
-
lbCleaningList.Items.Add(lbCleaning.SelectedItem)
-
lbCleaning.Items.Remove(lbCleaning.SelectedItem)
-
-
End Sub
-
-
Private Sub lbCleaningList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbCleaningList.DoubleClick
-
-
lbCleaning.Items.Add(lbCleaningList.SelectedItem)
-
lbCleaningList.Items.Remove(lbCleaningList.SelectedItem)
-
-
End Sub
-
-
Private Sub lbMisc_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbMisc.DoubleClick
-
-
lbMiscList.Items.Add(lbMisc.SelectedItem)
-
lbMisc.Items.Remove(lbMisc.SelectedItem)
-
-
End Sub
-
-
Private Sub lbMiscList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbMiscList.DoubleClick
-
-
lbMisc.Items.Add(lbMiscList.SelectedItem)
-
lbMiscList.Items.Remove(lbMiscList.SelectedItem)
-
-
End Sub
-
-
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
-
lbFood.Sorted = True
-
lbCleaning.Sorted = True
-
lbToiletries.Sorted = True
-
lbMisc.Sorted = True
-
-
End Sub
-
End Class
1 1713
Question moved to .NET forum.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Marri Suliez |
last post by:
Has anyone found some documentation on how to properly subclass a ListBox
control and provide custom sorting (when the list items come from a
DataSource)?
The only way I can figure out how to do this is by sorting an array of some
sort and then setting the DataSource. I don't like this because it fires
the DataSourceChanged event.
What I really want to do is get access to the underlying list items, sort
them, and then have the...
|
by: Alex Stevens |
last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms
and microsoft.public.dotnet.framework.windowsforms.controls to no avail so
apologies for the cross-posting.
Hi,
I'm writing a usercontrol which displays the typical two listboxes and the
ability to move items from one to the other.
The listboxes are populated with my custom objects (SwapItem), which simply
|
by: Jason |
last post by:
Here is an odd issue. I am trying to shed some light on why this is causing
a problem.
I have an ArrayList. I am binding it to a ListBox control with has its Sort
property set to True. If the ArrayList only has one element in it everything
works ok. But as soon as I have more than one element, I get the following
exception when the control loads up: "Cannot modify the Items collection
when the DataSource property is set.".
Anybody...
|
by: Ali Chambers |
last post by:
Hi,
I have a bit of a problem with a sort procedure I need to do. I have a
list of items in a listbox, eg:-
2.3%<A other text here>
-4%<B other text here>
10%<C other text here>
-9.3%<D other text here>
22%<E other text here>
|
by: Leszek Klich |
last post by:
Hello All !
I have a task:
QT library:
List ListBox. I generating n random numbers from range 0 to 100. I have to
sort it by hand... It has to look nicely. It's my workhome from my school.
Sorting must visualise (preview) process in list. Any method of sorting. I
do not want to use stantard methods including to QT. I have ready: (main
window, list, slider (count elements to generic), button: generic numeric
| |
by: 00_ChInkPoIntD12 |
last post by:
Can anyone confirm there isn't a Sort() method for WebControl Listbox in
Asp.net?
It is rather simple to write a method to do the sorting, but just wondering
I shouldn't invent the wheel if there is already one.
C.P.
|
by: Joe Fallon |
last post by:
I have 2 listboxes on a Web Form.
As I move an item from 1 to the other it shows up at the end of the list.
How can I sort the list that just got the new item added to it so it is in
alphabetical order?
--
Joe Fallon
|
by: Ambica Jain |
last post by:
Hi,
I want custom sorting on some of the columns in the datagrid. And i am able
to do the same by overriding MouseDown event. However, i need to rebind my
datatable to reflect the changes in grid. And with rebinding, sorting image
(little triangle on the column header) goes away.
I need to show sorting image as well custom sorting. Please help.
Thanks
|
by: Sunray |
last post by:
I have a form called the sales form and i have 2 sets of listboxes
So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set.
when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
|
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: 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
| |
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...
| |