从一个DataRow获取默认视图DataRowView的 [英] Get the DefaultView DataRowView from a DataRow

查看:198
本文介绍了从一个DataRow获取默认视图DataRowView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的情况:我需要绑定一个WPF 固定页面针对的DataRow 。绑定不会对数据行工作;他们对 DataRowViews 工作。我需要做的这可能是最通用的方法,因为我什么都不知道,并已超过什么是在的DataRow 无法控制的。

Here's the situation: I need to bind a WPF FixedPage against a DataRow. Bindings don't work against DataRows; they work against DataRowViews. I need to do this in the most generic way possible, as I know nothing about and have no control over what is in the DataRow.

我需要的是能够得到一个 DataRowView的对于给定的的DataRow 。我不能使用查找()的方法默认视图,因为这需要一个密钥,难保该表将有一个主键设置。

What I need is to be able to get a DataRowView for a given DataRow. I can't use the Find() method on the DefaultView because that takes a key, and there is no guarantee the table will have a primary key set.

是否有人有一个建议,以最好的方式去解决呢?

Does anybody have a suggestion as to the best way to go around this?

推荐答案

不完全是一个性感的一张code,但他们似乎并没有被找到该行没有正当循环表自动的方式。

Not Exactly a sexy piece of code but their doesn't seem to be an automated way to find the row without just looping the table.

        DataRowView newRowView = null;
        foreach (DataRowView tempRowView in myDataTable.DefaultView)
        {
            if (tempRowView.Row == rowToMatch)
                newRowView = tempRowView;
        }
        if (newRow != null)
            UseNewRowView(newRowView);
        else
            HandleRowNotFound();

这篇关于从一个DataRow获取默认视图DataRowView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