I am working with a UltraWinGrid which has an attached UltraDataSource. Im using vb.NET to develop my application. My problem is that I cannot find an easy way to check if a row exists within the rows collection of either the WinGrid or the DataSource.
To add a new row to the datasource im using the following code:-
Dim o = New Object() {False, emailImage, status}dsDocuments.Rows.Add(o)
This will add the row to the datasource and the wingrid fine, however some of the rows which I will add contain duplicate data and I need a way to detect if the data already exists so I can cancel the row being added. I have tried using the following to no avail:-
If Not (dsDocuments.Rows.Contains(o)) Then dsDocuments.Rows.Add(o)End If
However the compiler shows an error as the array cannot be converted to an gridrow or a datasourcerow. I have tried using the events raised (rowadding & rowadded) and still cannot find a solution.Is there an easy way to check if a duplicate row exists without looping through each row?
Thanks
Sean
Hi Sean,
You will have to loop through the rows and compare the values of each field. You cannot use Contains, because Contains is probably expecting you to pass in a DataRow - and even if you had a DataRow, it would just do a reference comparison, which would never be true.
One of the columns in my data contains a unique ID, so I ordered my data on this column and when it came to adding rows I compared the current ID to the previous to see if it existed, rather than looping through hundreds of rows.
Thanks for the reply.