-
Oct 21st, 2017, 04:04 PM
#1
Thread Starter
Fanatic Member
I can' find a title to this issue!!!
Hello vbforums
I hesitate for a long time before I wrote about my worry. I can't even find a title to describe the issue. because I thought it is impossible.
But my last experience learnt me that everything is possible on Vbforums.
I'am copying data from a listview to a multiline textbox.
Code:
Private Sub lvw_ItemClick(ByVal Item As MSComctlLib.ListItem)
clicknum = clicknum + 1
Select Case clicknum
Case 1
Text1.Text = " " & "1-" & " " & lvw.SelectedItem.Text & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(2).Text
Case 2
Text1.Text = Text1.Text & vbNewLine & vbNewLine & " " & "2-" & " " & _
lvw.SelectedItem.Text & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(2).Text
Case 3
Text1.Text = Text1.Text & vbNewLine & vbNewLine & " " & "3-" & " " & _
lvw.SelectedItem.Text & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(2).Text
Case 4
Text1.Text = Text1.Text & vbNewLine & vbNewLine & " " & "4-" & " " & _
lvw.SelectedItem.Text & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(2).Text
Case 5
Text1.Text = Text1.Text & vbNewLine & vbNewLine & " " & "5-" & " " & _
lvw.SelectedItem.Text & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
lvw.SelectedItem.ListSubItems(2).Text
End Select
End Sub
This is the output:
What I need is to put the lvw.SelectedItem.ListSubItems(1).Text in the same vertical line. I mean they should have the same"left" regardless the length of the lvw.SelectedItem.Text.
I thought of using: If Len(lvw.SelectedItem.ListSubItems(1). = ?? then String$(??, " ") but this is not pratical at all.
Thanks
-
Oct 21st, 2017, 04:07 PM
#2
Re: I can' find a title to this issue!!!
Instead of using spaces try using tabs. The tab positions of a textbox can be set with APIs. Or, just use a fixed-pitch/mono-space font where each character's width uses exactly the same number of pixels.
-
Oct 21st, 2017, 05:14 PM
#3
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Thank you sir
But what you are suggesting is out of my capacities.
-
Oct 21st, 2017, 05:30 PM
#4
Re: I can' find a title to this issue!!!
Nah, for examples, just give the forum a quick search for: em_settabstops
-
Oct 21st, 2017, 08:58 PM
#5
Re: I can' find a title to this issue!!!
Here is a solution implements LaVolpe's suggestion
In Form declaration section add
Code:
Const EM_SETTABSTOPS = &HCB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
In Form_Load event add
Code:
Dim lngTabStop(1) As Long
lngTabStop(0) = 200
lngTabStop(1) = 230
SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
Replace your lvw_ItemClick with the following one
Code:
Private Sub lvw_ItemClick(ByVal Item As MSComctlLib.ListItem)
clicknum = clicknum + 1
Select Case clicknum
Case 1
Text1.Text = " 1- " & lvw.SelectedItem.Text & vbTab & vbTab & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
lvw.SelectedItem.ListSubItems(2).Text
Case 2
Text1.Text = Text1.Text & vbNewLine & vbNewLine & " 2- " & _
lvw.SelectedItem.Text & vbTab & vbTab & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
lvw.SelectedItem.ListSubItems(2).Text
Case 3
Text1.Text = Text1.Text & vbNewLine & vbNewLine & " 3- " & _
lvw.SelectedItem.Text & vbTab & vbTab & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
lvw.SelectedItem.ListSubItems(2).Text
Case 4
Text1.Text = Text1.Text & vbNewLine & vbNewLine & " 4- " & _
lvw.SelectedItem.Text & vbTab & vbTab & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
lvw.SelectedItem.ListSubItems(2).Text
Case 5
Text1.Text = Text1.Text & vbNewLine & vbNewLine & " 5- " & _
lvw.SelectedItem.Text & vbTab & vbTab & _
lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
lvw.SelectedItem.ListSubItems(2).Text
End Select
End Sub
Last edited by 4x2y; Oct 21st, 2017 at 09:07 PM.
-
Oct 22nd, 2017, 12:47 AM
#6
Re: I can' find a title to this issue!!!
Sam
Here is another solution that uses LaVolpe's suggestion .. ie, the use of vbTab
There are several key considerations:
- The length of the string
- You can't always use a constant number of tabs
- The number needs to take into account the length of the string, where length is pixels, not characters
- Use the TextWidth Method to establish the length
- The length of vbTab .. will be font dependent
- Determine the max and min number of tabs required
- Add tabs as required
Here is an image
- The top control is the ListView
- Awid is the TextWidth of Author + 1 space
- tabs is the number of tabs in Author .. ie, in Awid
- in this case, TextWidth(.SelectedItem.Text & " ") / 840
- where the width of vbTab is 840 (in this case)
- The 2nd control is Text2 .. it always uses 1 vbTab
- shown for demo purposes only
- ie, what NOT to do
- The 3rd control is Text4 .. it adds an extra vbTab as needed
Notice that Text2 .. not aligned
Notice that Text4 .. IS aligned
Here is a code snippet ...
Code:
Private Sub ListView1_Click()
'
With ListView1
' 1. initial 4 selections
If samSel = Empty Then
' 0. determine tab width
txt0 = "1" & vbTab
tw0 = TextWidth(txt0) ' 840
tabwid = tw0
'
minrawtab = samMinTxWd / tabwid
minnntab = Int(minrawtab) + 1
maxrawtab = samMaxTxWd / tabwid
maxnntab = Int(maxrawtab) + 1
' orig
ClickNum = ClickNum + 1
Select Case ClickNum
Case 1
' w/ 1 tab
Text2.Text = " " _
& "1-" _
& " " _
& .SelectedItem.Text _
& vbTab _
& .SelectedItem.ListSubItems(1).Text _
& vbNewLine _
& vbTab _
& .SelectedItem.ListSubItems(2).Text
' w/ nn tabs
txwd = TextWidth(.SelectedItem.Text & " ")
rawtabs = txwd / tabwid
iitabs = Int(rawtabs)
nntabs = maxnntab - iitabs
Text4.Text = " " _
& "1-" _
& " " _
& .SelectedItem.Text _
& vbTab _
& IIf(nntabs = 2, vbTab, "") _
& .SelectedItem.ListSubItems(1).Text _
& vbNewLine _
& vbTab _
& .SelectedItem.ListSubItems(2).Text
Case Is >= 2
' w/ 1 tab
Text2.Text = Text2.Text _
& vbNewLine _
& vbNewLine _
& " " _
& CInt(ClickNum) & "-" _
& " " _
& .SelectedItem.Text _
& vbTab _
& .SelectedItem.ListSubItems(1).Text _
& vbNewLine _
& vbTab _
& .SelectedItem.ListSubItems(2).Text
' w/ nn tabs
txwd = TextWidth(.SelectedItem.Text & " ")
rawtabs = txwd / tabwid
iitabs = Int(rawtabs)
nntabs = maxnntab - iitabs
'
Text4.Text = Text4.Text _
& vbNewLine _
& vbNewLine _
& " " _
& CInt(ClickNum) & "-" _
& " " _
& .SelectedItem.Text _
& vbTab _
& IIf(nntabs = 2, vbTab, "") _
& .SelectedItem.ListSubItems(1).Text _
& vbNewLine _
& vbTab _
& .SelectedItem.ListSubItems(2).Text
End Select
End With
'
End Sub
... where the key is this line of code .. for Case 1
Code:
Case 1
' w/ nn tabs
txwd = TextWidth(.SelectedItem.Text & " ")
rawtabs = txwd / tabwid
iitabs = Int(rawtabs)
nntabs = maxnntab - iitabs
Text4.Text = " " _
& "1-" _
& " " _
& .SelectedItem.Text _
& vbTab _
& IIf(nntabs = 2, vbTab, "") _
& .SelectedItem.ListSubItems(1).Text _
& vbNewLine _
& vbTab _
& .SelectedItem.ListSubItems(2).Text
.. with a similar line of code for Case Is >= 2
Indeed, if there is a really large difference in TextWidth's, extra IIf()'s may be needed
There are a few other code frags involved.
Holler if you'd like to see them.
Natch, modify as needed.
BTW, no API's required ..
Spoo
Last edited by Spooman; Oct 22nd, 2017 at 01:31 AM.
Reason: BTW
-
Oct 22nd, 2017, 01:29 AM
#7
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
4x2y
Spooman
You are great men.
I thank you very much.
As I expected the miracles are possible on Vbforums.
Gentelmen: What you are doing encouraged me to ask this question:
Is it possible to change the tab (space) at runtime by code?
thanks a lot.
-
Oct 22nd, 2017, 01:35 AM
#8
Re: I can' find a title to this issue!!!
Originally Posted by samer22
Gentelmen: What you are doing encouraged me to ask this question:
Is it possible to change the tab (space) at runtime by code?
Can't speak for 4x2y, but in my code snippet, the number of tabs DOES change at runtime
Spoo
-
Oct 22nd, 2017, 02:39 AM
#9
Re: I can' find a title to this issue!!!
Add the following sub to your code and call it with desired values
(I'm not on computer to test, but it should work)
Code:
Private Sub SetTabWidth(ByVal t1 As Long, ByVal t2 As Long)
Dim lngTabStop(1) As Long
lngTabStop(0) = t1
lngTabStop(1) = t2
SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
Text1.Refresh
End Sub
-
Oct 22nd, 2017, 07:10 AM
#10
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Spooman
Thanks a lot
In fact, I'm using 4x2y' code and it's working perfectly.
because I need to use the item click event instead of the lvw_click event.
thank you sir again.
-
Oct 22nd, 2017, 07:13 AM
#11
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
4x2y
Million thanks for your precious help.
I found big trouble to call the subroutine under a button click.
Could you please tellme how to do?
thanks a lot.
-
Oct 22nd, 2017, 09:26 AM
#12
Re: I can' find a title to this issue!!!
Originally Posted by samer22
I found big trouble to call the subroutine under a button click.
Could you please tellme how to do?
thanks a lot.
The itemclick event is for a single item. If you want to transfer all items to the textbox, you would loop through the items and send each one to that event, something like this:
Code:
Dim n As Long
For n= 1 To lvw.ListItems.Count
Call lvw_ItemClick(lvw.ListItems(n))
Next
Likewise, if just wanting to send the selected item only
Code:
Call lvw_ItemClick(lvw.SelectedItem)
However, I'd suggest moving the code from the lvw_ItemClick event to your own custom subroutine. That way you can call it from wherever you need and the code wouldn't be tied to a specific event.
-
Oct 22nd, 2017, 10:26 AM
#13
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Thank you LaVolpe
In fact I'm referring to 4x2y subroutine.
Code:
Private Sub SetTabWidth(ByVal t1 As Long, ByVal t2 As Long)
Dim lngTabStop(1) As Long
lngTabStop(0) = t1
lngTabStop(1) = t2
SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
Text1.Refresh
End Sub
How shall I call this sub?
thank you sir
-
Oct 22nd, 2017, 11:14 AM
#14
Re: I can' find a title to this issue!!!
Originally Posted by samer22
Spooman
Thanks a lot
In fact, I'm using 4x2y' code and it's working perfectly.
because I need to use the item click event instead of the lvw_click event.
thank you sir again.
Sam
My bad .. I had not noticed the way you defined the sub in your post #1 ..
However, now I'm a little confused
In my post #6 I used
Code:
Private Sub ListView1_Click()
'
End Sub
But ...
.. if I rename the sub as ...
Code:
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
'
End Sub
... or ...
Code:
Private Sub ListView1_ItemClick(ByVal Item As ListItem)
'
End Sub
... I get identical results
In all 3 cases, the subs trigger ONLY IF items in the 1st column (ie, Author) are clicked
My knowledge of ListView is limited. To those in the know ..
- what is the difference between the 3 sub definitions ?
- and why do they all produce identical results ?
Spoo
-
Oct 22nd, 2017, 11:14 AM
#15
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
I think I got it
Code:
SetTabWidth 100, 160
Thanks
-
Oct 22nd, 2017, 11:31 AM
#16
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Spooman
I didn't know if your code can be used under item click event.
In my project I'm using the item clik and itemcheck events.
to export items I use the itemclik
to delete items I use the item-check.
But if using lvw_click to export, the items are exported when checked.
this is why I needed the item click event
-
Oct 22nd, 2017, 11:32 AM
#17
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Now I'll play a little with my code then close the post
thank you
-
Oct 22nd, 2017, 12:03 PM
#18
Re: I can' find a title to this issue!!!
Sam
Sounds good to me.
BTW, I checked the IDE's Help for ListView control, and ItemCheck is NOT listed among Events.
However, if I search for ItemCheck event, it's there, plain as day !
Go figure.
Learned something new .. thanks
Spoo
-
Oct 22nd, 2017, 12:49 PM
#19
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
My friends I'm sorry to disturb you again.
Code:
Private Sub SetTabWidth(ByVal t1 As Long, ByVal t2 As Long)
Dim lngTabStop(1) As Long
lngTabStop(0) = t1
lngTabStop(1) = t2
SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
Text1.Refresh
End Sub
Is it possible to know the number of vbtabs and store these values in an ini or texfile.
thank you
Last edited by samer22; Oct 22nd, 2017 at 01:19 PM.
-
Oct 22nd, 2017, 01:54 PM
#20
Re: I can' find a title to this issue!!!
Originally Posted by samer22
Is it possible to know the number of vbtabs and store these values in an ini or texfile.
Are you save Tabs only not whole text?
Try this
Code:
Private Function GetTabCount(ByVal strText As String) As Long
Dim c As Long
Dim j As Long
For j = 1 To Len(strText)
If Mid$(strText, j, 1) = vbTab Then
c = c + 1
End If
Next
GetTabCount = c
End Function
Usage
Code:
Private Sub Command1_Click()
MsgBox GetTabCount(Text1.Text), vbOKOnly + vbInformation
End Sub
-
Oct 22nd, 2017, 03:38 PM
#21
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Thank you sir
But I'm a bit confused.
The function you provided is really what I need and apparently it returns the right number of vbtabs.
However, there is a problem.
When calculating the vbtabs by means of the function it gives 3 vbtabs and that seems the corret value.
Suppose I store this value.
When I call this value using the subroutine, the values are initially:
Code:
SetTabWidth 100, 160
Where am I going to put the stored value 3.
seems impossible.
I hope you will understand my worry.
thank you
-
Oct 22nd, 2017, 05:53 PM
#22
Re: I can' find a title to this issue!!!
Tabstops are not how much the Text1.Text contain vbTab characters, but they are describe the location the cursor stops after vbTab character, most word processors uses Tabstops to enable the user to align text by pressing the tab key.
The following screenshot is taken from Windows Write program, as you can see there are only two Tabstops but many Tab characters
I have declared the array lngTabStop with 2 values only because your output text don't requires more.
I hope this is clear to you.
-
Oct 22nd, 2017, 06:36 PM
#23
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
thanks sir
I understand
So what I'm looking for is to calculate this space maybe in text_change event.
Then restore it whenever I wish.
Is this possible?
-
Oct 22nd, 2017, 07:00 PM
#24
Re: I can' find a title to this issue!!!
Originally Posted by samer22
thanks sir
I understand
So what I'm looking for is to calculate this space maybe in text_change event.
Then restore it whenever I wish.
Is this possible?
That space is defined by the two values passed to SetTabWidth method, so all you need is saving these values and call SetTabWidth again with saved values.
-
Oct 23rd, 2017, 01:26 AM
#25
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Originally Posted by 4x2y
That space is defined by the two values passed to SetTabWidth method, so all you need is saving these values and call SetTabWidth again with saved values.
Would you please give me an example.
Something like:
Debug.Print values
thanks
-
Oct 23rd, 2017, 02:32 AM
#26
Re: I can' find a title to this issue!!!
SetTabWidth should called only once at program start (usually in Form_Load). Do you call it after that with different values? If so then save the new values to your settings file and in Form_Load read from settings file, something like this
Code:
Private Sub Form_Load()
' Here you should read t1 and t2 from your settings file
SetTabWidth t1, t2
End Sub
Code:
Private Sub SetTabWidth(ByVal t1 As Long, ByVal t2 As Long)
Dim lngTabStop(1) As Long
lngTabStop(0) = t1
lngTabStop(1) = t2
SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
Text1.Refresh
' Here you should save t1 and t2 to your settings file
End Sub
I hope you got the idea.
-
Oct 23rd, 2017, 07:33 AM
#27
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
thanks sir
I understand quite well.
However what I wish to reach is something else.
Let's explain:
A user clicks on an item in the listview.
The item(s) is exported to the textbox.
Current formatting is quite satisfactory, but a user may change the initial formating by shortening or widening the space shown in the picture above.
This means that the intial space ( t1, t2) has been changed.
now, I need to pick these new values of t1 and t2 under the textbox change event and save them.
I don't know wether this is possible or not?
thank you
-
Oct 23rd, 2017, 04:40 PM
#28
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Last edited by samer22; Oct 23rd, 2017 at 06:30 PM.
-
Oct 23rd, 2017, 10:29 PM
#29
Re: I can' find a title to this issue!!!
Originally Posted by samer22
Current formatting is quite satisfactory, but a user may change the initial formating by shortening or widening the space shown in the picture above.
If this text box is editable by the user, aren't you have to save his whole changes not just formatting?
-
Oct 24th, 2017, 01:56 AM
#30
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Originally Posted by 4x2y
If this text box is editable by the user, aren't you have to save his whole changes not just formatting?
No I don't need to save the content of the textbox.
I'm just interested in the layout.
My question:
Is it possible to detect (t1 and t2) while editing the text?
thank you
-
Oct 24th, 2017, 02:44 AM
#31
Re: I can' find a title to this issue!!!
Originally Posted by samer22
Is it possible to detect (t1 and t2) while editing the text?
It is possible if you let the user change them not the text itself, that is set Text1.ReadOnly to True and add HScroll1 and HScroll2 to your form and use code like this
Code:
Private Sub HScroll1_Change()
SetTabWidth HScroll1.Value, HScroll2.Value
' Save HScroll1.Value and HScroll2.Value to your settings file.
' in Form_Load call SetTabWidth with above saved values
End Sub
Private Sub HScroll2_Change()
SetTabWidth HScroll1.Value, HScroll2.Value
' Save HScroll1.Value and HScroll2.Value to your settings file.
' in Form_Load call SetTabWidth with above saved values
End Sub
I suggest using HScroll control but you are free to use any other input method.
-
Oct 24th, 2017, 03:39 PM
#32
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
You are a programmer of genius.
Though the method does not meet exactly what I was wishing, it is creative and ingenious.
I tested it and it is working perfect
The read-only property doesn't fit the situation.
Congratulation sir
-
Oct 25th, 2017, 12:34 AM
#33
Re: I can' find a title to this issue!!!
Great
-
Oct 25th, 2017, 01:01 PM
#34
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Spooman
Using your code in #6, I couldn't get the same alignement.
Could you please attach a sample.
thanks
-
Oct 25th, 2017, 03:22 PM
#35
Re: I can' find a title to this issue!!!
Sam
Here is the snippet I used to load the ListView
Code:
Public ClickNum
Dim aaSam(2, 4)
Public samXdn
Public samNN As Integer
Public samSel As Integer
Public samMaxTxWd As Integer
Public samMinTxWd As Integer
'
Private Sub Command1_Click()
With ListView1
.Visible = True
.Top = 300
.Left = 300
.Width = 4720
.Height = 2500
' Add ColumnHeaders.
ListView1.ColumnHeaders.Add , , "Author", 2500
ListView1.ColumnHeaders.Add , , "ID", 500, lvwColumnCenter
ListView1.ColumnHeaders.Add , , "A wid", 1000
ListView1.ColumnHeaders.Add , , "tabs", 700
' Set View property to Report.
ListView1.View = lvwReport
' Set the Database to the BIBLIO.MDB database.
fpBIB = "C:\Program Files (x86)\Microsoft Visual Studio\VB98\Biblio.mdb"
Dim myDb1 As Database, myRs1 As Recordset
Set myDb1 = DBEngine.Workspaces(0).OpenDatabase(fpBIB)
' Set the recordset to the "Authors" table.
Set myRs1 = myDb1.OpenRecordset("Authors", dbOpenDynaset)
' Declare a variable to add ListItem objects.
Dim itmX1 As ListItem
samNN = 8
' lead
txt1 = " " _
& "1-" _
& " "
tw1 = TextWidth(txt1)
tw2 = TextWidth(" ") ' 45
samMaxTxWd = 0
samMinTxWd = 5000
For ii = 1 To samNN
Set itmX1 = ListView1.ListItems.Add(, , CStr(myRs1!Author)) ' Author
' 1. If the AuthorID field is not null, then set SubItem 1 to it.
If Not IsNull(myRs1!Au_id) Then
itmX1.SubItems(1) = CStr(myRs1!Au_id)
End If
' 2. txt width
txt0 = .ListItems.Item(ii)
itmX1.SubItems(2) = TextWidth(txt0) + tw2
' 3. calc tabs
If TextWidth(txt0) > samMaxTxWd Then
samMaxTxWd = TextWidth(txt0) + tw2
End If
If TextWidth(txt0) < samMinTxWd Then
samMinTxWd = TextWidth(txt0) + tw2
End If
itmX1.SubItems(3) = Format((TextWidth(txt0) + tw2) / 840, "#.##")
'
myRs1.MoveNext
Next ii
End With
'
End Sub
You may need to change this file path.
Note
.. I used Sub Command1_Click()
.. you may want to put it into Sub Form_Load()
HTH
Spoo
-
Oct 25th, 2017, 04:02 PM
#36
Thread Starter
Fanatic Member
Re: I can' find a title to this issue!!!
Spooman
thanks
but the code is about feeding a listview from database.
And my concern is about alignement in textbox when sending items from a listview.
-
Oct 25th, 2017, 04:23 PM
#37
Re: I can' find a title to this issue!!!
If there is a way to retrieve the current tab positions in a textbox, I am not aware of it. Per MSDN, the default is every 32 dialog units. So, unless there is a way to retrieve them, you will need to cache/remember the ones you set. After setting t1,t2, cache them somewhere along with a flag that they are set. Then when you change them, re-cache them.
Code:
Dim m_TabPositions As String
Private Function TabPositionsExist() As Boolean
TabPositionsExist = Not (m_TabPositions = vbNullString)
End Function
Private Sub SetTabPositions(t1 As Long, t2 As Long)
m_TabPositions = t1 & "," & t2
Dim lngTabStop(1) As Long
lngTabStop(0) = t1
lngTabStop(1) = t2
SendMessage Text1.hWnd, EM_SETTABSTOPS, 2, lngTabStop(0)
Text1.Refresh
End Sub
Private Sub GetTabPositions(t1 As Long, t2 As Long)
' t1 & t2 are filled or returned as zero if not previously set
If m_TabPositions = vbNullString Then
t1 = 0: t2 = 0
Else
t1 = CLng(Left$(m_TabPositions, InStr(m_TabPositions, ",") - 1))
t2 = CLng(Mid$(m_TabPositions, InStr(m_TabPositions, ",") + 1))
End If
End Sub
The above is just an idea. If it sounds like it will work, modify it as needed.
Edited: Changed GetTabPositions to more resemble SetTabPositions
Last edited by LaVolpe; Oct 25th, 2017 at 04:36 PM.
-
Oct 25th, 2017, 04:33 PM
#38
Re: I can' find a title to this issue!!!
Originally Posted by samer22
Spooman
thanks
but the code is about feeding a listview from database.
And my concern is about alignement in textbox when sending items from a listview.
Post #35 is what populates the ListView
I thought that is what you meant by "attach a sample"
The code for alignment issues is (and was all along) shown in post #6.
What is it that you are looking for?
Please be specific
Spoo
Last edited by Spooman; Oct 25th, 2017 at 04:36 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|