ListBox - SetHorizontalExtent

Hi,

I have a ListBox in a dialog. There are more places 
(functions) from which strings can be added to that 
listbox.

I am wondering where is the best place to put the method 
call SetHorizontalExtent, as the width of strings is know 
just at run time. I don't want to call that function from 
every place, from which a string is added to the listbox. 
I would prefer to place that function in some WM_MESSAGE 
handler, which would be called by a framework at every 
time, the string is added to the listbox. I didn't find 
such appropriate message. Can anybody tell me which 
message is the best for this purpose?

Thank you.

Regards,
Lubomir
0
anonymous (74719)
1/8/2004 7:52:05 PM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
1133 Views

Similar Articles

[PageSpeed] 7

"Lubomir" <anonymous@discussions.microsoft.com> wrote in message
news:023d01c3d620$e44376f0$a401280a@phx.gbl...
> Hi,
>
> I have a ListBox in a dialog. There are more places
> (functions) from which strings can be added to that
> listbox.
>
> I am wondering where is the best place to put the method
> call SetHorizontalExtent, as the width of strings is know
> just at run time. I don't want to call that function from
> every place, from which a string is added to the listbox.
> I would prefer to place that function in some WM_MESSAGE
> handler, which would be called by a framework at every
> time, the string is added to the listbox. I didn't find
> such appropriate message. Can anybody tell me which
> message is the best for this purpose?
>
> Thank you.
>
> Regards,
> Lubomir

I had the same problem and I ended up deriving a class from CListBox, and
overriding AddItem/InsertItem.  In those functions I had an algorithm that
would determine the length of the string before you add it.  The algorithm
would remember this number and then next time the function was called,
determine the length of that string and then compare it to that number,
always keeping the largest number.  Then I set the horizontal extent to that
number + the size of the scrollbar if it is larger than the width of the
listbox.  At least this way,  the ListBox takes care of the scrolling
itself.  Remember to override the delete & clear functions too.  Of course
you could save yourself all of this work and just replace your CListBox with
a CListViewCtrl which manages the horizontal scrollbar automatically.


0
trevor8021 (184)
1/8/2004 8:49:24 PM
Hi Lubomir!
In that situation, I change all the codes that use AddString or InsertString
with a new function that I would call AddInsert, whatever.
In that function I use AddString or InsertString and SetHorizontalExtent.
Normand

"Lubomir" <anonymous@discussions.microsoft.com> a �crit dans le message de
news: 023d01c3d620$e44376f0$a401280a@phx.gbl...
> Hi,
>
> I have a ListBox in a dialog. There are more places
> (functions) from which strings can be added to that
> listbox.
>
> I am wondering where is the best place to put the method
> call SetHorizontalExtent, as the width of strings is know
> just at run time. I don't want to call that function from
> every place, from which a string is added to the listbox.
> I would prefer to place that function in some WM_MESSAGE
> handler, which would be called by a framework at every
> time, the string is added to the listbox. I didn't find
> such appropriate message. Can anybody tell me which
> message is the best for this purpose?
>
> Thank you.
>
> Regards,
> Lubomir


0
NoEmail9920 (149)
1/9/2004 7:14:08 AM
Take a look at my listbox class that handles this automatically; it is on my MVP Tips
site. Essentially, you have to override AddString, InsertString, DeleteString, and
ResetContent, to manage the horizontal extent. Ignore WM_MESSAGE and the like. Since the
only way you would want to add items to the listbox is to call the class methods, creating
a listbox subclass and overriding these methods works perfectly.
					joe

On Thu, 8 Jan 2004 11:52:05 -0800, "Lubomir" <anonymous@discussions.microsoft.com> wrote:

>Hi,
>
>I have a ListBox in a dialog. There are more places 
>(functions) from which strings can be added to that 
>listbox.
>
>I am wondering where is the best place to put the method 
>call SetHorizontalExtent, as the width of strings is know 
>just at run time. I don't want to call that function from 
>every place, from which a string is added to the listbox. 
>I would prefer to place that function in some WM_MESSAGE 
>handler, which would be called by a framework at every 
>time, the string is added to the listbox. I didn't find 
>such appropriate message. Can anybody tell me which 
>message is the best for this purpose?
>
>Thank you.
>
>Regards,
>Lubomir

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
1/9/2004 9:58:26 AM
Hi,

Thanks for ideas.

I think it is too much work to make a new class because of 
just one method.

The best probably will be to make a new function, which 
will be called by adding a string into a Listbox.

I will use a new user message=> ::SendMessage
(m_hWndParent, MY_MESSAGE, 0, (long)pBuf);

