えムナウ Blog

えムナウ の なすがまま

目次

Blog 利用状況

ニュース


follow mnow at http://twitter.com


えムナウのプログラミングのページ

INETAJ

書庫

日記カテゴリ

ギャラリ

都道府県ComboBox

話題になっていたのでさらしてみた。

 

・シングルトン化した。

・デザイン時はDBを読まないように

 

デザイナにはbindingSourceを貼り付けてあります。

都道府県DataSet /都道府県TableAdapter は都道府県DataSet.xsdが別にあります。
 

public partial class 都道府県ComboBox : ComboBox, ISupportInitialize

{

    public 都道府県ComboBox()

    {

        InitializeComponent();

        if (都道府県DataSet == null)

        {

            InitializeDataSet();

        }

        this.bindingSource.DataSource = 都道府県DataSet;

        this.DataSource = this.bindingSource;

        this.ValueMember = "都道府県.コード";

        this.DisplayMember = "都道府県.名称";

    }

 

    static private SampleApplication.Data.都道府県DataSet 都道府県DataSet = null;

    static private SampleApplication.Data.都道府県DataSetTableAdapters.都道府県TableAdapter 都道府県TableAdapter;

 

    private void InitializeDataSet()

    {

        都道府県DataSet = new SampleApplication.Data.都道府県DataSet();

        都道府県TableAdapter = new SampleApplication.Data.都道府県DataSetTableAdapters.都道府県TableAdapter();

        ((System.ComponentModel.ISupportInitialize)(都道府県DataSet)).BeginInit();

 

        都道府県DataSet.DataSetName = "都道府県DataSet";

        都道府県DataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;

 

        都道府県TableAdapter.ClearBeforeFill = true;

        ((System.ComponentModel.ISupportInitialize)(都道府県DataSet)).EndInit();

    }

 

    #region ISupportInitialize メンバ

 

    public void BeginInit()

    {

    }

 

    public void EndInit()

    {

        if (!this.DesignMode)

        {

            if (都道府県DataSet.都道府県.Count == 0)

            {

                都道府県TableAdapter.Fill(都道府県DataSet.都道府県);

            }

        }

    }

 

    #endregion

}

投稿日時 : 2007年6月12日 21:10

コメントを追加

# re: 部品化する場合としない場合 2007/06/12 21:17 R.Tanaka.Ichiro's Blog

re: 部品化する場合としない場合

# re: 都道府県ComboBox 2007/06/13 13:14 通り*

こうすればデータは外で操作すればいいので、ユーザーさんからの様々要求にも対応できそうですね!
...と、素直には思えませんでした(^-^;;
ちょっと「都道府県ComboBox」の存在意義が薄く感じたのは私だけ...?

今回のオオモトの話の場合、
static private SampleApplication.Data.都道府県DataSet
がどこかにあればいいのではないかなと思いました。

#WPFのセッション、Web で拝見しました。勉強になりました!

# re: 都道府県ComboBox 2007/06/13 18:50 通り*

私のコメントは、話が逆行(というか平行)しちゃってるかもしれませんでした。
失礼しました~
実は@ITの方で2ページ目以降があることに今気付きましたorz
@ITとかは普段見ないので、上とか離れた下の方にページ選択があるのに気付きませんでした(-_-;)

# re: 都道府県ComboBox 2007/06/13 19:58 えムナウ

私も@IT書き込み久々なので、
なんだかカウントもまた1からみたい。

# re: 都道府県ComboBox 2007/06/14 0:51 片桐

都道府県データのCSVファイルって、確か郵政公社でダウンロード出来るんですよね……
そのデータから、今回のコンボボックス実装までが一連のクラスというか、アプリケーションっていうか、まぁそんなパッケージっぽいものになってると、使いたがる人が多そうです……

# re: 都道府県ComboBox 2007/06/14 12:01 とっちゃん

>ダウンロード出来るんですよね
あのデータは人が見るためのものであって、プログラムで使うためのものじゃないですよw

うちでも引いてますが、(別形式にプログラムで)加工して、(手作業でもろもろ)修正して、(本番プログラムで使うための下地としてプログラムで)加工して、別のデータを合成して...
それでようやく最終版のビルド...という感じだしw

CSVのままでもいいんだけど、もうチョットプログラムにやさしいものを出してほしいというのが
そっちに近い筋の人たちの共通見解ですww

# Fine way of explaining, and pleasant paragraph to get data concerning my presentation subject, which i am going to convey in college. 2019/04/10 22:41 Fine way of explaining, and pleasant paragraph to

Fine way of explaining, and pleasant paragraph to get data concerning my presentation subject, which i am going to convey
in college.

# you are really a excellent webmaster. The site loading velocity is amazing. It sort of feels that you are doing any distinctive trick. Also, The contents are masterpiece. you have done a magnificent activity in this matter! 2019/05/11 10:55 you are really a excellent webmaster. The site loa

you are really a excellent webmaster. The site loading velocity is amazing.
It sort of feels that you are doing any distinctive trick.

Also, The contents are masterpiece. you have done a magnificent
activity in this matter!

# My brother suggested I might like this blog. He was totally right. This post actually made my day. You can not imagine just how much time I had spent for this info! Thanks! 2019/05/13 19:44 My brother suggested I might like this blog. He wa

My brother suggested I might like this blog. He was totally
right. This post actually made my day. You can not imagine just how much time I had spent
for this info! Thanks!

タイトル
名前
URL
コメント