とりこらぼ。

Learn from yesterday,
live for today,
hope for tomorrow.

目次

Blog 利用状況

ニュース

プロフィール

  • 名前:とりこびと
    とるに足らない人間です。

  • Wankuma MVP
    for '平々凡々'

Web Site

  • Memo(Of T)

もうひとつの Blog

広告っぽい

書庫

日記カテゴリ

データバインディングのおべんきょ。その5。

データバインディングのおべんきょ。その4。

前回のあらすじ

あ、あ、あれ? 'とりこびと' いないぢゃん!(ToT)

なんとも切ないお話です。もちろん涙が止まりません。バインドしたリストにプログラムコードから新しく追加しても ComboBox1 に反映されませんでした。

なんとかこの問題もズバッと解決したいところですね。いろいろ調べた結果、いくつか方法があるようですので順番に書いていきますね。

まず、一つ目です。さくっと書きます。

List クラス使うのやめちゃう!

ええ、とてもつらいです。つらいですが、仕方ありません。List クラス単独では難しそうなんですもの。なぜかって?

IBindingList インターフェイスを実装してないからです。

MSDN だとこちら↓。

MSDN:IBindingList インターフェイス(http://msdn2.microsoft.com/ja-jp/library/system.componentmodel.ibindinglist(VS.80).aspx)

どうやら、IBindingList インターフェイス の メンバ ListChanged イベントがリストの変更通知としての機能を果たすようですね。で、なんかそれっぽいクラスはないかな~って探してみると・・・

MSDN:BindingList クラス(http://msdn2.microsoft.com/ja-jp/library/ms132679(VS.80).aspx)


いいもん持ってんじゃねーか♪


ええまったく、.NET Framework のクラスライブラリっていろんなクラスがありますね。

前回使用した Form1 のコードを以下のように修正します。

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel


Public Class Form1

    Private _entertainerList As BindingList(Of WankumaEntertainer)

    Private Sub Form1_Load(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.Load
        Me._entertainerList = New BindingList(Of WankumaEntertainer)         Me._entertainerList.RaiseListChangedEvents = True
        Me._entertainerList.Add(New WankumaEntertainer("ぽぴ王子"))         Me._entertainerList.Add(New WankumaEntertainer("アクア"))         Me._entertainerList.Add(New WankumaEntertainer("R・田中一郎"))
        Me.ComboBox1.DataSource = Me._entertainerList         Me.ComboBox1.DisplayMember = "Name"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click
        Me._entertainerList.Add(New WankumaEntertainer("とりこびと"))
    End Sub

End Class

前回 List クラスしていた部分を BindingList に変更しただけですね。RaiseListChangedEvents プロパティは ListChanged イベントを発生させるかどうかを設定できるようです。なので今回は 発生させたいので True にしてあります。(あ、System.ComponentModel を Imports してます。BindingList クラスはSystem.ComponentModel 名前空間にありますので。)

作業はこれでおしまいです。早速実行してみてください。前回、Button1 をクリックすると _entertainerList に新しく 'とりこびと' という Name プロパティ に設定された WankumaEntertainer を追加するコードになっていました。その Button1 をクリックして ComboBox1 のリストが変更されるか確認してみましょう。


新しい自分(とりこびと)がいる!!


というわけで、BindingList クラスというとっても便利なクラスを使用する方法でリストの変更をコントロールに通知する方法でした。




・・・って、今回はそう簡単には終わらせないぞ!フヒヒ


というのも、リストの変更は通知されるようになりましたが、リストの要素の変更はどうでしょう?今回だと _entertainerList に含まれる WankumaEntertainer クラスのインスタンスの Name プロパティが変更された場合、ちゃんと変更されるでしょうか?

ちょっと試してみましょう。デザイナから Form1 にButton を一つ追加して(Button2 で。)Form1 を以下のように変更します。

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel


Public Class Form1

    Private _entertainerList As BindingList(Of WankumaEntertainer)

    Private Sub Form1_Load(ByVal sender As ObjectByVal e As EventArgs) Handles MyBase.Load
        Me._entertainerList = New BindingList(Of WankumaEntertainer)         Me._entertainerList.RaiseListChangedEvents = True
        Me._entertainerList.Add(New WankumaEntertainer("ぽぴ王子"))         Me._entertainerList.Add(New WankumaEntertainer("アクア"))         Me._entertainerList.Add(New WankumaEntertainer("R・田中一郎"))
        Me.ComboBox1.DataSource = Me._entertainerList         Me.ComboBox1.DisplayMember = "Name"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click
        Me._entertainerList.Add(New WankumaEntertainer("とりこびと"))
    End Sub

    ' 書き加えた部分。     Private Sub Button2_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button2.Click
        For Each entertainer As WankumaEntertainer In Me._entertainerList
            If entertainer.Name = "とりこびと" Then
                entertainer.Name = "とりこびと(仮)"
            End If
        Next
    End Sub
End Class

Button2 をクリックすると _entertainerList に 'とりこびと' という Name プロパティ に設定された WankumaEntertainer クラスのインスタンスがあれば、そのName プロパティを'とりこびと(仮)'に変更するコードです。

ではでは、実行してみましょう。Button1 をクリックして 'とりこびと' を追加し、Button2 をクリックして変更してみてください。でもってその後 ComboBox1 のリストを確認してみてください。


うひぃ~!変化なし!!(ToT)


そうです。プログラムコードから_entertainerList の要素の変更に対して行った変更が反映されません。・・・またまた困りましたね。



・・・と、困ったところで今回も次回につ・づ・く♪

投稿日時 : 2007年5月30日 14:13

Feedback

# re: データバインディングのおべんきょ。その5。 2007/05/30 15:14 かずくん

> いいもん持ってんじゃねーか♪
Framework1.0「なんだよ。どいつもこいつも、Framework2.0ばかりひいきしやがって」
Framework1.1「そうそう、俺らの頃なんかよー。DateSetを一度nullにしてから、再セットしたってのによー」
Framework1.0「それが今じゃ、BindingListで、ホイ!って。まったく、やってられねーよ。」
Framework1.1「くそ、Framework2.0のこと考えてたら、また腹たってきたわ。」

#先輩たちの会話....

# re: データバインディングのおべんきょ。その5。 2007/05/30 17:18 とりこびと

かずくんさん、コメントありがとうございます。

ねたみはいじめの要因になりうる・・・とwww

実際.NET Framework 2.0 触ってみるともう先輩には戻りたくない症候群になりますたw

# データバインディングのおべんきょ。その6。 2007/05/30 17:35 とりこびと ぶろぐ。

データバインディングのおべんきょ。その6。

# データバインディングのおべんきょ。その8。 2007/05/31 10:19 とりこびと ぶろぐ。

データバインディングのおべんきょ。その8。

# PVAaZsWTfABy 2011/12/22 21:29 http://www.discreetpharmacist.com/

XsYTVg Pleased to read intelligent thoughts in Russian. I`ve been living in England for already 5 years!...

# mNYOWQmZrXwkkbBzHpi 2011/12/29 21:29 http://4iu.org/

Are you interested in webmaster`s income?!...

# blonde lace wigs 2018/08/04 2:25 ohirvmji@aol.com

These blonde lace wigs https://youtu.be/3KO3e4I3_24 are so wonderful I'm buying another an individual for the friend's birthday.

# If you want to increase your familiarity simply keep visiting this website and be updated with the most recent news posted here. 2019/05/30 10:22 If you want to increase your familiarity simply ke

If you want to increase your familiarity simply keep visiting
this website and be updated with the most recent news posted here.

# Good day! I know this is somewhat off topic but I was wondering which blog platform are you using for this website? I'm getting fed up of Wordpress because I've had problems with hackers and I'm looking at options for another platform. I would be awesom 2019/06/06 19:50 Good day! I know this is somewhat off topic but I

Good day! I know this is somewhat off topic but I was wondering which
blog platform are you using for this website? I'm getting fed up of Wordpress because I've had problems with hackers and I'm looking at options
for another platform. I would be awesome if you could point me in the
direction of a good platform.

# Have you ever thought about including a little bit more than just your articles? I mean, what you say is important and everything. However think about if you added some great images or video clips to give your posts more, "pop"! Your content is 2019/08/24 20:46 Have you ever thought about including a little bit

Have you ever thought about including a little bit
more than just your articles? I mean, what you say is important and
everything. However think about if you added some great
images or video clips to give your posts more, "pop"! Your content is excellent but with pics and clips, this site could certainly be one of the
greatest in its niche. Wonderful blog!

# Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but instead of that, this is wonderful blog. An excellent read. I'll cert 2019/09/08 14:10 Its like you read my mind! You seem to know a lot

Its like you read my mind! You seem to know a
lot about this, like you wrote the book in it
or something. I think that you could do with some pics to drive
the message home a bit, but instead of that, this is wonderful blog.
An excellent read. I'll certainly be back.

# ivermectin http://stromectolabc.com/
stromectol 3mg 2022/02/07 17:14 Busjdhj

ivermectin http://stromectolabc.com/
stromectol 3mg

# stromectol 12mg http://stromectolabc.com/
order stromectol online 2022/02/08 3:21 Busjdhj

stromectol 12mg http://stromectolabc.com/
order stromectol online

# doxycycline 100mg online https://doxycyline1st.com/
buy doxycycline 2022/02/26 9:15 Doxycycline

doxycycline 100mg online https://doxycyline1st.com/
buy doxycycline

# Wow! This blog looks just like my old one! It's on a totally different topic but it has pretty much the same page layout and design. Outstanding choice of colors! 2022/03/23 1:23 Wow! This blog looks just like my old one! It's o

Wow! This blog looks just like my old one! It's on a totally different topic but
it has pretty much the same page layout and design. Outstanding choice of colors!

# I know this web page offers quality dependent posts and additional data, is there any other web page which offers these things in quality? 2022/03/23 15:39 I know this web page offers quality dependent post

I know this web page offers quality dependent
posts and additional data, is there any other web page which offers these
things in quality?

# I know this web page offers quality dependent posts and additional data, is there any other web page which offers these things in quality? 2022/03/23 15:40 I know this web page offers quality dependent post

I know this web page offers quality dependent
posts and additional data, is there any other web page which offers these
things in quality?

# I know this web page offers quality dependent posts and additional data, is there any other web page which offers these things in quality? 2022/03/23 15:41 I know this web page offers quality dependent post

I know this web page offers quality dependent
posts and additional data, is there any other web page which offers these
things in quality?

# I know this web page offers quality dependent posts and additional data, is there any other web page which offers these things in quality? 2022/03/23 15:42 I know this web page offers quality dependent post

I know this web page offers quality dependent
posts and additional data, is there any other web page which offers these
things in quality?

# fantastic issues altogether, you simply received a brand new reader. What may you suggest about your post that you just made some days ago? Any sure? 2022/06/05 15:29 fantastic issues altogether, you simply received a

fantastic issues altogether, you simply received a brand new reader.
What may you suggest about your post that you just made some days ago?
Any sure?

# When someone writes an piece of writing he/she retains the idea of a user in his/her brain that how a user can be aware of it. Thus that's why this piece of writing is outstdanding. Thanks! 2022/06/07 0:00 When someone writes an piece of writing he/she ret

When someone writes an piece of writing he/she retains the idea of a user in his/her brain that how a user can be aware of it.
Thus that's why this piece of writing is outstdanding. Thanks!

# What a information of un-ambiguity and preserveness of valuable experience about unexpected emotions. 2022/06/10 10:29 What a information of un-ambiguity and preservenes

What a information of un-ambiguity and preserveness of valuable experience about unexpected emotions.

# mens ed pills https://erectionpills.best/
ed treatment pills 2022/06/28 10:39 ErectionPills

mens ed pills https://erectionpills.best/
ed treatment pills

# canadian drug https://withoutprescription.store/
best non prescription ed pills 2022/07/02 17:16 CanadaRx

canadian drug https://withoutprescription.store/
best non prescription ed pills

# Right away I am going away to do my breakfast, when having my breakfast coming again to read further news. 2022/08/03 20:10 Right away I am going away to do my breakfast, whe

Right away I am going away to do my breakfast, when having my breakfast coming again to read
further news.

# These are really fantastic ideas in on the topic of blogging. You have touched some pleasant things here. Any way keep up wrinting. 2022/08/15 9:10 These are really fantastic ideas in on the topic o

These are really fantastic ideas in on the topic of blogging.
You have touched some pleasant things here. Any way keep up wrinting.

# My developer is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using WordPress on a number of websites for about a year and am anxious about switching to anot 2022/08/19 11:29 My developer is trying to persuade me to move to .

My developer is trying to persuade me to move to .net from PHP.
I have always disliked the idea because of the
costs. But he's tryiong none the less. I've been using WordPress on a
number of websites for about a year and am anxious about switching to another platform.
I have heard great things about blogengine.net. Is there a way I
can import all my wordpress posts into it? Any help would be greatly appreciated!

# how to write commentary in an essay b959bt 2022/09/04 3:07 Charlosmox


Helpful posts. Thanks a lot. https://definitionessays.com/ australian essay writing service

# college acceptance essay x152rt 2022/09/08 18:11 Charlosmox


Nicely put. Kudos. https://definitionessays.com/ is a thesis required for a masters degree

# best ed treatment pills https://erectiledysfunctionpills.shop/ 2022/10/14 16:21 Erectile

best ed treatment pills https://erectiledysfunctionpills.shop/

# how to get prednisone without a prescription https://prednisone20mg.icu/ 2022/10/15 6:55 Prednisone

how to get prednisone without a prescription https://prednisone20mg.icu/

# free datings site https://datingtopreview.com/
pof login online 2022/10/17 14:05 Dating

free datings site https://datingtopreview.com/
pof login online

# prednisone 10 mg coupon https://prednisone20mg.site/
prednisone 5mg price 2022/11/15 10:46 Prednisone

prednisone 10 mg coupon https://prednisone20mg.site/
prednisone 5mg price

# ourtime inloggen https://datingsiteonline.site/
beste dating site 2022/12/05 17:03 Tading

ourtime inloggen https://datingsiteonline.site/
beste dating site

# video dating https://datingonline1st.com/
dating dating 2023/01/17 17:23 Dating

video dating https://datingonline1st.com/
dating dating

# pills for erection https://edpills.ink/# - erection pills online 2023/07/26 14:10 EdPills

pills for erection https://edpills.ink/# - erection pills online

# buy valtrex australia https://valtrex.auction/ valtrex online purchase 2023/10/24 11:25 Valtrex

buy valtrex australia https://valtrex.auction/ valtrex online purchase

# paxlovid pill https://paxlovid.bid/ paxlovid price 2023/10/25 11:51 Paxlovid

paxlovid pill https://paxlovid.bid/ paxlovid price

# comprare farmaci online all'estero https://farmaciait.pro/ farmacie online sicure 2023/12/04 3:38 Farmacia

comprare farmaci online all'estero https://farmaciait.pro/ farmacie online sicure

# best treatment for ed https://edpills.tech/# ed pills gnc 2023/12/22 23:41 EdPills

best treatment for ed https://edpills.tech/# ed pills gnc

# where to buy prednisone in australia https://prednisone.bid/ where to buy prednisone 20mg 2023/12/27 2:26 Prednisone

where to buy prednisone in australia https://prednisone.bid/ where to buy prednisone 20mg

# UK News Hub: Check In touch on Politics, Succinctness, Culture & More 2024/03/28 19:00 Tommiemayox

Appreciated to our dedicated platform in support of staying briefed about the latest news from the Joint Kingdom. We take cognizance of the import of being learned about the happenings in the UK, whether you're a denizen, an expatriate, or simply interested in British affairs. Our encyclopaedic coverage spans across diversified domains including political science, conservation, taste, production, sports, and more.

In the bailiwick of wirepulling, we living you updated on the intricacies of Westminster, covering according to roberts rules of order debates, sway policies, and the ever-evolving vista of British politics. From Brexit negotiations and their import on trade and immigration to domesticated policies affecting healthcare, edification, and the medium, we plan for insightful analysis and timely updates to ease you manoeuvre the complex society of British governance - https://newstopukcom.com/review-hozier-o2-academy/.

Economic dirt is crucial for reconciliation the monetary thudding of the nation. Our coverage includes reports on superstore trends, organization developments, and economic indicators, offering valuable insights for investors, entrepreneurs, and consumers alike. Whether it's the latest GDP figures, unemployment rates, or corporate mergers and acquisitions, we strive to read meticulous and relevant report to our readers.

タイトル
名前
Url
コメント