Same CurrentRow in Datagrid as before...

  • Thread starter Thread starter P Dietz
  • Start date Start date
P

P Dietz

Hello,
I'm using a datagrid to show data (ok, what else...), and
by doubleclick on a row I first hide the Datagrid-Form
and start another form to work with the data.
After returníng to the Datagrid-Form and reload the data I
would like to jump to the same row as i was before.

To get the actual row before leave the form, I use

aktID = dvProt(Me.dgProt.CurrentRowIndex)!naqs_ID.toString
Sort = dvProt.Sort
where dgprot is the datagrid and dvprot the dataview of
the dataset.table("prot")

then
me.hide
frmEditData.showdialog

LoadDataNew() 'to load the data again from the database

and now?
to set the same sort-sequence as before,
dvprot.sort=sort is good,
but how can i find the row?
dvprot.find searches the sort-column, but sort-column and
ID must not be the same:-(

Thanks for help!

Peter
 
Hello Peter,

since DataView.Find only searches the sorted columns, you could implement
the search yourself by going through the rows in the DataView. Here's a
simple example (you can improve it for your needs):

Private Function FindRow(ByVal dataView as DataView, ByVal columnName
As String, ByVal value As Object) As Integer
Dim index As Integer = 0
For Each drv As DataRowView In dataView
If drv(columnName) = value Then
Return index
End If

index += 1
Next

Return -1
End Function

This function will search the given column of the given dataView for a
value that matches what you're interested into. This assumes that your IDs
are unique else there might be more than one row that will match. The you
can user it like this:

Dim rowIndex = FindRow(myDataView, "ID", 1051)

HTH

Antoine
Microsoft Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
Content-Class: urn:content-classes:message
From: "P Dietz" <[email protected]>
Sender: "P Dietz" <[email protected]>
Subject: Same CurrentRow in Datagrid as before...
Date: Tue, 21 Oct 2003 05:57:53 -0700
Lines: 31
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOX0vEFL0hxaEGWSsO4gc1srb71KA==
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:148638
NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Hello,
I'm using a datagrid to show data (ok, what else...), and
by doubleclick on a row I first hide the Datagrid-Form
and start another form to work with the data.
After returníng to the Datagrid-Form and reload the data I
would like to jump to the same row as i was before.
To get the actual row before leave the form, I use
aktID = dvProt(Me.dgProt.CurrentRowIndex)!naqs_ID.toString
Sort = dvProt.Sort
where dgprot is the datagrid and dvprot the dataview of
the dataset.table("prot")
then
me.hide
frmEditData.showdialog
LoadDataNew() 'to load the data again from the database
and now?
to set the same sort-sequence as before,
dvprot.sort=sort is good,
but how can i find the row?
dvprot.find searches the sort-column, but sort-column and
ID must not be the same:-(
Thanks for help!
Peter


This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top