かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

[WPF][C#]IEditableCollectionView その5

IEditableCollectionViewの登録・更新・削除のときの動きを今までさらっと見てみた。
IEditableCollectionViewの動き自体は、ちゃんと見てみると何も難しくないと思う。
(きちんと連携させるためのIEditableObjectの実装がめんどくさいことを除いて)

ということで(どういうことで?)今回は、今まで避けてきたIEdltableCollectionViewのNewItemPlaceholderPositionプロパティを見てみようと思う。
NewItemPlaceholderPositionは、新規追加が可能なUIを構築するときに、その場所を提供するためのダミーのオブジェクトを何処に追加するかということが設定できる。
DataGridViewで、追加を有効にしたときに一番最後の行に表示される空の行みたいなのを提供するためのものっぽいです。

コンソールからでも、ListCollectionViewクラスのCountプロパティを通じて存在を確認することは出来るけど、GUIで見たほうがてっとり早いので、今回はGUIのプロジェクトを作ってやってみようと思う。
新規作成で、NewItemPlaceというプロジェクトを作って、いつものPersonクラスを定義する。

namespace NewItemPlace
{
    public class Person
    {
        public string Name { get; set; }
        public override string ToString()
        {
            return base.ToString() + ": " + this.Name;
        }
    }
}

ToStringのオーバーライドは、後でListBoxに表示したときにDataTemplateをこさえるのがめんどくさいから手抜きしています。
さて、これのListCollectionViewのインスタンスを作ってWindowのDataContextに突っ込んでおく。

using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Data;

namespace NewItemPlace
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();


            // IEditableCollectionViewを作って
            var people = 
                Enumerable.Range(1, 5).Select(i =>
                    new Person { Name = "田中 太郎" + i }).ToList();
            var view = (IEditableCollectionView)CollectionViewSource.GetDefaultView(people);

            // DataContextに設定
            DataContext = view;
        }
    }
}

XAML側は、さくっとListBoxを設置する。

<Window x:Class="NewItemPlace.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <ListBox ItemsSource="{Binding}" />
    </Grid>
</Window>

実行すると、PersonのToStringの結果がずらっと表示される。
image

これに、NewItemPlaceholderPositionプロパティの値をいじくって実行結果を見ていく。
コード的には、以下のような感じになる。

using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Data;

namespace NewItemPlace
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();


            // IEditableCollectionViewを作って
            var people = 
                Enumerable.Range(1, 5).Select(i =>
                    new Person { Name = "田中 太郎" + i }).ToList();
            var view = (IEditableCollectionView)CollectionViewSource.GetDefaultView(people);

            // ここでセットしますぞ!!
            view.NewItemPlaceholderPosition = NewItemPlaceholderPosition.None;

            // DataContextに設定
            DataContext = view;
        }
    }
}

NewItemPlaceholderPositionプロパティは、NewItemPlaceholderPosition列挙体の値を代入することが出来ます。
NewItemPlaceholderPosotion列挙体は、None(デフォルト),AtEnd,AtBeginningの3つの値が定義されています。Noneのときの結果は、上で示した実行結果なので、残りの値にしたときの実行結果を以下に示します。

AtEnd
image

AtBeginning
image

最初と最後に、NewItemPlaceholderがくっついてるのが見て取れる。
ここに、新規登録用のUIを用意して、ごにょごにょするといった感じに使うのだろう。

ただ、これにきっちり対応したものを作ろうと思うと大変そうな気がする。
おとなしくWPF ToolkitのDataGridが完成するのを待つのがよろしいような気がする今日この頃でした。

投稿日時 : 2009年1月1日 20:13

Feedback

# IEditableCollectionView 2009/01/02 10:17 えムナウ Blog

IEditableCollectionView

# moncler jackets 2012/12/08 6:34 http://supermonclercoats.webs.com/

Some really wonderful information, Gladiolus I found this. "Genius is one of the many forms of insanity." by Cesare Lombroso.

