Hello,
I am making e-mail client, and trying to look lile MS Outlook. I created grid just like this
[Image] [FromEmail] [Date] [FlagIcon] [Subject] [AttachmentIcon]
It's working great, but now I want to auto resize only columns FromEmail and Subject ? If I use autoresize, it resizes all columns. What's the best way to resize only these two columns, and Image column to stay at left side, and Data, Flag, Attachment on right ?
1. Set the UltraWinGrid.DisplayLayout.AutoFitStyle to None
2. Add an event handler to the InitializeLayout event of the UltraWinGrid
3. In the event handler function access the columns you're interested in using the InitializeLayoutEventArgs object parameter passed to the function:
private
void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e){
ColumnsCollection cols = e.Layout.Bands[0].Columns
cols["your_column"].Width = 255
// ... do whatever else you need to do here
}
I already did that. But I need an idea what code to put in that function. I.ve been thinking to calculate grid width minus width of other cells, and to store that value as Subject cell width. But is there any other solution wich is simpler ?
Sorry, Mike, I was talking about auto fit style. So the only way is to hard code values. I'll try your idea, just to see if it's working...
Hi,
I'm not sure I am following what you want here. AutoSize means sizing the column width to it's contents. So this would make the column widths big enough to fit all of the text. If that's what you want, then all you have to do is call the PerformAutoSize method on the column.
It sounds like you may be talking about AutoFit - which means sizing all of the column widths so that the fill the horizontal area of the grid with no extra space. If that's the case, you can use the AutoFitStyle property.
There is no option on this property to AutoFit a particular column, though. It's either all columns or the last column.
What I've done in a case like this is I set AutoFitStyle to ResizeAllColumns. Then I set the Width, MaxWidth, and MinWidth of every column (except one) to some hard-coded value. I know that works in the standard ViewStyle, but I can't say I have ever tried it in a RowLayout like you have here, so I'm not sure if it will work. Might be worth a shot, though.
This is what I've done so far, and it's working. But still wondering if there is any simplier solution, or grid function ?
private void gridMail_Resize(object sender, EventArgs e) { int size = gridMail.Width - 149-10; // (size of grid - size of other cells - size of vertical scrollbar) RowLayoutColumnInfo info = gridMail.DisplayLayout.Bands[0].Columns["Subject"].RowLayoutColumnInfo; if (size > 0) { info.PreferredCellSize = new Size(size, 15); } else { info.PreferredCellSize = new Size(128, 15); // default size } }