简体   繁体   English

RowSizingAutoMaxLines一排超网格基础设施

[英]RowSizingAutoMaxLines one row Ultragrid Infragistics

I am using this code, it is a bad example, but it works to test, but it ends up changing all rows. 我正在使用此代码,这是一个不好的例子,但可以测试,但最终会更改所有行。

I need only change the row selected. 我只需要更改选择的行。

if (e.Cell.Column.Layout.Override.RowSizingAutoMaxLines == 4)
{
       e.Cell.Column.Layout.Override.RowSelectorStyle = Infragistics.Win.HeaderStyle.XPThemed;
       e.Cell.Column.Layout.Override.RowSizingAutoMaxLines = 20;
}
else
{
       e.Cell.Column.Layout.Override.RowSelectorStyle = Infragistics.Win.HeaderStyle.Default;
       e.Cell.Column.Layout.Override.RowSizingAutoMaxLines = 4;
 }

Setting the RowSizingAutoMaxLines on Override will set this to all the rows. 将RowSizingAutoMaxLines设置为Override会将其设置为所有行。 What you can do instead is calculate the necessary row height and set it to the current row, assuming you have set beforehand RowSizing to Free or to AutoFree. 相反,您可以做的是计算必要的行高并将其设置为当前行, 前提是您事先已将RowSizing设置为Free或AutoFree。 You can use Graphics MeasureString to calculate the height of one row and set then each row's height like this: 您可以使用Graphics MeasureString来计算一行的高度,然后设置每一行的高度,如下所示:

First setup the grid: 首先设置网格:

    private void UltraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
    //  I think you need row selectors as you set their style
    e.Layout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.True;

    //  Set the RowSizing to some Free value to allow each row to has its onw height
    e.Layout.Override.RowSizing = RowSizing.AutoFree;

    //  I think you have multiline text in the cells, so you should set CellMultiLine to true too
    e.Layout.Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.True;
}

Then measure one row and set the row's height: 然后测量一行并设置行的高度:

//  Calculate the height of one line of text
var oneLineHeight = float.MinValue;
using(Graphics g = this.ultraGrid1.CreateGraphics())
{
    oneLineHeight = g.MeasureString("Jj", this.ultraGrid1.Font, int.MaxValue, StringFormat.GenericTypographic).Height;

}

// Set the row selectors' style and the row's height
if(e.Cell.Column.Layout.Override.RowSelectorStyle == Infragistics.Win.HeaderStyle.Default)
{
    e.Cell.Column.Layout.Override.RowSelectorStyle = Infragistics.Win.HeaderStyle.XPThemed;

    //  Add 4 to add some padding
    e.Cell.Row.Height = (int)(oneLineHeight * 20 + 4);
}
else
{
    e.Cell.Column.Layout.Override.RowSelectorStyle = Infragistics.Win.HeaderStyle.Default;

    //  Add 4 to add some padding
    e.Cell.Row.Height = (int)(oneLineHeight * 4 + 4);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM