CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: listview

  1. #1
    Join Date
    Oct 2002
    Location
    asian
    Posts
    116

    listview

    if im going to use listview, how can a put the record on it? i want to get the records from a recordset.

    Is it possible tu put textbox and checkbox on the listview at the same time?

    Pls help thanks!!!
    Last edited by kristine2002; October 24th, 2002 at 03:31 AM.
    Thanks!!!
    Kristine

  2. #2
    Join Date
    Oct 2002
    Location
    India
    Posts
    22

    An Example

    Here is an example I use Hope this will help You

    Sub Load Tests()

    ListView2.ListItems.Clear
    ListView2.ColumnHeaders.Clear

    ListView2.ColumnHeaders. _
    Add , , "Tests", 2030, lvwColumnLeft

    ListView2.ColumnHeaders. _
    Add , , "Rate", 1000, _
    lvwColumnRight

    ' Set View property to Report.
    ListView2.View = lvwReport


    SString = "specimen = '" & ComboSpc & "'"


    Rs.Open "select Testname, rate FROM testTable Where (" & SString & " and Testname is Not Null) Order by Testname", CN, adOpenDynamic, adLockOptimistic

    Dim itmX As ListItem
    While Not Rs.EOF
    Set itmX = ListView2.ListItems. _
    Add(, , UCase(Rs!testname)) ' testname

    itmX.SubItems(1) = Format((Rs!Rate), "0.00")

    Rs.MoveNext ' Move to next record.
    Wend
    Rs.Close


    End Sub


    VbBaby

  3. #3
    Join Date
    Oct 2002
    Location
    asian
    Posts
    116

    Smile listview (another question)

    Hi! Thanks for the help. But i still have two more problems. How can i put textbox and checkbox on a listview control. I know that you can set the checkbox property to true to display a checkbox on the listview, but how about textbox? Is it possible?

    Is there a way to know what column was click on a listview if it has several columns in it? Because i want to use listview the same way as datagrid.



    I'll really appreciate your help. Thanks in advance
    Last edited by kristine2002; October 24th, 2002 at 09:33 AM.
    Thanks!!!
    Kristine

  4. #4
    Join Date
    Oct 2002
    Location
    India
    Posts
    22
    Hello

    I am not sure why you want to put a text box on a ListView Control. And What is the problen to Put one on the list view control. Why not just draw text box on Listview?

    In listview control the colum is determined by the proppeety

    ListView1.SeletedItem. Subitem(Index)



    Will You Please explain what is your Idea Behind putting a text box on it??

    VbBaby

  5. #5
    Join Date
    Oct 2002
    Location
    asian
    Posts
    116

    Angry

    what do you mean when you say "draw a text box on a listview?
    Is it different from putting a textbox on a listview?

    I want to put textbox on a listview so user can keyin something, just like a datagrid. Before im planning to use datagrid but i have a problem using datagrid coz i dont know how to put checkbox on it.

    Someone from here suggested to use listview if i want to use checkbox. But my problem now is how can i put textbox on a listview.

    If i can draw a text box on a listview and will allow user to input something on it, how can i do that?

    I really need your help badly. Thanks for the time
    Thanks!!!
    Kristine

  6. #6
    Join Date
    Sep 2001
    Posts
    49
    You can set the listview property LabelEdit to automatic. That allows the user to edit each field.

    Here is a piece of code that I made for any recordset size or whatnot. However I use MSFlexGrid instead of a Listview. I am sure you can figure out how to use it in Listview. It does crash if there are too many records but I added more code to handle it which I didn't post here but again it can be coded.


    Dim i As Integer
    Dim j As Integer
    Dim intCount As Double
    Set mRS = RecSet
    With mRS
    'change the number of columns in grid
    msgGrid.Cols = .Fields.Count
    .MoveLast

    'change the number of rows in grid
    If .RecordCount > 5000 Then
    msgGrid.Rows = 5001
    mlngStartRecord = 1
    mlngLastRecord = 5000
    mblnMultiple = True
    Else
    msgGrid.Rows = .RecordCount + 1 'add one more for header row
    mlngStartRecord = 1
    mlngLastRecord = .RecordCount
    mblnMultiple = False
    End If
    .MoveFirst

    ' Create a header row using the field names and column widths
    For i = 0 To .Fields.Count - 1
    msgGrid.Row = 0
    msgGrid.Col = i
    'write the name to the grid cell
    msgGrid.Text = .Fields(i).Name & ""
    'set the header column width.
    msgGrid.ColWidth(i) = CLng(Len(.Fields(i).Name)) * 104
    intCount = intCount + msgGrid.ColWidth(i)
    Next i

    'change the width of the from to match with the width of the grid
    'unless the grid is wider than the screen itself then set to screen width
    If (intCount + 400) < Screen.Width Then
    Me.Width = intCount + 400
    Else
    Me.Width = Screen.Width
    Me.Left = 0
    End If

    'Now fill the grid with all the values in recordset
    'start with 1 since 0 is header row
    For i = mlngStartRecord To mlngLastRecord
    'set the row current
    msgGrid.Row = i
    'populate each column with field value
    For j = 0 To .Fields.Count - 1
    'set the column
    msgGrid.Col = j
    'write the value to the grid cell
    msgGrid.Text = .Fields(j).Value & ""
    Next j
    'move to the next record
    .MoveNext
    Next i
    End With

  7. #7
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    I've posted the code we use for filling, editing, deleting etc from a listview (with Icons) here in a zipfile. To use it properly, the "edit" form needs to have the properties used by the 'viewstaticdata' form declared.

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

Featured