作成日: 2018/05/31 最終更新日: 2018/05/31
文書種別
使用方法
詳細
C1ComboBoxのドロップダウンリストに、DataTableを使って複数列を表示しているとき、値メンバー列の値を指定して項目を選択し、C1ComboBoxには表示メンバー列のテキストを表示させることができます。
この動作を行わせるには、次の手順を実行します。
1. 値データ列をDataTableの主キーとして設定します。
2. DataTableのRows.Findメソッドを使用して、指定したデータを含む行番号を取得します。
3. ステップ2で取得した行番号を、C1ComboBoxのSelectedIndexに設定します。
◎サンプルコード(VB)
◎サンプルコード(C#)
この動作を行わせるには、次の手順を実行します。
1. 値データ列をDataTableの主キーとして設定します。
2. DataTableのRows.Findメソッドを使用して、指定したデータを含む行番号を取得します。
3. ステップ2で取得した行番号を、C1ComboBoxのSelectedIndexに設定します。
◎サンプルコード(VB)
Dim dt As DataTable
dt = New DataTable()
dt.Columns.Add("ID", GetType(System.String))
dt.Columns.Add("Name", GetType(System.String))
dt.Columns.Add("Type", GetType(System.Int32))
dt.Rows.Add("001", "りんご", 101)
dt.Rows.Add("002", "みかん", 102)
dt.Rows.Add("003", "バナナ", 103)
Dim columns(1) As DataColumn
columns(0) = dt.Columns("ID")
dt.PrimaryKey = columns
C1ComboBox1.TextDetached = True
C1ComboBox1.ItemsDataSource = dt
C1ComboBox1.ItemsValueMember = "ID"
C1ComboBox1.ItemsDisplayMember = "Name"
C1ComboBox1.ItemMode = C1.Win.C1Input.ComboItemMode.HtmlPattern
C1ComboBox1.HtmlPattern = "<table><tr><td width=30>{ID}</td><td width=70>{Name}</td><td width=70>{Type}</td></tr></table>"
C1ComboBox1.SelectedIndex = dt.Rows.IndexOf(dt.Rows.Find("003"))
dt = New DataTable()
dt.Columns.Add("ID", GetType(System.String))
dt.Columns.Add("Name", GetType(System.String))
dt.Columns.Add("Type", GetType(System.Int32))
dt.Rows.Add("001", "りんご", 101)
dt.Rows.Add("002", "みかん", 102)
dt.Rows.Add("003", "バナナ", 103)
Dim columns(1) As DataColumn
columns(0) = dt.Columns("ID")
dt.PrimaryKey = columns
C1ComboBox1.TextDetached = True
C1ComboBox1.ItemsDataSource = dt
C1ComboBox1.ItemsValueMember = "ID"
C1ComboBox1.ItemsDisplayMember = "Name"
C1ComboBox1.ItemMode = C1.Win.C1Input.ComboItemMode.HtmlPattern
C1ComboBox1.HtmlPattern = "<table><tr><td width=30>{ID}</td><td width=70>{Name}</td><td width=70>{Type}</td></tr></table>"
C1ComboBox1.SelectedIndex = dt.Rows.IndexOf(dt.Rows.Find("003"))
◎サンプルコード(C#)
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Type", typeof(int));
dt.Rows.Add("001", "りんご", 101);
dt.Rows.Add("002", "みかん", 102);
dt.Rows.Add("003", "バナナ", 103);
DataColumn[] columns = new DataColumn[1];
columns[0] = dt.Columns["ID"];
dt.PrimaryKey = columns;
c1ComboBox1.TextDetached = true;
c1ComboBox1.ItemsDataSource = dt;
c1ComboBox1.ItemsValueMember = "ID";
c1ComboBox1.ItemsDisplayMember = "Name";
c1ComboBox1.ItemMode = C1.Win.C1Input.ComboItemMode.HtmlPattern;
c1ComboBox1.HtmlPattern = "<table><tr><td width=30>{ID}</td><td width=70>{Name}</td><td width=70>{Type}</td></tr></table>";
c1ComboBox1.SelectedIndex = dt.Rows.IndexOf(dt.Rows.Find("003"));
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Type", typeof(int));
dt.Rows.Add("001", "りんご", 101);
dt.Rows.Add("002", "みかん", 102);
dt.Rows.Add("003", "バナナ", 103);
DataColumn[] columns = new DataColumn[1];
columns[0] = dt.Columns["ID"];
dt.PrimaryKey = columns;
c1ComboBox1.TextDetached = true;
c1ComboBox1.ItemsDataSource = dt;
c1ComboBox1.ItemsValueMember = "ID";
c1ComboBox1.ItemsDisplayMember = "Name";
c1ComboBox1.ItemMode = C1.Win.C1Input.ComboItemMode.HtmlPattern;
c1ComboBox1.HtmlPattern = "<table><tr><td width=30>{ID}</td><td width=70>{Name}</td><td width=70>{Type}</td></tr></table>";
c1ComboBox1.SelectedIndex = dt.Rows.IndexOf(dt.Rows.Find("003"));
関連情報
旧文書番号
82812