2017-12-20 3 views
0

두 개의 열이있는 gridcontrol을 추가했습니다. 열 1은 datatable의 문자열과 바인드를 나타내고 다른 열은 radiogroupitem을 나타내지 만 다음과 같은 질문에 따라 모든 행에 다른 라디오 버튼 값을 추가하려고합니다. (아직 - 예 - 오늘 밤)과 마지막 행 추가 - 그리고 다음 행은 (안 여기 여기) 추가 - 첫 번째 행 (나쁜 파인) 를 추가데이터 테이블을 기반으로 모든 행에 다른 데이터로 bind radiogroup

//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

, 당신은 어떻게 생각하십니까 ??? –

관련 문제