Click here to Skip to main content
15,884,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

I want to implement navigation in a form that uses Hashtables but I am unsure how to do it.

I want a 'Previous' button, 'Next' button and a 'first record' and 'last record' button.

I can currently get it to print to the Debug window like below but am unsure how to actually get it to display in the form..

Private Sub frmNavigationControls_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim oController As ProductController = New ProductController 
    lsData = oController.findAll()
End Sub

Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click
    Dim htData As Hashtable
    Dim iIndex As Integer
    iIndex = 0
    iCurrentIndex = iIndex
    htData = lsData.Item(iIndex)

    Dim sProductDetails As String
    sProductDetails = CStr(htData("SKU"))
    sProductDetails = sProductDetails & " | " & CStr(htData("ProductName"))
    sProductDetails = sProductDetails & " | " & CStr(htData("ProductDescription"))
    sProductDetails = sProductDetails & " | " & CStr(htData("Category"))
    sProductDetails = sProductDetails & " | " & CInt(htData("ReorderLevel"))
    sProductDetails = sProductDetails & " | " & CInt(htData("LeadTime"))
    sProductDetails = sProductDetails & " | " & CInt(htData("Discontinued"))
    sProductDetails = sProductDetails & " | " & CDbl(htData("UnitPrice"))
    Debug.Print("ProductDetails: " & vbCrLf & sProductDetails)
End Sub
Posted
Comments
Paulo Zemek 29-Sep-15 19:12pm    
A navigation using hashtables? Are you sure you want to do that?
A hashtable is a way of indexing data. The purpose of the hashtable is not to navigate records (be it one by one, by page or anything similar). The purpose is to find an item as fast as possible by its key.

For example, when you use htData(...) if htData is a hashtable, it will find the value for the provided parameter (the key) as fast as possible. It actually doesn't matter if the pair (key/value) is located as first item or as last item.
Member 12021055 30-Sep-15 4:01am    
Hi Paulo,

I think that perhaps I have just worded this incorrectly.

Basically, the way I'm storing data from the SELECT query is by using hashtables.

My question is how do I implement navigation (i.e. first/last/next/prev) for this data I'm storing in these hashtables and thus in my forms?

In the above code, I can get it to display in the immediate window (though I can only get 'last' and 'first' working, not 'previous' and 'next')

Thava Rajan 30-Sep-15 0:41am    
actually what kind of workout you want? please elabrate
Member 12021055 30-Sep-15 5:19am    
Basically, the way I'm storing data from the SELECT query is by using hashtables.

My question is how do I implement navigation (i.e. first/last/next/prev) for this data I'm storing in these hashtables and thus in my forms?

In the above code, I can get it to display in the immediate window (though I can only get 'last' and 'first' working, not 'previous' and 'next')
Thava Rajan 1-Oct-15 0:29am    
there are lot of ways there,
just for curiosity may i know why you choose the hashtables?

1 solution

Ok. I think that I understood your case now.

You have a list. Each item in the list is a HashTable, which represents the columns and values of a single record.

How you will read the hashtable and show it on the screen is up to you. But considering your code that Debug.Print the record data, you may want to:

Put the code to show the record (by index) on another method.
When going to the previous record, you simply decrement the record index and call that method.
When going to the next record, you simply increment the record index and call that method.
When going to the first record, simply set the record index and call that method.
When going to the last record, set the record index to the total number of records less one (as the index is zero based).


You will probably want to put validations do disable the first, previous when in the first record and to disable the last/next record when on the last record.

Your navigation is actually TABLE based. The HashTables only represent a single row, so you never navigate the HashTable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900