Navigating DataSet when using BindingSource?

Bisto

Member
Joined
Jan 25, 2007
Messages
6
Programming Experience
Beginner
Hello people,
Please can anyone tell me how best to navigate records when using a BindingSource? All the examples I can find on the internet dont mention the BindingSource. I'm basically using BindingContext to naviagte (i.e next, previous, last etc).

Thanks,
Bisto
 
YourBindingSource.MoveFirst
YourBindingSource.MoveLast
YourBindingSource.MoveNext
YourBindingSource.MovePrevious
and
YourBindingSource.Position=index_of_row
 
YourBindingSource.Position=index_of_row

This might not strictly be correct.. You see the BindingSource has its own internal list which might be a subset of the original source if a filter is applied. Thuis, your datatable rows might number 100 but the bindingsource list only has 10 items thanks to a filter. Asking the bindingsource to move to position 78 will either result in an error, or it will move to the last item in its list
 
You are right. That index_of_row means index of row in BindingSource list, NOT index of DataRow from DataTable.
 
Thank you for all the replies people, worked great.
My next question which is kind of related is, how do you delete a record which has relating fields in related tables? I get an error saying that it cannot delete because of related records.

Thanks,
Bisto
 
delete the children too?

either set the relation to delete them for you, or GetChildRows on the parent, delete the children then delete the parent
 
YourBindingSource.Position=index_of_row
This might not strictly be correct.. You see the BindingSource has its own internal list which might be a subset of the original source if a filter is applied. Thuis, your datatable rows might number 100 but the bindingsource list only has 10 items thanks to a filter. Asking the bindingsource to move to position 78 will either result in an error, or it will move to the last item in its list

You are right. That index_of_row means index of row in BindingSource list, NOT index of DataRow from DataTable.

Hello dranko and cjard,
This point still comes back to make me ponder about this... having another filter on a set BindingSource.
If you have a DataSet that is 'filtered' through a SQL statement or otherwise that a BindingSource is bound to... why would you have another filter set or bound to that BindingSource instead of creating new one?
 
You never wanted to download a set of, say, 100 customers, but then when you were looking at the data, you realised that you just wanted to provide a box for the user to type in to quickly find all the Males, or all the Females?

Sure you can download them all again, but you have to balance out; do you really want the server doing millions of inane queries just to quickly highlight a few records that the user already downloaded?

Also, say you make a combo with all the columns in it and provide a UI where it looks like:

FIND all rows where [DROP DOWN COMBO#] contaisn the text [TEXT BOX FOR FREE TYPING]
It's a lot easier to say:
VB.NET:
myBS.Filter = String.Format("{0} = '{1}'", myDropdown.Text, myTextBox.Text)

THan it is to create a whole new data aapter with the chosen column, add a param, popualte it, send it to the db.. damn, i'm getting bored just writing about it.

But you WOULDNT use bs.Filter to reduce millions of records to 1 or 2 - the server does the heavy searching, the client keeps it light.


Note also, just because its there doesnt mean you HAVE to use it..
 
I also use it as a kinda trick for those lsits where you have everything on the left, and then double click items to move them to the right, to pick.. you know?

One of these:
edit_navbar.gif


1 table, 2 BS, table has all items, and column "Picked Qty"
BS on left has filter "PickedQty = 0"
BS on right has "PickedQty > 0"
clicking item in left, raises quantity, clicking item in right, lowers quantity

items "move" magically because filters do/dont apply

There ar eloads of tricks for them, just gotta think some more
 
Guys,

I am trying the same but the records are not changing for me.
Below is the code I am using for the same.


BindingSource1.MoveNext()

I am not getting any error.

Please guide.

Regards
Sudhir
 

Latest posts

Back
Top