I want to display repeated data in my visual basic 6.0 form. how can I do this?
ex:
1. NEW TRAINING PROGRAMME
Please note that we now have a new training program in place for all interpreters. Please register online.
Posted by: Ian McKenzie Mon 29 Feb 2016
2. Batch Training Program
Please note that we have arrange a new batch program.
Posted by: Ian McKenzie Mon 22 Feb 2016
Re: Display repeated data(like repeater in asp.net)
Hello Arnoutdv,
1. NEW TRAINING PROGRAMME
Please note that we now have a new training program in place for all interpreters. Please register online.
Posted by: Ian McKenzie Mon 29 Feb 2016
all 3 lines are diff. DB table fields. is it feasible?
Re: Display repeated data(like repeater in asp.net)
You can use 3 columns in the ListView and the MSFlexGrid control.
You can also use the MSFlexGrid control and show the 3 fields in their own rows, having 3 rows per record.
Then you can make the each 1st row bold or having a different font size.
Re: Display repeated data(like repeater in asp.net)
Basic sample:
Code:
Private Sub Command1_Click()
Static CNT As Long
CNT = CNT + 1
AddRecord CStr(CNT) & " TRAINING", "Please note that we now have a new training program in place for all interpreters. Please register online", "Posted by: Ian McKenzie Mon 29 Feb 2016, " & Time
End Sub
Private Sub Form_Load()
With MSFlexGrid1
.FixedRows = 0
.FixedCols = 0
.Rows = 0
.Cols = 1
.ColWidth(0) = .Width
.ColAlignment(0) = flexAlignLeftCenter
End With
End Sub
Private Sub AddRecord(Field1 As String, Field2 As String, Field3 As String)
Dim lMainRow As Long
With MSFlexGrid1
lMainRow = .Rows
.AddItem UCase$(Field1)
.AddItem Field2
.AddItem Field3
.Row = lMainRow: .RowSel = lMainRow
.CellFontBold = True
.CellBackColor = RGB(255, 255, 127)
lMainRow = .Rows
.Rows = .Rows + 1
.RowHeight(lMainRow) = Screen.TwipsPerPixelY * 1
.Row = lMainRow: .RowSel = lMainRow
.CellBackColor = RGB(1, 1, 1)
End With
End Sub
Last edited by Arnoutdv; Mar 29th, 2016 at 09:57 AM.
Re: Display repeated data(like repeater in asp.net)
Yeah, typically that's how it's done... in a grid of some kind. Mostly because it's the path of least resistance. I don't think VB6 has a built-in repeater control... I've seen them, but they were third party controls, which have long since gone the way of the Dodo...
which means rolling your own... which isn't overly difficult, but can be tedious at times.
If it were me... this is probably how I'd do it:
1 - create a user control that displays one record
2 - create a second user control - put a picture box on it... the UC then accepts a Recordset... loops through the recordset, pulls the data needed, creates a new instance of the UC from #1, feeds it the info to display, then adds it to the Picturebox...
3 - add any otehr needed code - I don't know if you'll need to handle scrol;ling yourself or if the PB will take care of that for you...
4 - that UC can then be dropped onto a form, and then passed the data at run-time.
Re: Display repeated data(like repeater in asp.net)
Hello Arnoutdv,
The data coming from DB table. these are not static content. it is just given for example. How can we give DB data one by one to AddRecord function.
That is what that we want. now few changes we want to do.
1) we want to make 'Please note that we now...' line wrap in case of too much text. should we wrap it?
2) we want to make 'posted by' line right aligned and font to italic. should we need to take 2 column?
3) we also want to set vertical scroll bar as we have so many posts but do not want to display horizontal scroll bar.
1. NEW TRAINING PROGRAMME
Please note that we now have a new training program in place for all interpreters. Please register Online. We
want this line to wrap.
Posted by: Ian McKenzie Mon 29 Feb 2016
Thanks
Last edited by krunal.itaction; Mar 30th, 2016 at 01:42 AM.
Reason: req update
Re: Display repeated data(like repeater in asp.net)
I hope you know how to retrieve data from your database?
Then you can pass the fields to the "AddRecord" method.
I just gave an example, use this as a base for your own method.
Study the help for the MSFlexGrid for additional layout like alignment, fonts etc.
Last edited by Arnoutdv; Mar 30th, 2016 at 09:49 AM.
Reason: Spelling...
Re: Display repeated data(like repeater in asp.net)
Hello Arnoutdv,
Many thanks for the code. Finally I have made modification in you code and make my output.
With MSFlexGrid1
.FixedRows = 0
.FixedCols = 0
' .Rows = 0
.Cols = 2
.ColWidth(0) = .Width
.ColAlignment(0) = flexAlignLeftCenter
End With
Public Sub LoadData()
Dim rst As Recordset
Dim i As Integer
On Error GoTo LoadErr
Dim rs As New ADODB.Recordset
Dim k As Integer
strSql = "select p.*,ca.Firstname, ca.Lastname from tblposts p inner join CAMAccts ca on p.Username = ca.Username Order by CreateModifyDate desc"
PrepareRecordset rs
rs.Open strSql
If rs.RecordCount > 0 Then
If (rs("IsLogoDisplay")) Then
imgLogo.Visible = True
Else
imgLogo.Visible = False
End If
lblPageHeader.Caption = rs("PageHeader")
k = 1
MSFlexGrid1.Cols = 3
For i = 1 To rs.RecordCount
' MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
' AddRecord i, rs("id") & " " & rs("PageHeading"), CStr(rs("Description")), "Posted by: " & rs("Firstname") & " " & rs("Lastname") & _
' " " & Left(WeekdayName(Weekday(rs("CreateModifyDate"))), 3) & " " & Day(rs("CreateModifyDate")) & " " & MonthName(Month(rs("CreateModifyDate")), True) & " " & Year(rs("CreateModifyDate"))
' rs.MoveNext
' Next i
''''''''''''
MSFlexGrid1.Rows = (rs.RecordCount * 3) + 1
With MSFlexGrid1
For j = 1 To 3
If j = 1 Then
.TextMatrix(k, 1) = rs(0) & ". " & rs("PageHeading")
.ColWidth(1) = 16500
.Col = 1
.Row = k
.CellFontBold = True
.CellAlignment = vbLeftJustify
k = k + 1
End If
If j = 2 Then
.TextMatrix(k, 1) = rs("Description")
.Col = 1
.Row = k
.ColWidth(2) = 16500
.CellAlignment = vbLeftJustify
.WordWrap = True
' .AllowUserResizing = flexResizeBoth
' .ColAlignment(1) = flexAlignLeftTop
.RowHeight(k) = 800
' .RowHeight(1) = Screen.TwipsPerPixelY * 1
k = k + 1
End If
If j = 3 Then
.TextMatrix(k, 2) = "Posted by: " & rs("Firstname") & " " & rs("Lastname") & _
" " & Left(WeekdayName(Weekday(rs("CreateModifyDate"))), 3) & " " & Day(rs("CreateModifyDate")) & " " & MonthName(Month(rs("CreateModifyDate")), True) & " " & Year(rs("CreateModifyDate"))
.ColWidth(2) = 4000
.Col = 2
.Row = k
.CellFontItalic = True
.CellAlignment = flexAlignRightCenter
k = k + 1
End If
Next j
.RowHeight(0) = 0
.ColWidth(0) = 0
End With
rs.MoveNext
Next i
End If