Results 1 to 6 of 6

Thread: How to find "Listindex" of DBList?

  1. #1
    Junior Member mohsen313's Avatar
    Join Date
    Aug 12
    Posts
    16

    How to find "Listindex" of DBList?

    Hi
    I use DBList1 in my program and I want to find the index of selected item then move the current data to it. For example I want to Use this code:
    HTML Code:
    Private Sub DBList1_Click()
    Data1.Recordset.Move(X)
    Data1.Refresh
    End Sub
    How can I find X?

  2. #2
    New Member
    Join Date
    Aug 12
    Posts
    5

    Re: How to find "Listindex" of DBList?

    The answer is in dblist1.SelectedItem --- this gives you the index My code for an EXAMPLE!!!!

    Private Sub DataList1_Click()
    Dim strQuery As String
    strQuery = "Select * FROM Products WHERE SupplierID = " & _
    DataList1.BoundText
    With adoProducts
    .RecordSource = strQuery
    .Refresh
    End With
    With DataGrid1
    .ClearFields
    .ReBind
    End With
    ''move adoProducts.Recordset to the same number as the index of the datalist
    adoProducts.Recordset.Move (DataList1.SelectedItem - 1) '' minus 1 as first entry in recordset is zero
    End Sub

  3. #3
    Junior Member mohsen313's Avatar
    Join Date
    Aug 12
    Posts
    16

    Re: How to find "Listindex" of DBList?

    Thank for your answer, but when I use "DBList1.SelectedItem" an error occurs and shows its value like vbnullstring. look:
    Attached Images Attached Images  

  4. #4
    New Member
    Join Date
    Aug 12
    Posts
    5

    Re: How to find "Listindex" of DBList?

    Can you use a datalist component vice a databaselist one? Or is that simply the name you gave the datalist component?

    Make sure you actually SELECT an item in the datalist component, otherwise your XXlist1.selectedItem WILL be NULL.

    Send my your section of code and I'll test. (Or, take mine (using a datalist component (datalist1) and a datagrid component (DataGrid1) and an ADODC component (adoProducts), connect them to a database (a great example is located in the msdn library showing how to use these components), and test it yourself). If you can't figure it out, I'll send you my entire (small) VB project so you can see how I set up each component).

  5. #5
    Frenzied Member
    Join Date
    Jan 09
    Location
    Watch Window(Shift+f9)
    Posts
    1,431

    Re: How to find "Listindex" of DBList?

    try the following !
    Code:
    Private Sub DataList1_Click()
    Dim strQuery As String
    strQuery = "Select * FROM Products WHERE SupplierID = " DataList1.BoundText
    With adoProducts
    .RecordSource = strQuery
    .Refresh
    End With
    With DataGrid1
    .ClearFields
    .ReBind
    End With
    ''move adoProducts.Recordset to the same number as the index of the datalist
    adoProducts.Recordset.Move (clng(DataList1.SelectedItem) - 1) '' minus 1 as first entry in recordset is zero
    End Sub
    Last edited by firoz.raj; Aug 30th, 2012 at 01:36 PM.

  6. #6
    Junior Member mohsen313's Avatar
    Join Date
    Aug 12
    Posts
    16

    Re: How to find "Listindex" of DBList?

    Thank you dennismcfarland.
    When I used ADO my problem has solved and the
    Code:
    DataList1.SelectedItem
    worked correctly.

Posting Permissions

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