In a handler of this message I will call 
SetHorizontalExtent and
::SendMessage(m_hWndParent, LB_ADDSTRING, 0, (long)pBuf);

Thnaks,
Lubomir
0
anonymous (74719)
1/9/2004 8:29:01 PM
Thanks for ideas.

Lubomir
0
anonymous (74719)
1/10/2004 8:53:03 PM
Thank you for ideas.

Lubomir
0
anonymous (74719)
1/11/2004 10:56:08 PM
"I think it is too much work to make a new class because of just one method" is without a
doubt one of the silliest statements I've heard in a long time. Exactly what is "too much
work"? It should take less than 5 minutes to derive this class, and in any case, the
actual effort involves downloading a class I've already created, which probably takes less
time than that.

http://www.flounder.com/hscroll.htm

It seems equally silly to call ::SendMessage directly. In other words, you are actually
doing MORE work to come up with a BAD solution than it would take to create the correct
solution!

A couple years ago I saw an equally silly message, which was amazing because I'd created
seven classes that morning, all before breakfast. Those of you who know Through The
Looking Glass will get the joke. 

Learn to use the tools in the way they are intended to be used, not create unmaintainable,
obscure kludges based on some bizarre delusion that subclassing is a lot of work. It is
the natural paradigm for extending class functionality.
				joe

On Fri, 9 Jan 2004 12:29:01 -0800, "Lubomir" <anonymous@discussions.microsoft.com> wrote:

>Hi,
>
>Thanks for ideas.
>
>I think it is too much work to make a new class because of 
>just one method.
>
>The best probably will be to make a new function, which 
>will be called by adding a string into a Listbox.
>
>I will use a new user message=> ::SendMessage
>(m_hWndParent, MY_MESSAGE, 0, (long)pBuf);
>
>In a handler of this message I will call 
>SetHorizontalExtent and
>::SendMessage(m_hWndParent, LB_ADDSTRING, 0, (long)pBuf);
>
>Thnaks,
>Lubomir

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
1/12/2004 2:19:35 AM
Reply:

Similar Artilces:

scrollbar listbox
i'm trying to get rid of the horizontal scrollbar in listbox is it even possible to do that? tia jocke --- Message posted from http://www.ExcelForum.com/ ...

filter a listbox
Hi, i have made a form where i have 4 combolistbox (named: BOX1, BOX2, BOX3, BOX4) and a listbox (Named: LIST1, it is based on a table). i want to filter the data in the listbox by selecting some filter criteria in one of the 4 combolistboxes. i have tried to find out what to do, but i can't make anything of the solutions to work. I hope someone can help me with my problem. David, Why not base your listbox on a query. Within the query you can reference the comboboxes. In the after update of the combobox you can place a me.listbox.requery which will requery the source of the listbo...

ListBox
On my form I have a combobox with a value list. After I make my selection I would like to run a query (after_update) and have it populate a list box? Is this possible and how? The query is simple and will only select one field from my table with about 20 records. Then is it possible to select certian values in this list box (may CTRL Click the ones I want) and then have a report print out based on what I selected in the list box with other selection on my form? Thanks, Sean, In the combo's AfterUpdate event, you need to add code to set the listbox's RowSource property. ...

listbox inconsistencies
I am a relatively new VBA user and this is my first post to this forum. I am using Excel 2002 sp3 with VBA (help shows VB 6.03 version 1024) on an XP sp3 machine. I have a project with one workbook that has one form - frmRecordJob. This form has a calendar control, a combo box, 2 listboxes, some labels, and 2 text boxes. The 2 list boxes (lstCode1 and lstCode2) are in a frame. lstCode2 was created by copy/paste from lstCode1. Checking their properties shows them to be identical except for the tab indices and top properties. The value and text properties are both empty, with no...

Move data between ListBoxes
I created a UserForm with two list boxes (ListBox1 & ListBox2). Right now when I show the Form ListBox1 is the only ListBox with choices inside of it. The problem I am having is that I’d like to be to be able to double click a selection from ListBox1 and have it be moved over to ListBox2. Similarly, I would like to be able to double click a selection after I have moved it to ListBox2 and have it be move back over to ListBox1. Can you help me develop the code that will perform the procedure I am trying to add to this form? see if this helps http://www.dailydose...

