Specifying rowfilter criteria to be evaluated in DataTable event handlers
<p>We have a mini business application framework of our own to meet our custom needs. We are using datatables in our business classes for storing collections (e.g. detail data). Our framework identifies any datatable type properties declared in a business object and attaches a few event handlers to provide services like authorization control, change tracking etc. Things are running fine but today a small requirement got me a little baffled.</p>

<p>Apart from all authorization requirements e.g. role based access to edit the datatable, edit some columns of the datatable etc., our devs now require to specify a criteria for a datatable and all the matching rows (fulfilling that criteria) will then be prevented from editing.</p>

<p>For example if there is a datatable having values as below - </p>

<hr>

<p>SettingName | Value | IsPolicyControlled</p>

<hr>

<p>Setting1    | 10 | False</p>

<p>Setting2    | 20 | True</p>

<hr>

<p>The devs want to specify a criteria through our business framework as below -</p>

<p>someBusinessObject.MakeReadOnly("Settings", "IsPolicyControlled == true");</p>

<p>the first parameter being the datatable name and second the criteria for readonly rows. Now as the framework developer my duty will be to prevent any editing in any rows that match the specified condition.</p>

<p>For that I can attach some event handler to that datatable to monitor any changes that are being made, e.g. I can handle RowChanging to monitor the change being made. Now I need to verify that whether the row that is being changed matches the specified condition. Something like </p>

<p>if (RowMatchesCondition(e.Row))
     // block changes</p>

<p>Now I could find no optimized mechanism of getting this done. One thing that came to my find is to use a DataTable.Select() method with that condition and to check if the current row (in RowChanging) exists within the returned DataRow array. But I am looking for a little better solution.</p>

<p>Thanks for any help buddies.</p>
