Sort the contents in a Listbox

I have a CDialog where the user can type in numerical values in an Editbox and which is then added to a Listbox. My question is how I sort the contents as soon as a new value has been added? 
0
anonymous (74722)
1/20/2004 7:41:06 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
618 Views

Similar Articles

[PageSpeed] 2

Hi.
Check the "sort" option for the listbox in the dialog resource editor.
- Parhar



"Urban Olars" <anonymous@discussions.microsoft.com> wrote in message
news:8FD6A3C2-D59D-4486-8ABF-47E5B6BAC262@microsoft.com...
> I have a CDialog where the user can type in numerical values in an Editbox
and which is then added to a Listbox. My question is how I sort the contents
as soon as a new value has been added?


0
os_parhar (20)
1/20/2004 7:49:10 AM
Calculate the position of the new value in the sorted list, BEFORE adding it to the list box and then you can add the new value using CListBox::InsertString() and insert it in the required spot.

-Animesh

0
anonymous (74722)
1/20/2004 7:51:06 AM
"Urban Olars" <anonymous@discussions.microsoft.com> wrote in message
news:8FD6A3C2-D59D-4486-8ABF-47E5B6BAC262@microsoft.com...
> I have a CDialog where the user can type in numerical values in an Editbox
and which is then added to a Listbox. My question is how I sort the contents
as soon as a new value has been added?

Use the LBS_SORT style for the list box, then it will be sorted
automatically (alphabetically).
Check the help files.

Tom.


0
1/20/2004 10:00:47 AM
I just want to point out something here.
Tom and Parhar's solutions are valid ones, but keep in mind that the listbox
with LBS_SORT flag sorts things as text. So things would look list this
1
12
15
116
2
21
239849
3

instead of
1
2
3
12
15
21
116
239849

If you want them to be sorted in numerical value you might want to store all
your values in a CWordArray get rid of the LBS_SORT on the Listbox, sort the
CWordArray, and add them to the list in the order that you want. to keep
things from flickering you can call the listbox's LockWindowsUpdate and
UnlockWindowsUpdate around the code that empties the listbox and fills it
back in.

Ali R.

"Urban Olars" <anonymous@discussions.microsoft.com> wrote in message
news:8FD6A3C2-D59D-4486-8ABF-47E5B6BAC262@microsoft.com...
> I have a CDialog where the user can type in numerical values in an Editbox
and which is then added to a Listbox. My question is how I sort the contents
as soon as a new value has been added?


0
nospam7515 (2084)
1/20/2004 4:24:41 PM
Reply:

Similar Artilces:

Sorting data based on quarters of the year
Hi Not quite sure of the best way to approach this problem I need to filter the data in the table below into quarters Jan-Mar Apr-Jun Jul-Sept Oct-Dec For each quarter i need to find the change in values,i need to subtrac the open price in each quarter(Jan,Apr,Jul,Oct) from the closing pric at the end of each quarter(Mar,Jun,Sept,Dec) So for the latest quarter shown at the top of the table Apr-Jun(04), the open in April would be 4,385.70 which i would like to subtract fro the close in June 4,487 , 4,487-4,385.70 = 101.3 So for Apr-Jun(04) the market gained 101.3 Date-----Open-- Close...

Highlighted email changes when I sort by subject
Don't believe it's related to the number of messages we have a user experiencing the same problem the have over 1500 and the behavior is random..... EggHeadCafe.com - .NET Developer Portal of Choice http://www.eggheadcafe.com Stony Curtis wrote: > Don't believe it's related to the number of messages we have a user > experiencing the same problem the have over 1500 and the behavior is > random..... > > > EggHeadCafe.com - .NET Developer Portal of Choice > http://www.eggheadcafe.com Please be aware that this "egghead cafe" is just a front fo...

coallating designator and sort order
Hi, in 2005 MS SQL , how can I see coallating designator and sort order of my instance ? Thanks. big (big@discussions.microsoft.com) writes: > in 2005 MS SQL , how can I see coallating designator and sort order of my > instance ? SELECT serverproperty('Collation') Note that the collation can be over-ridden on database level and eventually on column level. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 20...

