move to the next and the next row datagridview

Richnl

Well-known member
Joined
Mar 20, 2007
Messages
93
Programming Experience
Beginner
Hi,

I have this code placed in a button(btnNext)
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] idx [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32 = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgvJobs.CurrentRow.Index + 1[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgvJobs.Rows(idx).Selected = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]

The thing is that if I move to the next row the thingi on the left(arrow-rowheader) doesn't move also, hence I can move only one row forward.

How can I get the whole row moving forward, backward, to the end?

To do it with a bindingsource is easy(position +/- x), but now I have set a dataview object as a datasource for the gridview.

Thanks, Richard
 
Last edited:
Try this:


Dim iTest As Integer

dgvJobs.SelectionMode = DataGridViewSelectionMode.FullRowSelect

iTest = dgvJobs.SelectedRows(0).Index + 1

dgvJobs.Rows(iTest).Selected =
True


 
To do it with a bindingsource is easy(position +/- x), but now I have set a dataview object as a datasource for the gridview.

So why not make the dataview the datasource for the bindingsource? It's what it uses anyway.. Take a look at the thing you get back by calling BS.Current --> a DataViewRow! :)

Also, given that BS uses a DataView, is there not the possiility that you cen drop the notion of using a DV, and use a BS instead? BS can sort and filter - are you using something else from the DV that BS doesnt have?
 
thanks, Martin for the syntax
thanks Cjard,

Yes, I had to move around in the gridview and be able to sort, hide specificcolumns

I created my own navigate buttons

I think the problem was, that I needed the option to navigate threw all records or just the ones constraint to one ID¨
I had to change datasources
If it makes any sense, I used this
Anyway, it works for now
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] idx [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] bIsdataView [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]idx = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].bsLeden.Position
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].bsLeden.Position = idx + 1
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]idx = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].bsJobs.Position
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].bsJobs.Position = idx + 1
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE]
 
Last edited:
Back
Top