# la redoute soldes 2012/12/12 10:54 http://www.laredoutecode.com/

Our undesirable means by which to lose people might be placed best with it understanding you possibly can‘longer have them.

# longchamp le pliage 2012/12/14 20:41 http://www.saclongchampachete.com/category/sac-lon

Looking ahead to looking at more!

# longchamp outlet prix 2012/12/15 15:49 http://www.soldesacslongchamp.info/category/prix-s

I go along with the expensive garbage provide feedback. I can't stand the glance, sound or even feel of the Beats.

# burberry outlet 2012/12/15 22:53 http://www.burberryuksale.co/burberry-uk-bags-c-48

Hi, i've really been a lurker around your website for several months.

# sac longchamp pliage 2012/12/16 17:53 http://www.saclongchampachete.info/category/sac-lo

i commend you onto your great content material and superb topic possibilities.

# burberry femme soldes 2012/12/17 2:46 http://www.sacburberryecharpe.fr/category/burberry

I have not looked to Sennheisers and additionally am short of new tote.

# トリーバーチ 2012 2012/12/17 20:59 http://www.torybruchjp.info/category/トリーバーチ

Ill be back the track to view other blogposts that.

# longchamp pliage 2012/12/21 4:32 http://sacslongchamppliage.monwebeden.fr

i compliment you on your great material and great topic picks.

# sac a main michael kors pas cher 2012/12/22 17:54 http://sacmichaelkorssoldes.monwebeden.fr/#/bienve

this is something relating to never actually read.

# http://www.destockchinefr.fr/maillot-de-club-pas-cher/serie-a-pas-cher/ 2013/01/13 4:39 http://www.destockchinefr.fr/maillot-de-club-pas-c

Our hardest strategy to neglect a friend or relative should be laying perfect alongside these knowing you could憑t|capital t|big t|to|testosterone levels|testosterone|w not|longer|l|r|g|s|h|d|p|T|metric ton|MT|tonne} keep these things.
http://www.destockchinefr.fr/maillot-de-club-pas-cher/serie-a-pas-cher/ http://www.destockchinefr.fr/maillot-de-club-pas-cher/serie-a-pas-cher/

# cAhVdpeueRRmP 2014/08/05 6:06 http://crorkz.com/

c8Gju5 I truly appreciate this blog article.Thanks Again. Fantastic.

# JmfhTHCkBKfZW 2014/08/28 6:52 http://crorkz.com/

diU0he Hello, you used to write great, but the last several posts have been kinda boring??? I miss your super writings. Past several posts are just a little out of track! come on!

# Colin Dexter 13 ebooks PDF Collection To Download go to http://we.hwv.pw/5l 2014/12/19 15:43 CBgfUToobs

L J Smith 19 ebooks Collection PDF MOBI EPUB To Download go to http://8.tvv.pw/tsc

# cartier love bracelet silver replica 2015/07/29 16:26 refkcafq@aol.com

So you only wash your hair once or twice a week? How do you keep it looking great in between washes? I’m so jealous of girls that can do that, my hair gets so oily so quickly and the poor stuff is so damaged from heat.
cartier love bracelet silver replica http://www.lovejewellerywomen.com/

# Hi Abdul. Thanks for this useful article. When I tried it, although the page 1 of the site shows as PR6 with the firefox SEOQquake plugin, I didn't find any pages that I commented on that had anything like that page rank. Am I doing something wrong? 2019/07/25 6:01 Hi Abdul. Thanks for this useful article. When I t

Hi Abdul. Thanks for this useful article. When I tried it, although the page
1 of the site shows as PR6 with the firefox SEOQquake plugin, I didn't find
any pages that I commented on that had anything like that page rank.
Am I doing something wrong?

# Hi Abdul. Thanks for this useful article. When I tried it, although the page 1 of the site shows as PR6 with the firefox SEOQquake plugin, I didn't find any pages that I commented on that had anything like that page rank. Am I doing something wrong? 2019/07/25 6:04 Hi Abdul. Thanks for this useful article. When I t

