Hello,
I am preparing one utility which shows results of different medicine orders recorded at different time. I have to select data from Grid . Here time columns are generated dynamically as per result Recorded time.
I have created design as per requirement which is as per below. Data are showing in grid two level Group.
Grid Contains Fixed Header Checkbox, Checkbox in Group header. I have to select data on check box check. Please provide me solution How I can access rows under particular group. I have attached sample Test Code for same.
Hi Bhavin,
Data rows under a group by row can be accessed by looping through the GroupByRow’s rows collection. If you are trying to access the DataRows of the selected GroupByRows then you can achieve this by doing something like below.
foreach (UltraGridRow row in this.Grid.Selected.Rows) { if (row is UltraGridGroupByRow) { UltraGridGroupByRow groupByRow = row as UltraGridGroupByRow; RowsCollection rows = groupByRow.Rows; // By looping through the above rows collection you can access each datarow of a groupbyrow. }
}
Or if you just want to loop through non-groupby rows in the Grid then I recommend using GetRowEnumerator method.
Please let me know if I may be of further assistance.
Sincerely,Sahaja KokkalagaddaAssociate Software Developer
Thank You Sahaja,
I am able two select Rows with help of below code .More I have to select Group by Row header check box on select of parent Group by row header check box. Please refer
Screen shot. In Many Cases I have done this using Header.Tag=True But in this Case it is not working.
foreach (Infragistics.Win.UltraWinGrid.UltraGridGroupByRow item in _RowsCateGoryTwo)
{
_Rows = item.Rows;
_Rows.Tag = Convert.ToBoolean(e.CheckState);
foreach (Infragistics.Win.UltraWinGrid.UltraGridRow Row in _Rows)
Row.Selected =Convert.ToBoolean(e.CheckState);
Row.Cells[0].Value = Convert.ToBoolean(e.CheckState);
-> Another Thing is that Can I Select individual cell as selected. when I click on any cell it appearance is changed to as selected but when I select another cell then appearance of first cell is changed and second cell shows as selected . I want cell as selected on one click and un selected on second click. Using this I have to select Multiple Cells and get value.
Right Now I can do this with help of Ctrl+ Click. But I have to do this without pressing Ctrl. Please refer below Screen shot.
private void aCheckBoxOnHeader_CreationFilterGroupByHeaderCheckBoxClicked(object sender, CheckBoxOnHeader_CreationFilter.GroupByHeaderCheckBoxEventArgs e)
CheckBoxOnHeader_CreationFilter Obj_ = (CheckBoxOnHeader_CreationFilter)sender;
string _RowGroupOn = e.GroupByRowDesc.GroupByRow.Column.Key.ToString();
// System.Windows.Forms.MessageBox.Show(e.GroupByRowDesc.GroupByRow.Column.Key.ToString() + e.CheckState.ToString());
Infragistics.Win.UltraWinGrid.RowsCollection _Rows;
Infragistics.Win.UltraWinGrid.RowsCollection _RowsCateGoryOne;
Infragistics.Win.UltraWinGrid.RowsCollection _RowsCateGoryTwo;
if (_RowGroupOn == "CATEGORYONE")
_RowsCateGoryTwo = e.GroupByRowDesc.GroupByRow.Rows;
Infragistics.Win.UltraWinGrid.ColumnHeader _Header = _RowsCateGoryTwo.Band.Columns["CATEGORYTWO"].Header;
_Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization.Band;
_Header.Tag = Convert.ToBoolean(e.CheckState);
if (_RowGroupOn == "CATEGORYTWO")
_Rows = e.Rows;
Row.Selected = Convert.ToBoolean(e.CheckState);
if (_RowGroupOn == "MASTERCATEGORY")
(e.GroupByRowDesc.GroupByRow.Rows.FirstVisibleCardRow).Tag=Convert.ToBoolean(e.CheckState);
//_RowsCateGoryTwo.Tag = Convert.ToBoolean(e.CheckState);
//_RowsCateGoryTwo.Band.Header.Selected = Convert.ToBoolean(e.CheckState);
//_RowsCateGoryTwo.Band.Header.Tag = Convert.ToBoolean(e.CheckState);
//_RowsCateGoryTwo.Band.Columns["CATEGORYONE"].Band.Header.Tag = Convert.ToBoolean(e.CheckState);
//_RowsCateGoryTwo.Band.Columns["CATEGORYONE"].Band.SortedColumns.Band.Header.Tag = Convert.ToBoolean(e.CheckState);
foreach (Infragistics.Win.UltraWinGrid.UltraGridGroupByRow item_One in _RowsCateGoryTwo)
_RowsCateGoryOne = item_One.Rows;//e.GroupByRowDesc.GroupByRow.Rows;
_RowsCateGoryOne.Tag = e.CheckState;
foreach (Infragistics.Win.UltraWinGrid.UltraGridGroupByRow item_two in _RowsCateGoryOne)
_Rows = item_two.Rows;
//_Rows.Tag = Convert.ToBoolean(e.CheckState);
There is a possibility of selecting multiple rows without using the Ctrl key by implementing ISelectionStrategyFilter interface and redefining its GetSelectionStrategy method. For example you can implement this interface in your form like this:
public partial class Form1 : Form, ISelectionStrategyFilter { private ISelectionStrategy cellSelectionStrategy; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.ultraGrid1.DataSource = BuildData(new int[] { 2, 3 }); // Set the grid’s SelectionStrategyFilter property to the object that // implements the ISelectionStrategyFilter interface. this.ultraGrid1.SelectionStrategyFilter = this; // Create the custom selection strategy this.cellSelectionStrategy = new MyCustomSelectionStrategy(this.ultraGrid1); } private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { this.ultraGrid1.DisplayLayout.Override.SelectTypeCell = SelectType.Extended; this.ultraGrid1.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect; } public ISelectionStrategy GetSelectionStrategy(ISelectableItem item) { // If the item is a cell return the custom strategy if (item is UltraGridCell) return this.cellSelectionStrategy; return null; } }
private void Form1_Load(object sender, EventArgs e) { this.ultraGrid1.DataSource = BuildData(new int[] { 2, 3 }); // Set the grid’s SelectionStrategyFilter property to the object that // implements the ISelectionStrategyFilter interface. this.ultraGrid1.SelectionStrategyFilter = this; // Create the custom selection strategy this.cellSelectionStrategy = new MyCustomSelectionStrategy(this.ultraGrid1); }
private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { this.ultraGrid1.DisplayLayout.Override.SelectTypeCell = SelectType.Extended; this.ultraGrid1.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect; }
public ISelectionStrategy GetSelectionStrategy(ISelectableItem item) { // If the item is a cell return the custom strategy if (item is UltraGridCell) return this.cellSelectionStrategy;
return null; } }
1. Focus the control.2. Activate the cell over which left mouse button is clicked.3. Toggle the cell selected state over which the left mouse button is pressed.
For example you can write a derived class MyCustomSelectionStrategy that inherits from SelectionStrategyExtended class like this:
internal class MyCustomSelectionStrategy : SelectionStrategyExtended { internal MyCustomSelectionStrategy(ISelectionManager manager) : base(manager) { } public override bool OnMouseDown(Infragistics.Shared.ISelectableItem item, ref Infragistics.Win.MouseMessageInfo msginfo) { // Do some custom mouse down processing Infragistics.Win.UltraWinGrid.UltraGridCell cell = item as Infragistics.Win.UltraWinGrid.UltraGridCell; if (cell != null && msginfo.Buttons == MouseButtons.Left) { //Focus the control if it isn't already. UltraGrid control = this.SelectionManager as UltraGrid; if (control.Focused == false) control.Focus(); //Make this cell active cell control.ActiveCell = cell; cell.Selected = !cell.Selected; // Return true to signify that we handled the message return true; } return base.OnMouseDown(item, ref msginfo); } }
// Do some custom mouse down processing Infragistics.Win.UltraWinGrid.UltraGridCell cell = item as Infragistics.Win.UltraWinGrid.UltraGridCell; if (cell != null && msginfo.Buttons == MouseButtons.Left) { //Focus the control if it isn't already. UltraGrid control = this.SelectionManager as UltraGrid; if (control.Focused == false) control.Focus(); //Make this cell active cell control.ActiveCell = cell; cell.Selected = !cell.Selected; // Return true to signify that we handled the message return true; } return base.OnMouseDown(item, ref msginfo); } }
Please refer to the attachment for complete code sample.
I did not understand your first question like what you meant when you said“More I have to select Group by Row header check box on select of parent Group by row header check box. Please referScreen shot. In Many Cases I have done this using Header.Tag=True But in this Case it is not working.”
Please elaborate on the details of the issue you are having here. Also if you can give me a sample demonstrating the issue it will be helpful for identifying the issue.
Please let me know if you have any questions.
Hi Sahaja,
I want to select Group by header checkbox programmatically. Please refer below screen shot. when I check Laboratory then as per Hierarchy Blood Bank , Blood Bank Test and Rows should be select. I am facing problem to select check box of Group by header check box (here Blood Bank and Blood Bank Test). Please get code from below link. https://drive.google.com/open?id=0BxuTllvO1EG-Rl9UREVRNHJ6OFU
Hello Bhavin,
I have looked at the sample code you have sent us. Casting a row into UltraGridGroupByRow and using the rows collection off of it will give you a way to access its child rows. But there is no possibility with the built in functionality in UltraGrid to select rows on more than one level at a time. I.e. you cannot select a GroupByRow and one of its child rows at once.