Dataview Find not in sync with CurrencyManager

D

Dana L. Stille

I have incorporated a search function into my .NET application. I use the Find method in the DataView, and return the index of the associated record. I use this integer to set the Position property of my BindingManager on my form. Refer to the code snippet below. When I use the search function on my development machine it works great, but when I install my application on another machine and use the search function the BindingManager is set to the same position but the controls on the form do not show the correct data. It is as if the dataset is index differently. I am setting the ApplyDefaultSort property to True, and from what I can gather this will align the DataView with the sort order of the dataset table I am using.

_________________________________________________________________________________________
' If Find routine is being used set the current SCR integer so that the

' binding manager can be position to the correct record in the dataset

If strGoToSCR <> "" Then

intCurrentSCR = dvSCRData.Find(strGoToSCR)

strGoToSCR = ""

End If

'If Current SCR Number is available search for it, and if its in the dataset move to it

If intCurrentSCR > 0 Then

SCRBindingManager.Position = intCurrentSCR

intCurrentSCR = 0

Else

SCRBindingManager.Position = SCRDataSet.scrdata.Rows.Count - 1

End If

_____________________________________________________________________________________

I would appreciate any suggestions on how to better position my data to the record I am searching. Thanks, and God Bless!
 
C

Cor Ligthert

Dana,

If the datasource of your bindings is dvSCRData than it would probably go
well (when the dataview has no rowfilter).

However when you have used another source than it should go wrong whatever
computer is used.

Therefore what is the datasource that you are using?

Cor
 
D

Dana L. Stille

The datasource is a dataset with a single datatable constructed from an SQL
statement. The SQL is used to pull records from an Access database. The
development computer and non-development are running the same version of the
..NET application which uses the same code to create the dataset. The
dataview property "DataViewRowState" is set to the default "CurrentRows."
During the debug process I check to make sure the dataview and the
bindingmanager had the same number of records, and they did. As I stated
before when I perform the search using the dataview "Find" method the same
index number is returned on each computer, but the non-development computer
does not show the correct data associated with the index number.
 
C

Cor Ligthert

Dana,

A problem with the dataview.find is that it needs a sort. When the user does
a sort in by instance a datagrid than that is gone. (However as well when
there is added a row at the end what has an outsequence key what will be
used for the find) The most easy solution is of course to make from the
dataview your datasource.

I hope this helps,

Cor
 
D

Dana L. Stille

Cor,

The SQL statement the constructs the dataset is using the Primary Key field
for the sort ( ORDER BY MOD_NO ASC). So, I used the following code to try to
align the DataView with the sort order of the DataTable. I was thinking that
by using the "ApplyDefaultSort" property and setting it to "True" would
cause the DataView to be sorted the same as the Order By statement in the
SQL statement.

SCRDataSet.Merge(dsSCR, False, MissingSchemaAction.AddWithKey)

dvSCRData = SCRDataSet.scrdata.DefaultView

dvSCRData.ApplyDefaultSort = True

SCRBindingManager = Me.BindingContext(SCRDataSet, AC.SCRSettings.TableName)

I have also tried using the Sort property for the DataView. I set the Sort
property to "MOD_NO ASC". This did not help either.
 
C

Cor Ligthert

Dana,

I tried something.
(I agree with you that there are on first sight some weird things when it is
with the sort of the datagrid)

Maybe can you try this as well

\\\
'\\needs a datagrid, a textbox and a button
Private Sub Form9_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Id")
dt.Columns.Add("Name")
dt.LoadDataRow(New Object() {"1", "Dana"}, True)
dt.LoadDataRow(New Object() {"2", "Bruce"}, True)
dt.LoadDataRow(New Object() {"3", "Cor"}, True)
dt.DefaultView.Sort = "Id"
dt.DefaultView.RowFilter = "Id < 3"
DataGrid1.DataSource = dt.DefaultView
DataGrid1.AllowSorting = False
TextBox1.Text = ""
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = DirectCast(DataGrid1.DataSource,
DataView).Table
Dim dv As New DataView(dt)
dv.Sort = "Id"
Dim pos As Integer = dv.Find("3")
TextBox1.Text = dt.Rows(pos)("Name").ToString
End Sub
///

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top