Hi Abdul. Thanks for this useful article. When I tried it, although the page
1 of the site shows as PR6 with the firefox SEOQquake plugin, I didn't find
any pages that I commented on that had anything like that page rank.
Am I doing something wrong?

# Hi Abdul. Thanks for this useful article. When I tried it, although the page 1 of the site shows as PR6 with the firefox SEOQquake plugin, I didn't find any pages that I commented on that had anything like that page rank. Am I doing something wrong? 2019/07/25 6:06 Hi Abdul. Thanks for this useful article. When I t

Hi Abdul. Thanks for this useful article. When I tried it, although the page
1 of the site shows as PR6 with the firefox SEOQquake plugin, I didn't find
any pages that I commented on that had anything like that page rank.
Am I doing something wrong?

# cjUdPkytSrfeVXe 2021/07/03 4:59 https://www.blogger.com/profile/060647091882378654

I saw plenty of website but I conceive this one contains a thing special in it. The finest effect regarding fine people is experienced after we ave got left their presence. by Rob Waldo Emerson.

# re: [WPF][C#]IEditableCollectionView ??5 2021/07/06 10:12 hydroxychloroquine risks

chloroquine side effect https://chloroquineorigin.com/# what is hydroxychloride

# is erectile dysfunction reversible 2021/07/07 21:52 malaria drug hydroxychloroquine

dolquine https://plaquenilx.com/# quineprox

# re: [WPF][C#]IEditableCollectionView ??5 2021/07/12 8:47 risks of hydroxychloroquine

is chloroquine a sulfa drug https://chloroquineorigin.com/# chloroquine phosphate vs hydroxychloroquine

# Wonderful, what a webpage it is! This web site provides valuable data to us, keep it up. 2021/07/27 8:43 Wonderful, what a webpage it is! This web site pro

Wonderful, what a webpage it is! This web site provides valuable data to us, keep it up.

# Wonderful, what a webpage it is! This web site provides valuable data to us, keep it up. 2021/07/27 8:46 Wonderful, what a webpage it is! This web site pro

Wonderful, what a webpage it is! This web site provides valuable data to us, keep it up.

# Wonderful, what a webpage it is! This web site provides valuable data to us, keep it up. 2021/07/27 8:49 Wonderful, what a webpage it is! This web site pro

Wonderful, what a webpage it is! This web site provides valuable data to us, keep it up.

# Wonderful, what a webpage it is! This web site provides valuable data to us, keep it up. 2021/07/27 8:52 Wonderful, what a webpage it is! This web site pro

Wonderful, what a webpage it is! This web site provides valuable data to us, keep it up.

# I always spent my half an hour to read this webpage's content every day along with a mug of coffee. 2021/08/04 13:19 I always spent my half an hour to read this webpag

I always spent my half an hour to read this webpage's content every day
along with a mug of coffee.

# Why people still make use of to read news papers when in this technological globe all is presented on web? 2021/08/24 3:46 Why people still make use of to read news papers w

Why people still make use of to read news papers when in this technological globe all
is presented on web?

# Why people still make use of to read news papers when in this technological globe all is presented on web? 2021/08/24 3:47 Why people still make use of to read news papers w

Why people still make use of to read news papers when in this technological globe all
is presented on web?

# Why people still make use of to read news papers when in this technological globe all is presented on web? 2021/08/24 3:48 Why people still make use of to read news papers w

Why people still make use of to read news papers when in this technological globe all
is presented on web?

# Why people still make use of to read news papers when in this technological globe all is presented on web? 2021/08/24 3:49 Why people still make use of to read news papers w

Why people still make use of to read news papers when in this technological globe all
is presented on web?

# Thanks for the auspicious writeup. It in reality was a entertainment account it. Look advanced to far brought agreeable from you! By the way, how could we be in contact? 2021/08/26 7:31 Thanks for the auspicious writeup. It in reality w

