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?
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
1 Attachment(s)
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:
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).
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
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.