1 private void button1_Click(object sender, EventArgs e) 2 { 3 DataTable dt = new DataTable(); 4 dt.Columns.Add("Group"); 5 dt.Columns.Add("id... ...
1 private void button1_Click(object sender, EventArgs e) 2 { 3 DataTable dt = new DataTable(); 4 dt.Columns.Add("Group"); 5 dt.Columns.Add("idex"); 6 dt.Columns.Add("name"); 7 for (int i = 0; i < 5; i++) 8 { 9 DataRow dr = dt.NewRow(); 10 dr["Group"] = "<5"; 11 dr["idex"] = i.ToString(); 12 dr["name"] = "姓名" + i.ToString(); 13 dt.Rows.Add(dr); 14 } 15 for (int i = 5; i <= 10; i++) 16 { 17 DataRow dr = dt.NewRow(); 18 dr["Group"] = "(5,10]"; 19 dr["idex"] = i.ToString(); 20 dr["name"] = "姓名" + i.ToString(); 21 dt.Rows.Add(dr); 22 } 23 for (int i = 10; i <= 15; i++) 24 { 25 DataRow dr = dt.NewRow(); 26 dr["Group"] = "(10,15]"; 27 dr["idex"] = i.ToString(); 28 dr["name"] = "姓名" + i.ToString(); 29 dt.Rows.Add(dr); 30 } 31 32 gridColumnNumber.FieldName = "idex"; 33 gridColumnName.FieldName = "name"; 34 gridColumnGroup.FieldName = "Group"; 35 gridColumnGroup.GroupIndex = 0; 36 gdc.DataSource = dt; 37 gdv.ExpandAllGroups(); 38 39 for (int i = -1; gdv.IsGroupRow(i); i--) 40 { 41 DataRow dr = gdv.GetDataRow(gdv.GetDataRowHandleByGroupRowHandle(i)); 42 if (dr == null) return; 43 if (dr["Group"].ToString() == "(5,10]") 44 { 45 gdv.CollapseAllGroups(); 46 gdv.FocusedRowHandle = i; 47 gdv.SetRowExpanded(i, true); 48 return; 49 } 50 } 51 }