Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to find record in BindingSource?

$
0
0

I have a typed DataTable with a compound primary key. A BindingSource bsTest is used for binding to controls in a WinForms app:

bsTest.DataSource = dsTest;
bsTest.DataMember = dsTest.tblTest.TableName;

The form receives search criteria to select a record, which is done using Linq.  Then it is necessary to position bsTest on the selected record.  Because of the compound PK, the Find method will not work. I coded a work-around as follows:

var rec = tblTest.FirstOrDefault(<critieria>);<validate rec>

// move BindingSource
var dv = (DataView)bsTest.List;
int n = 0;
for (; dv[n].Row != rec; n++);
bsTest.Position = n;
bsTest.ResetCurrentItem();

There must be a better way to accomplish this, no?


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>