Thanks for the auspicious writeup. It in reality was a entertainment account it.
Look advanced to far brought agreeable from you!
By the way, how could we be in contact?

# Hey there! I just wanted to ask if you ever have any trouble with hackers? My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no data backup. Do you have any methods to protect against hackers? 2021/08/31 19:39 Hey there! I just wanted to ask if you ever have a

Hey there! I just wanted to ask if you ever have any trouble with hackers?
My last blog (wordpress) was hacked and I ended up losing a few months of hard work due
to no data backup. Do you have any methods to protect against hackers?

# It's an amazing article in favor of all the web people; they will get benefit from it I am sure. 2021/09/01 19:49 It's an amazing article in favor of all the web pe

It's an amazing article in favor of all the web people; they
will get benefit from it I am sure.

# I love what you guys are usually up too. This type of clever work and coverage! Keep up the amazing works guys I've incorporated you guys to blogroll. 2021/09/03 10:55 I love what you guys are usually up too. This type

I love what you guys are usually up too. This type of clever work
and coverage! Keep up the amazing works guys I've incorporated you guys to blogroll.

# I always used to study article in news papers but now as I am a user of internet therefore from now I am using net for articles, thanks to web. 2021/09/04 16:10 I always used to study article in news papers but

I always used to study article in news papers but now as I am a user of internet therefore from
now I am using net for articles, thanks to web.

# I always used to study article in news papers but now as I am a user of internet therefore from now I am using net for articles, thanks to web. 2021/09/04 16:11 I always used to study article in news papers but

I always used to study article in news papers but now as I am a user of internet therefore from
now I am using net for articles, thanks to web.

# I always used to study article in news papers but now as I am a user of internet therefore from now I am using net for articles, thanks to web. 2021/09/04 16:12 I always used to study article in news papers but

I always used to study article in news papers but now as I am a user of internet therefore from
now I am using net for articles, thanks to web.

# I always used to study article in news papers but now as I am a user of internet therefore from now I am using net for articles, thanks to web. 2021/09/04 16:13 I always used to study article in news papers but

I always used to study article in news papers but now as I am a user of internet therefore from
now I am using net for articles, thanks to web.

# I am regular reader, how are you everybody? This paragraph posted at this site is genuinely fastidious. https://parttimejobshiredin30minutes.wildapricot.org/ part time jobs hired in 30 minutes 2021/10/22 21:19 I am regular reader, how are you everybody? This p

I am regular reader, how are you everybody?
This paragraph posted at this site is genuinely fastidious.
https://parttimejobshiredin30minutes.wildapricot.org/ part
time jobs hired in 30 minutes

# Link exchange is nothing else however it is only placing the other person's website link on your page at suitable place and other person will also do similar in favor of you. 2021/10/26 15:35 Link exchange is nothing else however it is only p

Link exchange is nothing else however it is only placing the other person's website link on your page at suitable place and other person will also
do similar in favor of you.

# Just wish to say your article is as surprising. The clearness for your post is just cool and that i could think you're knowledgeable in this subject. Well with your permission allow me to grab your feed to stay up to date with imminent post. Thanks one 2021/12/06 23:32 Just wish to say your article is as surprising. Th

Just wish to say your article is as surprising.
The clearness for your post is just cool and that i could think you're knowledgeable in this subject.
Well with your permission allow me to grab your feed to stay up to date
with imminent post. Thanks one million and please keep up the gratifying work.

# bknxvifofsze 2022/05/06 17:25 meeifw

hydroxychloroquine side effects heart https://keys-chloroquinehydro.com/

# blmmnwfxxsjb 2022/05/17 1:06 oytpht

hydroxychloroquine sulfate 200 mg oral tablet https://keys-chloroquineclinique.com/

# hydroxychloroquine buy online 2022/12/25 15:56 MorrisReaks

generic chloroquine phosphate https://hydroxychloroquinex.com/

タイトル
名前
Url
コメント