Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

bindingSourceから型付き行の取り出しとか新規行の取得

More than 3 years have passed since last update.

こっちも、備忘録的な感じですがコード書き終わるとだいたい忘れてしまうのでメモ
拡張で書いておくと、楽に変換出来るかもつう事でソースです
どちらのメソッドも、見ての通り、DataRowViewからRowを取り出すんですけど
これを結構忘れてスタックしがち(笑)
ご参考になれば幸いです。

buindingSource.cs
    public static class BindingSourceExtensions
    {
        public static T GetCurrent<T>(this BindingSource bs) where T : class
        {
            T funcRet = null;
            DataRowView current = bs.Current as DataRowView;
            if (current != null) {
                funcRet = current.Row as T;
            }
            return funcRet;
        }

        public static T GetNewRow<T>(this BindingSource bs) where T : class
        {
            T funcRet = null;
            DataRowView addRow = bs.AddNew() as DataRowView;
            if (addRow != null) {
                funcRet = addRow.Row as T;
            }
            return funcRet;
        }
    }


Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away