设置创建新行后选择的超网格行

时间:2011-09-12 12:43:20

标签: c# .net winforms infragistics ultragrid

我有一个包含大量行的超网格,最后添加了新行,我希望在添加新行时,选择该行并且网格也应该滚动到底部。

我打算尝试使用ActiveRow,但它说它没有setter

private void ultraButtonCreateNew_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();
            FormAddUnit form = new FormAddUnit();

            form.BuildingDataSet = _buildingDataSet;
            form.SectionDataSet = _sectionDataSet;
            form.UnitDataSet = _uc011_WizardStepUnitDataSet;
            form.SummaryDataSet = _summaryDataSet;
            form.FormState = WizardState.Create;
            form.Enablement = false;

            dr = form.ShowDialog();

            if (dr == DialogResult.Yes)
            {
                UC011_WizardStepUnitDataSet.UnitRow row = form.GetRow();
                _uc011_WizardStepUnitDataSet.Unit.AddUnitRow(row);
                SetUltraGridData();
                ultraGridOverview.DisplayLayout.ActiveRow = row;
                SetSummaryDataSet();
            }
        }

2 个答案:

答案 0 :(得分:7)

为了选择一行并将其滚动到视图中,您可以在这样的行上调用激活方法

ultraGridOverview.Rows[ultraGridOverview.Rows.Count - 1].Activate() 

或者您可以设置基础CurrencyManager的位置属性

CurrencyManager currencymanagerCustomers;
currencymanagerCustomers = this.BindingContext(ultraGridOverview.DataSource);
currencymanagerCustomers.Position = _uc011_WizardStepUnitDataSet.Rows.Count -1;

答案 1 :(得分:0)

private void ultraGrid1_BeforeRowDeactivate(object sender, CancelEventArgs e)
{
    if (!first) //Ignore this step if application has just started
    {
       UltraGrid g = (UltraGrid)(sender);
       r = g.ActiveRow;
       ultraGrid1.Rows[g.ActiveRow.Index].Cells["Is Closed"].Value = false; 
    }
}

这适用于我,多个乐队。

r是一个全局var,它存储对新创建的行的引用。 首先是一个全局bool,它在Form_Load结束时变为false。

插入/创建行后,使用对r的引用来修改行