Hello Folks,
I am developing a WinForms Application and UltraWinGrid plays a major role in my application. I get the datasource by querying on sql tables and bind it to ultrawingrid. So, the columns are dynamic and I would be having numerous columns in my grid. Now, in order to avoid confusion for the user after seeing numerous columns, I have planned to categorize the columns to their respective category.For eg; Assume the following scenario
I have 9 columns starting from Column1,Column2.......Column9 which is in a sequential manner.Now I want to divide the 9 columns into three categories namely Category1,Category2,Category3. So, each Category consists of 3 columns.
How to implement this? Any help would be of great use.......
You could do this using Groups and Levels. Or, you could use a GroupLayout (RowLayout), if you have the latest version of the grid.
@Mike
Yes, I used RowLayoutGrouping as you said.......But, there are some ungrouped columns in my Grid too....The issue that am facing now is that all the grouped columns always precede the ungrouped columns and also the ungrouped columns are never getting spanned according to the grouped column header's height.......I hope you get my point....I have attached a snapshot of the output that I got........you would be able to get my issue......
RowLayoutGroupingSample.cs
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;using Infragistics.Win.UltraWinGrid;using Infragistics.Win;namespace RowLayoutGroupingSample{ public partial class frmRowLayoutSample : Form { public frmRowLayoutSample() { InitializeComponent(); } private void frmRowLayoutSample_Load(object sender, EventArgs e) { try { DataTable dt = new DataTable(); dt.Columns.Add("Salary", typeof(double)); dt.Columns.Add("EmpNo", typeof(int)); dt.Columns.Add("EmpName", typeof(string)); dt.Columns.Add("DepartmentNo", typeof(int)); dt.Columns.Add("DepartmentName", typeof(string)); DataRow drow = dt.NewRow(); drow["Salary"] = "12,000.00"; drow["EmpNo"] = 1; drow["EmpName"] = "Raghu"; drow["DepartmentNo"] = 1; drow["DepartmentName"] = "CSE"; dt.Rows.Add(drow); dt.AcceptChanges(); DataRow drow1 = dt.NewRow(); drow1["Salary"] = "20,000.00"; drow1["EmpNo"] = 2; drow1["EmpName"] = "Vairam"; drow1["DepartmentNo"] = 2; drow1["DepartmentName"] = "CSE"; dt.Rows.Add(drow1); dt.AcceptChanges(); ultraGrid1.DataSource = null; ultraGrid1.DataSource = dt; UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0]; //Arrange the band's column in Group Layout style this.ultraGrid1.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.GroupLayout; //Enable Column/Group moving this.ultraGrid1.DisplayLayout.Override.AllowRowLayoutColMoving = Infragistics.Win.Layout.GridBagLayoutAllowMoving.AllowAll; //Create a group for Employees UltraGridGroup empGroup = band.Groups.Add("EmpGroup", "Employee Details"); //Create a group for Department UltraGridGroup deptGroup = band.Groups.Add("DeptGroup", "Department Details"); band.Columns["Salary"].RowLayoutColumnInfo.ParentGroup=null; band.Columns["EmpNo"].RowLayoutColumnInfo.ParentGroup = empGroup; band.Columns["EmpName"].RowLayoutColumnInfo.ParentGroup = empGroup; band.Columns["DepartmentNo"].RowLayoutColumnInfo.ParentGroup = deptGroup; band.Columns["DepartmentName"].RowLayoutColumnInfo.ParentGroup = deptGroup; } catch (Exception ex) { MessageBox.Show(ex.Message, "Row Layout Grouping Sample", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ultraGrid1_InitializeLayout_1(object sender, InitializeLayoutEventArgs e) { foreach (UltraGridBand band in e.Layout.Bands) { foreach (UltraGridColumn col in band.Columns) { switch (col.Key.ToUpper()) { case "SALARY": col.Header.Fixed = true; break; case "DEPTNO": col.Header.VisiblePosition = 4; break; } } } } }}
If your grid has a DataSource at design-time, then you can use the row layout designer in the grid designer to just drag and drop the groups around and drag the span of the ungrouped column. Even if your data source is not available at design-time, it might be a good idea to go through the grid's quickstart and set up the data structure so you can do that.
Otherwise, you will have to use the RowLayoutColumnInfo properties on the columns and groups to arrange things how you want them. This is pretty complicated to do in code, though, which is why it's better to do it in the designer if at all possible.