Results 1 to 11 of 11

Thread: Display repeated data(like repeater in asp.net)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2012
    Posts
    28

    Display repeated data(like repeater in asp.net)

    Hello,

    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


    Thanks,
    KK

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: Display repeated data(like repeater in asp.net)

    Controls that could be used:
    ListBox, ListView, MS(H)FlexGrid.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2012
    Posts
    28

    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?

    can you give any example of this scenerio?
    Thanks

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    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.

  5. #5
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    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
    Attached Images Attached Images  
    Last edited by Arnoutdv; Mar 29th, 2016 at 09:57 AM.

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: Display repeated data(like repeater in asp.net)

    Olaf has a similar repeater deseign here.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Display repeated data(like repeater in asp.net)

    Have you looked at the standard VB6 DataRepeater (MSDatRep.ocx) control?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2012
    Posts
    28

    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

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    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...

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Oct 2012
    Posts
    28

    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

    Exit Sub

    LoadErr:
    MsgBox "Error:" & err & " " & err.Description
    Call Trap_Errors(err.Number, err.Description, Now, Me.name, "OpenRequest")

    End Sub

    Thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width