2017-12-20 11 views
0

2つの列を持つgridcontrolを追加しました。列1はdatatableの文字列とバインドを表し、別の列はradiogroupitemを表します。最初の行は を追加(ファイン - バート)、次の行は、(ここでは - ここにいない)を追加し、最後の行は(まだ - はい - 今夜)を追加データテーブルに基づいてすべての行に異なるデータをバインドします

//bind question column 
DataTable dtt = new DataTable(); 

dtt.Columns.Add("ID", typeof(string)); 

dtt.Rows.Add("How are you ?"); 
dtt.Rows.Add("Where are you ?"); 
dtt.Rows.Add("are you sleepy ?"); 

gridControl1.DataSource = dtt; 

gridControl1.ForceInitialize(); 

// Bind radiobuttonitem 
DataTable dataSource = new DataTable(); 
dataSource.Columns.Add("TypeID", typeof(int)); 
dataSource.Columns.Add("TypeName", typeof(string)); 

dataSource.Rows.Add(new object[] { 1, "A" }); 
dataSource.Rows.Add(new object[] { 2, "B" }); 
dataSource.Rows.Add(new object[] { 3, "C" }); 

foreach (DataRow dr in dataSource.Rows) 
    repositoryItemRadioGroup1.Items 
     .Add(new DevExpress.XtraEditors.Controls.RadioGroupItem(dr["TypeID"], dr["TypeName"].ToString())); 

https://imgur.com/a/25Ofu

答えて

1

異なる割り当てることCustomRowCellEditイベントを使用します編集者は個々の細胞にe.RepositoryItemパラメータを、

CustomRowCellEditイベントハンドラで
Dictionary<string, RepositoryItemRadioGroup> repositories = new Dictionary<string, RepositoryItemRadioGroup>(); 

RepositoryItemRadioGroup group1 = new RepositoryItemRadioGroup(); 
group1.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Fine", "Fine")); 
group1.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Bad", "Bad")); 
repositories.Add("How are you?", group1); 

RepositoryItemRadioGroup group2 = new RepositoryItemRadioGroup(); 
group2.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Here", "Here")); 
group2.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("There", "There")); 
repositories.Add("Where are you?", group2); 

、質問を取得するためにGetRowCellValueメソッドを呼び出して、辞書から対応するリポジトリ項目を取得し、設定します:あなたは辞書に質問やRepositoryItemRadioGroupsを保存することができます

また
void GridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) { 
    GridView view = sender as GridView; 
    if (e.Column.FieldName == "Answer" && view.IsValidRowHandle(e.RowHandle)) { 
     string question = (string)view.GetRowCellValue(e.RowHandle, "Question"); 
     RepositoryItemRadioGroup item; 
     if(repositories.TryGetValue(question, out item)) 
      e.RepositoryItem = item; 
    } 
} 

参照:Modify and Validate Cell Values

+0

私は形だけと負荷の質問にグリッドコントロールを追加した、あなたはどう思いますか? –

関連する問題