Populate a comboxbox and Listbox in a excel userform with an sql table data
Hi All, I have a excel userform which has some combo boxes and list boxes and I want to populate this boxes with the data which I have on my sql server database tables. Just to give an example. My first combo box is for region which needs to be populated from a sql table called Region_Mapping and my first list box should be linked to the same sql table but it should populate the countries on the basis of the region which user will select in the combo box. For eg : In my sql table I have following countries which are mapped against America 1) Argentina 2) Brazil 3) Mexico 4) Canada...

Listbox to control listbox
I have a list box with all phone numbers in it. I would like to be able to filter the listbox phone numbers by category. In other programs, I have seen two listboxes side by side and one be clickable to filter the results of the other listbox. How can I accomplish this result? Any suggestions on this would be helpful. NDClark wrote: > In other programs, I have seen two listboxes side by side and one be > clickable to filter the results of the other listbox. How can I accomplish > this result? You need: 2 tables: one containing the categories and on...

ListBox
Hi, I am trying to create one customized ListBox. 1) I have one CStatic as ListBox container and it holds one ListBox which is object of CListBox and one customized ScrollBar. 2) The picture is like, when I click on one button (which is on a dialog) , list box appears. 3) I also have some other controls on the same dialog. Now my problem is whenever I click on the portion of listbox which is overlapping with other controls it gets hide. omkar.parkhi@gmail.com wrote: > Hi, > I am trying to create one customized ListBox. > 1) I have one CStatic as ListBox container an...

How to get out of a listbox?
Hi! Need a little help please. Question, how do I terminate/close the listbox after the user made one selection? My code filling up a the listbox and calling a Userform1 Thank's ahead for any pointers. Sub slist() i = 1 For Each ws In Worksheets UserForm1.ListBox1.AddItem (Worksheets(i).Name) i = i + 1 Next ws UserForm1.Show End Sub Userform1 code:---------------------------------------- Private Sub ListBox1_Click() Sheets(UserForm1.ListBox1.Value).Select End Sub Not sure I have got the problem, but maybe try Sub slist() i = 1 Userform1.Listbox1.Clear For Each ws In Wor...

sorting a listbox
Hi, I have a listbox on a form dependant on a query called Projects. The listbox contains 6 columns and I have put 6 labels about each column which describes it and there is no set number of rows that will be displayed in the listbox. What I want to do is be able to sort the columns whenever the user clicks on the label name. I tried doing this with the macro builder but that didn't seem to work and I am only a beginner with VBA so I don't even know where to start. Thanks! Hi, would like to post the SQL string for the query Projects and the names of the 6 labels, then we could do...

Listbox UNICODE
Hi I'm writing an application with support to UNICODE, and when I show text in russian, (from an Access database), in an EditBox everything goes well, but when I want to add the same text in russian in a ListBox I see allways "|||||||" or "???????". How could I show Unicode characters in a ListBox? Thank you. Try using WideCharToMultiByte for displaying UNICODE string in List Box. Reply if works :-) "Demian" wrote: > Hi. > > I'm writing an application with support to UNICODE, and when I show text in russian, (from an Access database), in a...

listbox
I have a listbox in my Form. When I navigate to other records using the Form's navigator the listbox does not corresponds to the record. How do I make it to corresponds accordingly. Thanks in advance ChoonBoy, Use the OnCurrent event of the form to Requery your listbox. As you browse to each record, the Requery will "re-synch" the listbox according to some value on that particular record. -- hth Al Campagna Microsoft Access MVP http://home.comcast.net/~cccsolutions/index.html "Find a job that you love... and you'll never work a day in you...

What is the difference between a ListBox and ListControl??
Hi, What is actually the difference between a ListControl and a ListBox??? -- wayneschlegel ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------ >What is actually the difference between a ListControl and a ListBox??? They're totally different controls. A list box is the older simple vertical list of items (usually text). A list control is what you see in the RHS pane of Explorer. It can display its contents in various modes (such as icons, list, d...

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"}, >...

Listbox
I am trying so hard to work these things out how do I use a listbox I would like it to show the selections from a column and like it to open a corresponding workbook. Thanks in advance Greg Really a vague post, Greg. I can't tell whether the listbox is a from the Control Toolbox or the Forms toolbar. Or whether you want the list box on a userform or a worksheet. Or where the data is you want to appear in the list box. It really helps to be very specific. And also not to worry about step 2 (opening a workbook) before you get step 1 working. -- Jim Rech Excel MVP "Gre...

Listbox questions
If I add like 20 items to my userform's listbox control, how can I determine if a user selects or double clicks on item 10?? I'm just trying to figure out which event handles when an item is selected or double clicked. Thank you Assuming your listbox is ListBox1, if you use: Private Sub ListBox1_Click() MsgBox "You Selected" & Me.ListBox1.Value End Sub The above code would display a message box that tells you what selection you made, if the ListBox1 is not a multiselect type. "Robert Crandal" <nobody@gmail.com> wrote in messag...

