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 53an I M VB.NET DEVELOPER in my project i check and prevent to add duplicate row in this way PLEASE CHANGE ACCORDING YOUR REQUIRMENT
Dim frmdrug As New frmDrugSearch Dim rw As UltraGridRow = Cbxprovider.SelectedRow()
If frmdrug.ShowDialog(ListFormOpenMode.SelectionOnly) = Windows.Forms.DialogResult.OK Then If dsView.Tables(0).Select("DRUG_NDC = '" + frmdrug.DRUG_NDC + "' AND PROVIDER_ID = " + selectedProvider + " ").Length = 0 Then Dim newRow As DataRow = dsView.Tables(0).NewRow newRow("DRUG_ID") = frmdrug.MEDICATION_ID newRow("DRUG_NDC") = frmdrug.DRUG_NDC newRow("DRUG_NAME") = frmdrug.BRAND_NAME newRow("ACTIVE") = True newRow("PROVIDER_ID") = selectedProvider dsView.Tables(0).Rows.Add(newRow) Else MessageBox.Show("Selected DRUG Already Exists", "Add") End If
IF U NEED MORE HELP PLEASE CONTACT ME AT BELOW LINK
http://ahmadkhalid44.blogspot.com/
Regards:
Ahmad Khalid
Software Engineer
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.
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.