Search code examples
c#.netwinformsinfragisticsultrawingrid

Set ultragrid row selected after creating a new row for another band?


I already solved the problem if selecting the row after creating a new row. And it also scrolls down to it.

This time, the problem I have is different. It should scroll to the selected row, but the selected row has sub rows, and it should scroll down to the last subrow of the selected row.

I already know how to get the selected row, but no idea how to get the index of it.

private void SplitUnit(Boolean editSplittedRow)
        {
            UC011_WizardStepUnitDataSet.UnitRow unitRow;

            if (editSplittedRow)
            {
                unitRow = (ultraGridOverview.ActiveRow.ParentRow.ListObject as DataRowView).Row as UC011_WizardStepUnitDataSet.UnitRow;
            }
            else
            {
                unitRow = (ultraGridOverview.ActiveRow.ListObject as DataRowView).Row as UC011_WizardStepUnitDataSet.UnitRow;
            }

            DialogResult dr = new DialogResult();
            FormSplitUnit form = new FormSplitUnit();

            form.ParentRow = unitRow;
            form.UnitDataSet = _uc011_WizardStepUnitDataSet;

            dr = form.ShowDialog();

            if (dr == DialogResult.Yes)
            {
                // Get splitted units from form
                UC011_WizardStepUnitDataSet dataSet = form.GetDataSet();

                // Obsolete ?
                //_uc011_WizardStepUnitDataSet.Unit.Merge(dataSet.Unit, true, MissingSchemaAction.Ignore);

                // Update modified or add new units
                UpdateSplittedUnitList(dataSet);

                // Reset data to grid
                //SetUltraGridData();

                // Update summary data
                SetSummaryDataSet();
                ultraGridOverview.Rows[unitRow].Selected = true;
                ultraGridOverview.Rows[_uc011_WizardStepUnitDataSet.Unit.Count - 1].Activate();
                ultraGridOverview.PerformAction(UltraGridAction.LastRowInGrid);

            }
        }

Solution

  • You need to find the lowest child of your active row and force the grid to scroll that row into view. Depending on the version of the Infragistics controls you are using, some combination of UltraGridRow.HasChild() and UltraGridRow.GetChild() will help you to iterate through the children to identify the last sub-row of the selected row. Then UltraGridView.ActiveScrollRegion.ScrollRowIntoView() should force the desired scrolling.

    Implementation is left as an exercise for the reader :)

    Some of the method names have changed across versions of the Infragistics controls suite, but these or similar methods should still exist.