开发者

Specifying rowfilter criteria to be evaluated in DataTable event handlers

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.

开发者_如何学C

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.

For example if there is a datatable having values as below -


SettingName | Value | IsPolicyControlled


Setting1 | 10 | False

Setting2 | 20 | True


The devs want to specify a criteria through our business framework as below -

someBusinessObject.MakeReadOnly("Settings", "IsPolicyControlled == true");

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.

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

if (RowMatchesCondition(e.Row)) // block changes

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.

Thanks for any help buddies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