1

Windowsフォームc#のDataRepeater内でuserControlsをバインドする方法は?

このメソッドを使用したくない:http://blogs.msdn.com/b/vsdata/archive/2009/08/12/datarepeater-control-for-windows-forms.aspxしかし、バインディングを作成したいプログラムでDataSet/DataTableから。テストのためだけにリピーターの中に、1つのテキストボックスと1つのラベルを配置しました。また、1つのラベルと1つのテキストボックスの2つのコントロールで構成される1つのUserControl。これまでのところ、最初のラベルとテキストボックスのみが更新され、ユーザーコントロールは更新されていません。何が恋しいですか?

これはLoadイベントです

private void DataRepeaterForm_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=ADRIAN-PC; Initial Catalog=AdventureWorks2008R2; Integrated Security=true;User id=;password=");

            SqlCommand cmd = new SqlCommand("Select * from Person.Person", con);
            SqlDataAdapter adapt = new SqlDataAdapter(cmd);

            DataTable items = new DataTable();
            adapt.Fill(items);

            textBox1.DataBindings.Add("Text", items, "FirstName");
            label1.DataBindings.Add("Text", items, "LastName");

            TextBox myUcTextBox1 = (TextBox)myUC1.Controls.Find("textBox1", true).First();

            if( myUcTextBox1 != null)
                myUcTextBox1.DataBindings.Add("Text", items, "LastName");

            dataRepeater1.DataSource = items;
        }

DrawItemのような他のイベントも使用する必要があります...?よろしく。

4

1 に答える 1

4

BindingSourceを使用してバインディングを追加します。

BindingSource bindingSource1 = new BindingSource();
bindingSource1.DataSource = items;
textBox1.DataBindings.Add("Text", bindingSource1, "FirstName");
label1.DataBindings.Add("Text", bindingSource1, "LastName");
dataRepeater1.DataSource = bindingSource1;
于 2013-01-03T15:45:36.600 に答える