Listbox
Bonjour, Est-il possible, dans un ListBox � plusieurs colonnes, de modifier l'alignement des donn�es. (ex. Les colonnes nombres align�es � droite et les colonnes texte avec l'alignement � gauche)? Merci pour votre aide Charles ...

Copying selected items from Listbox into Textbox #3
Many thanks Jim. :) Exactly what I was looking for -- Alan ----------------------------------------------------------------------- Alan T's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=206 View this thread: http://www.excelforum.com/showthread.php?threadid=26842 ...

listbox #2
I have a listbox which I am listing cells a1:a1000 on a worksheet called "homes". I would like the ability to have the user highlight the item in the list box and execute a code that will go to that cell. Is this possible Thanks Greg Assuming a listbox from the control toolbox toolbar, you can use the click event: Private Sub ListBox1_Click() If listbox1.ListIndex <> -1 then Range(Listbox1.Value).Select End If End Sub -- Regards, Tom Ogilvy "Greg B" <laptopgb@ihug.com.au> wrote in message news:dgejv4$nfm$1@lust.ihug.co.nz... > I have a listbox wh...

Combobox to listbox data help
I have a combobox where I want the data from the choice in the combobox to go to a listbox. Now this works on the first selection, but when I change back and forth between combobox choices it stays on the first selection like its locked into place. Essentially how do I get the listbox to reflect whatever choices I have in the combobox? Here is my code. The two tables are linked together fine. ProductName = Item (subclass) CategoryID = Class of item Item = combobox name SELECT DISTINCT Products.ProductName, Products.CategoryID FROM Products WHERE (((Products.CategoryID)=[forms]![frmMainForm]!...

Listbox scretch
Hello, I added a listbox in my main sheet. The only property changed is the "listfillrange" (linked to another sheet/range A3:A200). Each time i load the file, the listbox is smaller and smaller... How can i fix this problem ? Jean, In design mode, right click the listbox and change the IntegralHeight property to False. Does this correct the problem ? Skiffle "Jean" <Jean@discussions.microsoft.com> wrote in message news:EE9F534A-B225-495B-9EA5-CDE0B81607B1@microsoft.com... > Hello, I added a listbox in my main sheet. The only property change...

Dropdowns to Activex listboxes
Hi All, I have 8 dropdown boxes on a worksheet that reference an array (A5:A12 on a different worksheet (Player Array) and once a team is selecte form the dropdown the team members are added into the sheet auto, wha I want to do is change the dropdowns for activex listboxes so I hav more control over the properties ie: font size. How can I do this :( I can get the listboxes there but I cant seem t get them referencing the array. If you need a copy of the file pleas let me know. Any help much appreciated Thanks Ro -- Message posted from http://www.ExcelForum.com Open the Control toolbox,...

move item in multiselect listbox
Good evening, The code below, found in this group, works fine when the multiselect listbox has 1 column, Struggling to get it work when the listbox has 2 columns but without success. Grateful for some hints. Brgds CG Rosen ------------------------------------------------------------ Private Sub SpinButton1_SpinUp() If ListBox1.ListIndex <> -1 Then i = ListBox1.ListIndex If i = 0 Then Exit Sub s = ListBox1.List(i) ListBox1.RemoveItem i ListBox1.AddItem s, i - 1 ListBox1.ListIndex = i - 1 ListBox1.Selected(i - 1) = True SpinButton1.Value = 0 En...

Listbox
Hi, I have created by Issue # field to except text. The Issue # field is a primary key. With this primary key I have created a listbox. Now, through the listbox I would like to select the Issue # field and open the form (Issue-General) for only that Issue #. Private Sub Command8_Click() On Error GoTo Err_Command8_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "Issue - General" stLinkCriteria = "[Issue #]=" & Me![List6] DoCmd.OpenForm stDocName, , , stLinkCriteria Exit_Command8_Click: Exit Sub Err_Command8_Click: MsgBox Err.Description Resu...

Listbox
I have userform4 where I have put a command button and listbox on it, this is connected to a sheet called Hidden. I want to allow the user to select the text in the userbox and click on the command button to delete that certain entry on the worksheet. Is this possible, How to I acheive this to happen. Thanks in advance Greg See one response at your other thread. Greg B wrote: > > I have userform4 where I have put a command button and listbox on it, this > is connected to a sheet called Hidden. > > I want to allow the user to select the text in the userbox and click ...