alternate sort on different columns
I try to sort a spreadsheet (Excel 2003) alternatively in two different ways, independent of each other. It means, if a certain condition is met, the data should be sorted on column A, if the other condition is met, it should be sorted on column D. Right now I have the problem that Excel remembers the previous sort (that is, if I first sorted on column D, the next sort on column A keeps the previous sort on D - which I don't want. How can I undo the previous sort? Aurora ...

duplicated content-type name
We have a exchange 2000 server with sp3. Every time when I send a mail, the content-type name in header will be duplicated. Is there anyone can help me Thanks! ...

Listbox problem
I have the following code setup. My form has 5 listboxes on them named LB1 thru LB5. All listboxes are single select. The code simply captures which listbox has been clicked (onClick event) then it does some stuff (not included in following code) and finally deselects the entry in the listbox. It's giving me fits. It will not deselect the entry. Can anyone tell me what I'm doing wrong? thanks Dim ctlCurrentControl As Control Dim strControlName As String Dim intCurrentRow As Integer Dim tmp_selected As Integer Set ctlCurrentControl = Screen.Ac...

Tricky
Hi All, I have a tricky excel macro opportunity..... My sheet(s) consist of sales data for a number of companies, populating columns A through to O. Column A lists company names. Column M lists Sales $ achieved. Within column A, there may be a group of identical entries (company names) that are differentiated somewhere else in the sheet. What I would like to do is sort by group of companies first, so the group of like named companies in column A with the greatest aggregate total of sales in column M should be listed at the top of the sorted list then each of the comanies within the gr...

Grouped/Sorted Report by Month
I have a fairly simple access database. I've created a report grouped by Category and Month... with a total per month. My problem is that the months with no total don't show on the report. Is there a way to make the month show with a zero total? ie. January - 24 orders February - 30 orders March - 0 orders April - 28 orders ********This is what I'd like to see ... each month listed. Currently, March doesn't show at all on my report. Any help would be appreciated. SCS wrote: >I have a fairly simple access database. I've create...

Populate Excel Listbox
Hi, I'm using this piece of code to populate an excel userform listbox with the name of each worksheet in a workbook i = 1 For Each ws In Worksheets Worksheets.Select Sheets(i).Activate ListBox1.AddItem (ActiveSheet.Name) i = i + 1 Next ws Is there a better way I can do this as this could visable activates each sheet each time the listbox is repopulated. Thanks ...pc i = 1 For Each ws In Worksheets ListBox1.AddItem (Worksheets(i).Name) i = i + 1 Next ws -- HTH RP (remove nothere from the email address if mailing direct) "PC" <paulm do...

Sorting in different culture
Hi! When we sort for example an array of char it's the numeric value for the character that is used to decide which one is greater then the other. But my question is if we look at other language and culture how is the sorting done there is it based on the numeric value for the character to decide which character is greter then another. I mean in english if we have the character cba it could have been implemented without using the numeric values for the character. So the sorting of cba might have given bac. //Tony Tony Johansson wrote: > Hi! > > When...

PO Printing Problem (sorting)
We recently upgraded to RMS 1.3 from 1.2. When printing a purchase order, I prefer to have the PO sorted by Order No. rather than lookup code (usually a worthless barcode). This makes it vastly easier for my distributors to input these. However, since the upgrade, when I hit print, RMS re-sorts the PO by lookup code. Is there a way to stop this from happening? Under General Options there's a "Don't Remember List Sorts" check box, but this doesn't effect the problem. Thanks! Gary Ray Black Diamond Games Concord, CA gray(at)blackdiamondgames. com This is a multi-part m...

Sorting alphanumeric #3
I've been searching through several old topics on alphanumeric sorts and have not seen any problem that resembles mine. So, any help is appreciated. I have a worksheet with several columns (~10). I am currently sorting this worksheet based on three columns (e.g. A then B then C). Column A is a text-formatted family name for a group of data within the worksheet. Column B is a family number. This further breaks down the families into "subfamilies," if you will, based on the family numbers. The final column is each item's name, which are alphanumeric. Here is a very crude...

Cell content surrounded by quotes when saving as tab delimited for
When performing a "Save as" a "Tab (delimited)" file in Excel 2000, cells contents that contain a comma are automatically surrounded by double quotes ("). Is there a way to save a file in tab delimited format without Excel automatically encapsulating text data that contain commas with double quotes? This appears to be a known issue, but I have not been able to find a solution. Tried to open the saved file in Note Pad and perform a find and replace, but the file is too big and consequently freezes application. Thanks, Jerry Supplemental: Found a Microsoft Know...

File exeed the 2GByte of size when I EDIT blob column contents
Hi! I edit a table column (type of OLE object) in a loop (all record) with DAO CdbRecordset. The columns contents will decrease with 12 byte. The size of the (Access 2000 type) mdb file at the beginning is 1 GByte and it grown to 2 GByte (and the program stop with error). Why grown the file of size if I edit its content and decrease it? Thanks for any idea. Imre ...

Sorting Data in a column
I am trying to extract data that is in a single column to split it into 3 columns. The data is cyclic and has 3 variables, a time, a data point and a random number. These simply run abcabcabcabc down the column and i would like to get all of the a's into a column, all of the b's into another column and all of the c's into a third column. any ideas? VBA? Sub Test() Dim iLastRow As Long Dim i As Long iLastRow = Cells(Rows.Count, "A").End(xlUp).Row If iLastRow Mod 3 <> 1 Then iLastRow = iLastRow - 1 If iLastRow Mod 3 <> 1 Then iLastRow = iLa...

populating a listbox...
Hello, Using VC++6 MFC, I want to populate a listbox with the following array: char * MyStrigs[] = { {"String1"}, {"String2"}, {"String3"}, {"0"} }; How would I do this? What CListbox function would I use? Thanks, RABMissouri RAB wrote: > Hello, > > Using VC++6 MFC, I want to populate a listbox with the following array: > > char * MyStrigs[] = > { > {"String1"}, > {"String2"}, > {"String3"}, >...

Content library problem
Hi all - Publish 2007. I write a newsletter twice a year. Since I use many of the same elements on the back page every time, I erased the volatile areas, then did a Save All on the page, and added it to the Content Library. But when I bring the page back in from the Content Library to a new, blank page, the paragraph spacing on the paragraphs has changed and left me with text boxes in an overflow condition. Am I doing something wrong? Craig Maybe saving the newsletter as a template would be better. I tried to duplicate your problem but could not. I selected all, grouped and then add...

How to get Cell contents in scrollbar mouseover, not cell#
Hello all - I have a large Xcel 2000 file with last names in column 'A'. I'd like to use the scroll bar and see the actual cell value rather than the cell# in the mouseover, as the cell# is not terrifically valuable information. Any hints or insights would help. Thanks and regards, Bob ...

ListBox and H Scroll
I have a ListBox on a form that was designed in VC6 resource editor. I asked for H and V scroll. Regardless of the length of the items in the list box the H scrollbar never appears. If I check the no show, then the HScroll is grayed out. I have several long strings for which scrolling would be useful. Thanks. Thomas Take a look at my automatic-HScroll listbox on my MVP Tips site. You have to send a WM_SETHORIZONTALEXTENT message to make it work, and my listbox class does this automatically. joe On Sat, 26 Jul 2003 12:03:28 -0400, Thomas <nospam@nospam.com> wrote: >I ...

sort mail group
How do I sort my names in a contact group by surname first. oldzac Have you tried clicking on the surname column header? --=20 Gary VanderMolen, Microsoft MVP (Mail) http://mvp.support.microsoft.com/default.aspx/profile/vandermolen "oldzac" <oldzac@ozemail.com.au> wrote in message = news:%23M3G%23nYZKHA.4932@TK2MSFTNGP02.phx.gbl... > How do I sort my names in a contact group by surname first. > oldzac When I open up the group there is no column header. I must be doing something wrong. oldzac "Gary VanderMolen" <gary@NoMail.invalid> ...

Sorting by number in a non-numeric field
Hi guys.. so question.. Say I have a row with example: Building1-PC1 Building2-PC1 Building3-PC1 Building1-PC2 Building2-PC2 Building3-PC3 Building1-PC100 Building2-PC100 Building3-PC100.. Desired result from a sort.. Building1-PC1 Building1-PC2 Building1-PC3 Building2-PC1 Building2-PC2 Building2-PC3 Building3-PC1 Building3-PC2 Building3PC-3 Now how do I get there? :P -- kronik ------------------------------------------------------------------------ kronik's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=31541 View this thread: http://www.excelforum.com/s...

Email Message Content Reading
Hi, I am an internal auditor and would like to find out whether is it possible for an email administrator to read the message content of a user? If possible, how and whether anyway to block it? Thank you Its depends on what they are connecting to, if Exchange then yes "Daniel Phua" <danielphua@interpac.com.my> wrote in message news:09bd01c34a1e$fca7de40$a401280a@phx.gbl... > Hi, I am an internal auditor and would like to find out > whether is it possible for an email administrator to read > the message content of a user? If possible, how and > whether anyway to...

Best Practise to Archive Public Folder Content
Hi everybody, sorry if this has already been answered a 100 times already, but as a newbie I need some advice in this area. What do people recommend as best practise/tools to archive content from Exchange 2003 Public Folders that will allow them to be recovered/restored at some time in the future if required. TIA, Colin Strain. Microsoft Journaling does not capture Public Folder items. You could mail-enable the public folders and that way journaling should collect the data. Then you just need an archiving solutions to collect and archive the journaled messages. Try looking at Connected ...

Moving Formulas when Sorting
Hi All & Happy Christmas & New year, How can I sort a table and have the formulas move to the relevant new postition? I'm working on a World Cup spreadsheet so I've got each table as follows a b c d e f g h i P W D L F A Pts GD Team A Team B Team C Team D The fixtures are below the table and this is where each teams results are from in the table. EG. In cell C2 (Team A Won) the formula is =SUM(A11+A15+K21) In cell D2 (Team A Draw) =SUM(B11+B15+L21) These formulas...

sorting data from pull down menus
everything explained in attachment with example Attachment filename: example3.xls Download attachment: http://www.excelforum.com/attachment.php?postid=64865 -- Message posted from http://www.ExcelForum.com Hi Pyzikchr it's better to ask your question by typing out an example or two in your posts, most ng readers will not open attachments because of the risk of viruses etc ... bascially in this situation you need to use the SUMIF function so for E9 type =SUMIF($C$4:$D$7,C9,$E$4:$E$7) where =SUMIF(range_to_check_for_criteria, criteria, range_to_sum) you ca...