New topic: Listbox horizontal scrollbar
<http://forums.realsoftware.com/viewtopic.php?t=47885> Page 1 of 1 [ 5 posts ] Previous topic | Next topic Author Message swineslife Post subject: Listbox horizontal scrollbarPosted: Wed May 15, 2013 4:50 am Joined: Wed May 15, 2013 4:29 am Posts: 6 Hello Newbie here so please be gentle. I have scanned the board/documentation regarding this - invoked some of the suggestions made previously but I cannot get the horizontal scrollbar on a listbox to work. I have just started with RS so this may be trivial but I can't work it out here's my code for a listbox in the open sub listbox1.HasHeading=true listbox1.ColumnCount=10 listbox1.width=200 listbox1.ColumnWidths="20" listbox1.ScrollBarHorizontal=true listbox1.DeleteAllRows Dim I,J as Integer for I = 0 to 20 listbox1.addrow "" for J=0 to 9 listbox1.heading(J)="Item "+str(J) listbox1.cell(I,J)="12345" next J next I In the IDE (I think it's called anyway the design mode) I set the listbox with a width of 200, visible, enabled, scrollbarhorizontal(& vertical) are checked, autohidescrollbars is unchecked. The listbox stays at width 200 but the columns are squashed into the listbox making the contents unreadable. (just a load of dots). The horizontal scrollbar is is not active - ever. The vertical scrollbar kicks in no problem, so what do I have to do to invoke the horizontal scrollbar to wake up??? Does the horizontal scrollbar actually work? This is my first play with RS and it's a pretty inauspicious start to be frank when something as seemingly as simple as this has forced me to come here to ask for help Top pfargo Post subject: Re: Listbox horizontal scrollbarPosted: Wed May 15, 2013 5:42 am Joined: Mon Oct 13, 2008 4:26 am Posts: 57 I believe you have to actually set the column widths in the IDE or code so that the sum of the widths is greater than the listbox width. If you do not then the auto sizing will force the columns to fit within the listbox width. Try this listbox1.HasHeading=true listbox1.ColumnCount=10 listbox1.width=200 'listbox1.ColumnWidths="20" listbox1.ScrollBarHorizontal=true listbox1.DeleteAllRows Dim I,J as Integer for I = 0 to 20 listbox1.addrow "" for J=0 to 9 listbox1.Column(j).WidthExpression = "25" listbox1.heading(J)="Item "+str(J) listbox1.cell(I,J)="12345" next J next I Listbox.WidthExpression in the Language Reference is helpful They key is the sum of the widths has to be wider than the listbox. Top swineslife Post subject: Re: Listbox horizontal scrollbarPosted: Wed May 15, 2013 7:24 am Joined: Wed May 15, 2013 4:29 am Posts: 6 Hi Many thanks for your reply. Yes, you have solved the mystery for when you have a listbox with known dimensions and known number of columns. That really has been helpful for me - thank you. However I note that if you add a column and resize the list box via code at runtime (even ensuring that the sum of the column widths is more than the width of the listbox) the horizontal scrollbar vanishes (well it does for me for at least). My idea was to have a listbox with the potential to span the whole width of a window. Initially there would be one column i.e a standard list box easily fitting onto the window - say listbox width 95px, column width 100px. The user would add columns of data and the listbox expand to cover the window width say 1000px. if the listbox grew anymore then the code would stop it and fix it to 1000px. The growth of the listbox width is governed by the number of fixed width columns - so for example if 9 columns of 100px were added at runtime then the listbox would be 900px and all columns shown on the 1000px window. Now if the user adds says two more columns to make the effective listbox size 1100px (i.e. 11 X 100px columns) the code would prevent the listbox from displaying as 1100px and set it to 1000px (its max). When that happens I thought the horizontal scrollbar would kick in and (in this example) column 11 is not displyed until the user scrolls across to see it (losing the first column from view). BUt each time I add a column at runtime the HSB vanishes and RS eventually reverts to squashing the columns or in other instances just showing newly added column (when using widthexpression(absolute) you suggested )without being able to view the first few columns. Hope that make sense. So the issue is how to "dynamically" invoke the HSB when certain conditions apply? Any help would be greatly appreciate and lordy lordy!....surely this is pretty standard stuff isn't it? or am I being unfair. Again thanks for the reply Top pfargo Post subject: Re: Listbox horizontal scrollbarPosted: Wed May 15, 2013 9:47 am Joined: Mon Oct 13, 2008 4:26 am Posts: 57 It is odd how it works. This may not be the easiest but it will allow you to add columns and will retain any changes you may make if your columns are set as resizable. Put a single column listbox on your window with this in the open event listbox1.HasHeading=true listbox1.width=300 listbox1.ScrollBarHorizontal=true listbox1.ColumnsResizable = true Add a button to the window and put this in the action event // add your new column Listbox1.ColumnCount = listbox1.ColumnCount + 1 // reset the existing column widths For i As Integer = 0 to Listbox1.ColumnCount - 1 listbox1.Column(i).WidthExpression = cstr(listbox1.Column(i).WidthActual) Next // set the new column width listbox1.Column(listbox1.ColumnCount).WidthExpression = "100" Should be enough to get the gears spinning! Hopefully Karen will pop in here with a simpler solution Top swineslife Post subject: Re: Listbox horizontal scrollbarPosted: Wed May 15, 2013 10:04 am Joined: Wed May 15, 2013 4:29 am Posts: 6 fantastic! this should get me going in the right direction...would never have been able to do that! works like a charm!...even with dynamically resizing the listbox many thanks Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 5 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
