Dataset Navigation - on primary key

bobberz

New member
Joined
Apr 11, 2005
Messages
3
Programming Experience
5-10
I have been pulling my hair out over this and would appreciate any help!! I have a relational dataset (objdsCompanies) that is displayed and bound on tabpage1. I apply a search on a different tabpage; this creates a second dataset (dsSearch) that holds CompanyName and CompanyID and populates a listbox (realise now after much reading here that this could be a datatable not a DS!). The listbox passes the CompanyID value. What i would like to happen is the listbox item clicked navigates the main tabpage to the selected index (CompanyID is the primary key and is passed on selectedIndexChange), I have tried retrieving the bindingcontext position value of the record to no avail. I can find the row (FindByCompanyID) in the main dataset (objdsCompanies) but as stated i would just like the bound dataset to remain whole (not filtered) and this search function to point to the associated record ie possibly change the position value of the record in objdsCompanies?

I think i may have to iterate through the whole dataset and stop when CompanyID = passed value. Was initially thinking of setting the bindingcontext position value to CompanyID as the initial order on the main tabpage which is (currently) not sorted, but then the navigation functionality increments the .position value so this would not work (I dont think anyway). I thought i had it cracked when I selected the row from the dataset...then query its position value...hmmm, DOH! =0!
I have had a play with dataviews but this functionality filters and is not appropriate here.
Also Im not using datagrids, just textboxes with info like CompanyAddress,CompanyPostcode etc for the main info form/tabpage then have relational bound listboxes that list things like email addresses, reports, URLs and Infringements which are all dynamic dependant on selected CompanyID. It is a little awkward as i am now thinking in SQL as opposed to VB.Net!!

I would appreciate any advice/thoughts, PB
 
Ooops, OLEDB datasets/connections accessing an Access database, purely used for offline storage ie no relations etc within access.

BoB

...just tried the following and cannot understand why it is not working...any ideas? companyID is the passed value form the listbox, CompanyID is the Company table key:
Me.BindingContext(objdsCompanyInfo, "Company").Position.Equals(Me.objdsCompanyInfo.Tables("Company").Rows(companyID)("CompanyID"))

Appreciate any pointers...literally!!
BoB
 
Last edited:
Result!

Sorted...but not ideal, performance is slow when navigating deeper into the dataset, function as follows (companyID is passed as listbox index which is CompanyID):

Dim count AsInteger = 0
Me.BindingContext(objdsCompanyInfo, "Company").Position = 0 'set to start of dataset
While (Not (companyID = Me.objdsCompanyInfo.Company.Rows(count).Item("CompanyID").ToString))
Me.BindingContext(objdsCompanyInfo, "Company").Position = count
count += 1
EndWhile
Me.BindingContext(objdsCompanyInfo, "Company").Position = Me.BindingContext(objdsCompanyInfo, "Company").Position + 1 'neccessary due to position starting at 0 not 1


If anyone has a better solution i would appreciate it!! Cheers
 
Back
Top