2017-02-23 3 views
0

私は、データベースの列のテキストボックスとチェックボックスを生成するウィンドウを持っています:Image だから私は何かを変更して保存をクリックします。私はこれらを保存したい。だから私は、複数のテキストボックスでそれぞれのループのための必要があります。テキストボックスの量を検出

テキストボックスの数を検出する方法はありますか?ここで

は、テキストボックスやチェックボックスの作成方法をいくつかのコードです:

public firmCustomerTable() 
    { 
     InitializeComponent(); 
     MySqlConnection connection; 
     config conf = new config(); 
     connection = new MySqlConnection(conf.connection_string); 
     DataTable schema = null; 

     using (var con = new MySqlConnection(conf.connection_string)) 
     { 
      using (var schemaCommand = new MySqlCommand("SELECT * FROM firmenkunden", con)) 
      { 
       con.Open(); 
       using (var reader = schemaCommand.ExecuteReader(CommandBehavior.SchemaOnly)) 
       { 
        schema = reader.GetSchemaTable(); 
       } 
      } 
     } 
     foreach (DataRow col in schema.Rows) 
     { 
      System.Windows.Controls.TextBox newTxt = new TextBox(); 
      System.Windows.Controls.CheckBox onoff = new CheckBox(); 

      // Add Label 
      newTxt.Text = col.Field<String>("ColumnName"); 
      newTxt.Name = col.Field<String>("ColumnName"); 
      newTxt.Width = 200; 


      // Add OnOff 
      onoff.HorizontalAlignment = HorizontalAlignment.Center; 
      onoff.Style = (Style)FindResource("CheckBoxStyle1"); 
      onoff.VerticalAlignment = VerticalAlignment.Center; 

      // Add To Panel 
      sp.Children.Add(newTxt); 
      sp.Children.Add(onoff); 

     } 
    } 
+0

私は、彼らがグリッドやStackPanelの、またはコンテナのいくつかの種類でなければなりませんassusme。これらの子を照会してTextBoxesに制限するには十分であるべきです – Lennart

+0

いくつかのコードを追加すると、コントロールの作成方法がわかります。 –

+0

@ R.Rusev私はいくつかのコードを追加しました。 – xKushGene

答えて

1

は、フォームで拡張機能を使用する using System.Linqを置きます。

List<TextBox> textboxes = sp.Children.OfType<TextBox>().ToList(); 

をして、あなたは、テキストボックスのリストに自分のものを行うことができます。その後、あなたはこのように、パネルの上に置かれているすべてのTextBoxのコントロールを取得するためにOfType<>メソッドを使用することができます。 また、カウントを取得します

int count = textboxes.Count; 
関連する問題