Indenting a list box (1 Viewer)

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
I bet this is something you just don't do.
My list of items is in groups with a Title. I'd like to indent the non-title rows as per the attached image.
The click event is wanted for each row so I have used a listbox but leading spaces are ignored. Would some other control be better?
I intend to learn about Reports but as yet know nothing... do they have a click event?
Thanks
 

Attachments

  • demo.jpg
    demo.jpg
    39.6 KB · Views: 78

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:51
Joined
Oct 29, 2018
Messages
17,177
Hi. Could you use non-breaking spaces or some other non-alphanumeric characters like the dash or asterisk?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:51
Joined
May 7, 2009
Messages
14,648
instead of listbox you can use a continuous form.
 

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
Only as a last resort What does a non breaking space appear as?
I've also just found the additem command does not all the whole item. Only so much of it. Unless it's just a width setting.
 

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
Hmm, thanks arne. The listbox is already on a Form. So I'd remove it and change the form.
Will have a go... have never used thsi type of form before. Do I have a text box for every line?
 

moke123

AWF VIP
Local time
Today, 01:51
Joined
Jan 11, 2013
Messages
2,603
Chr(160) is a non-breaking space.
You can also use a combination of Chr(160) & space(25) if you want to add many spaces.
 
Last edited:

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
Thanks for info about non breaking space.
Arne I have a continuous Form (Form 2) and have set it's RS to a table with a text box bound to the single field. Form width is 13cm
and Height 6cm. When run, nothing shows in the Form, except the Header. If I open Form2 by itself I see the attached... so the data is there. But what are the large height rows, and is this impacting my smaller Form ?
 

Attachments

  • ss1.jpg
    ss1.jpg
    53.6 KB · Views: 75

MajP

You've got your good things, and you've got mine.
Local time
Today, 01:51
Joined
May 21, 2018
Messages
5,690
indent.jpg

In the query use the String(N," ") function & concatenate
 

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
Thanks Moke that was a big help. But still not quite right, what are the alternating gray and yellow lines and how do I remove them? The actual data rows need the backcolor set but want to tidy it first. Then, must each row be the same forecolor?
MajP I'm lost. What query and what is String(N, "") ?
 

Attachments

  • ss2.jpg
    ss2.jpg
    53.3 KB · Views: 67

MajP

You've got your good things, and you've got mine.
Local time
Today, 01:51
Joined
May 21, 2018
Messages
5,690
1. I am assuming the listbox is built on a query, or that is one complicated value list.
2. The string function
So I concatenated the field value with
String([id] * 5, " ") & [FieldName]
since the ID changes it gave me a stair step
5 spaces, 10 spaces, 15, ....
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 01:51
Joined
May 21, 2018
Messages
5,690
Table1 Table1

IDFieldChapterChaperNumberLevel
1​
Chapter One1
1​
2​
Sub One1.1
2​
3​
Sub Two1.2
2​
4​
Sub Sub One1.1.1
3​
5​
Sub Three1.3
2​
6​
Chapter Two2
1​


Code:
SELECT String(5*[level]," ") & [chapernumber] & " " & [FieldChapter] AS Display
FROM Table1;
Indent2.jpg
 

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
The listbox is gone while I fight with this continuous Form - it may work out better.
It was populated by -
Code:
If Me!BComment > "" Then
                Comm = Split(Me!BComment, vbLf)
                For Each item In Comm
                    Me.Parent.Form3!lstBComment.AddItem item
                Next
        End If
I'm still pondering your String([id] suggestion. This would indent the rows?. You're way ahead of me with that.
 

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
Didn't see your example till now Maj, it might be beyond me to apply that. The field with the data is only formatted by VBLF delimiters. I was expecting to do some formatting at Add Item, basically if the first 4 chars didn't contain ". " then indent.
But the listbox might be now replaced by the Cont Form, if I come back to it I'll have a go... thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:51
Joined
May 7, 2009
Messages
14,648
can also be:

SELECT Space(5*([level]-1)) & [chapernumber] & " " & [FieldChapter] AS Display
FROM Table1;
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 01:51
Joined
May 21, 2018
Messages
5,690
I actually tested to see if this would work with the add item and it does not. Seems like the Additem method does apply a TRIM before adding.
 

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
Must be TRIM that was spoiling things initially.
I'm a bit stuck now until i get an answer for Msg #10. Googe isn't much help and tricky to descibe what to fix.
 

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
I've had a bit of a breakthrough but can anyone tell me why some lines have a grey backcolor, they should all be yellow.
And can the forecolor vary or must it be the same for each row ?
 

Attachments

  • ss3.jpg
    ss3.jpg
    13 KB · Views: 42

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
Plus, can you have wordwrap on a Continuous Form ? It's just truncating long lines at the moment.
 

kirkm

Registered User.
Local time
Today, 19:51
Joined
Oct 30, 2008
Messages
1,251
Well it's not easy to get what you want, and even then it may not work well. Getting rid of the grey lines involved setting the text box Locked, Yes, Enabled, No and applying conditional formatting. This was a fudge, Access won't use the same color as the detail section, you must vary it by at least one RGB unit. The conditions are pretty limited. I used Value > "" but still need to deal with blank lines. And it's very slow.. flashes of the grey color can still appear briefly. I tried Application.Echo but it didn't seem to make any difference. And the wordwrap issue remains. I found that Reports will not raise events so that's not worth trying -at least for this task where a click or d-click is wanted. It may be ok for Display only and arne if you read this I looked at your example in that db you attached and maybe you could help me with that please?
A listbox might be the best way, and as someone said, chr$(160) DOES work instead of chr$(32). This leaves only wordwrap to sort if anyway has ideas about that. Been a busy day, and quite a bit learned.
 

Users who are viewing this thread

Top Bottom