i can't find it anywhere on the internet, so i hope some of you guys have a solution for me.
I have like 5 textboxes on my form, and i want to put 1 scollbar (Vscroll) on my form. When i scroll down on my vscroll, i want al the textboxes to scroll down with the same interval. Anyone has an idea how to do this. What code do i have to put behind my vscroll_change??
if i do that, my textbox just moves down on the screen... this is not what i want...
i have like 5 textboxes on my form. Every textbox receives the values of a column in my sql database.
for examle
NR NAme .........
1 thomas
2 jef
3 maarten
4 romina
5 biatch
... ...
so suppose you only see the first 3 lines, then i want 1 scrollbar (vscroll), and that when i use that scrollbar, my 2 textboxes scrolls down. so you can see the numbers and names (4, romina and 5,biatch).
so suppose you only see the first 3 lines, then i want 1 scrollbar (vscroll), and that when i use that scrollbar, my 2 textboxes scrolls down. so you can see the numbers and names (4, romina and 5,biatch).
i dont understand, have you placed 5 text boxed one by one...is that not fitting into your screen...or are you using same text box to display all five lines....please clarify
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
While coordinating the scrolling of several textboxes can be done, are you sure you want to use textboxes? Unless the user is expected to write in those textboxes then you probably should use another control like a single listview or grid, or even several listboxes.
I have sample code on my website that does something along the lines of what you are looking for. On this page: http://www.thevbprogrammer.com/tutorials.html
See the "Scroll Bars" link under "9. Forms and More Controls"
yes i downloaded the file frametech, but it was not wat i was looking for. I'll try to explain again what i'm looking for.
I have several textboxes on my form. (they all fit in my form, i'll post a screenshot later in this post, so you can see something more).
When i press a button on the right (for example "objecteigenschappen"), all the data from that table ("objecteigeschappen is a table in my sql server database). in the database is filled into my textboxes. if the table has 3 columns, the first 3 textboxes are filled with all data in those columns.
Now when the table has many data in it, you only see the first 10 lines i shall say. Now i don't want 3 seperated scrollbars (one for every textbox), i want JUST ONE scrollbar (vsroll, somewhere on the screen) en that when i press that one, we move down in all the 3 textboxes to the next data.
I hope now you all know what i'm trying to do. Here's the screenie:
Use a list view. You can dynamically change the column headers and the data that is viewed in it. It would probably be alot easier to figure out than vscroll... Heres a code snippet
Dim adoSearchResults As New ADODB.Recordset
Dim itmListView As ListItem
Dim strSearchResultsQuery As String
lstSearchResults.ListItems.Clear
'|----------------------------------------------------------------------------------
'| Set Up SQL Query Based On User Input.
'|----------------------------------------------------------------------------------
strSearchResultsQuery = "Select [Panel Tag],[IO Type],[Drop],[Rack],[Slot],[Channel],[PLC Register],[Terminal Number],[PLC Tag],[PLC Description],[Comments],[Status],[RowID] From v_PLC_DATA Where " & strNewSearchCriteria & strTextBoxCriteria & " Order By [Drop],[Rack],[Slot],[Channel]"
'|----------------------------------------------------------------------------------
'| Open Recordset and Populate ListView with Results.
'|----------------------------------------------------------------------------------
With adoSearchResults
If .State = adStateOpen Then .Close
.ActiveConnection = strConnectionString
.CursorLocation = adUseClient
.Open (strSearchResultsQuery)
If Not .EOF Then
lblRecordCount.Caption = .RecordCount & " Records Retrieved."
Else
lblRecordCount.Caption = "No Records Retrieved."
End If
While Not .EOF
Set itmListView = lstSearchResults.ListItems.Add()
itmListView.Text = ![Object Name]
itmListView.Tag = ![RowID]
For i = 1 To .Fields.Count
If IsNull(.Fields(i).Value) Then
itmListView.SubItems(i) = ""
Else
itmListView.SubItems(i) = .Fields(i).Value
End If
Next i
.MoveNext
Wend
.Close
End With
Do a watch window on the recordset and loop through the fields.count loop. I think you might have to do For i = 1 to Fields.count -1 since ado starts at 0, while the listview starts at 1. Let me know...
This code is ugly, and quirky, and slow, but I think it does basically what you are wanting to do. The quirkiness comes from the fact that I don't know of a way to set the top line displayed in a text box -- so I used the "SelStart" to set the Selection bar location. Since SelStart defines a character position instead of a line position, I had to process through the text to translate that into lines, which makes the function slow.
Also, if you change the scroll bar, and calculate a new character position that is already displayed within the text box, the text box doesn't scroll at all. This makes it look like the scroll bars aren't working, when in fact, the SelStart value has changed. There may be ways to code around this, but I didn't take the time to figure it out. Does anybody know an easy way to tell if the scroll bar has been moved up or down? The only thing I could think of was to keep current value versus last value and compare them. Yuck.
Vscroll1 is the scroll bar object. The Max property is set to the number of lines in the text boxes. This, combined with a SmallChange property of 1, means that clicking on the scroll bar arrows will scroll the text by one line up or down. The LargeChange property is set to the number of lines displayed in the text boxes, so that clicking on the scroll bar itself results in "page up" and "page down" functionality.
The two text boxes are named txtSource and txtResults. They show 13 lines of text each.
I used the "Vscroll1.Value + 13" in the loop so that when the user first tries to scroll down using the arrows, the text starts moving right away -- they don't have to click on the arrows 13 times first. I tried setting the initial value of Vscroll1.Value to 13, which has the same sort of effect, but that led to a whole different set of quirks.
Needless to say, this looks like it is possible, but not pretty or easy.
Good luck!
VB Code:
Private Sub VScroll1_Change()
CharIndx = 1
CurLine = 1
If VScroll1.Value <> 1 Then
Do
NextChar = Mid(txtSource.Text, CharIndx, 1)
If NextChar = Chr(13) Then
CurLine = CurLine + 1
End If
CharIndx = CharIndx + 1
Loop Until NextChar = "" Or CurLine >= (VScroll1.Value + 13)
End If
txtSource.SelStart = CharIndx
If txtResults.Enabled = True Then
CharIndx = 1
CurLine = 1
If VScroll1.Value <> 1 Then
Do
NextChar = Mid(txtResults.Text, CharIndx, 1)
If NextChar = Chr(13) Then
CurLine = CurLine + 1
End If
CharIndx = CharIndx + 1
Loop Until NextChar = "" Or CurLine >= (VScroll1.Value + 13)
I've attached a sample app that shows how this works. This code works better than the code in my previous post -- I've handled all of quirkiness (I think). In particular, the problem of the current Value changing without changing the display is fixed. Now you always get an appropriate action when the scroll bar control changes.
Note that this is just a sample app with fixed line contents. It doesnt' take into account lines in the text with different lengths. My previous code snippet handled that, and I didn't want to reproduce that here, so that I could focus on the problems related to the actual scrolling.
VB Code:
Dim Value As Integer
Dim OldValue As Integer
Dim TopLine As Integer
Dim BottomLine As Integer
Dim TotalLines As Integer
Public Sub ProcessNewValue()
Value = VScroll1.Value
If (Value > OldValue) Then
' User is going DOWN
If (Value = OldValue + 1) Then
' Line down; jump to the bottom first, then process the change.
If BottomLine < TotalLines Then
Value = BottomLine + 1
BottomLine = BottomLine + 1
TopLine = TopLine + 1
End If
Else
' Page down; jump to the bottom first, then process the change.
If (Value = OldValue + 13) Then
Value = BottomLine + 13
TopLine = TopLine + 13
BottomLine = TopLine + 12
Else
TopLine = Value - 12
BottomLine = Value
End If
End If
Else
If (Value < OldValue) Then
' User is going UP
If (Value = OldValue - 1) Then
' Line Up; jump to the top first, then process the change.
Value = TopLine - 1
TopLine = TopLine - 1
BottomLine = TopLine + 12
Else
If (Value = OldValue - 13) Then
' Page Up; jump to the bottom first, then process the change.