If a column is sized with InitialAuto, which will also happen if they double click on the column separator to auto size the column, how do you determine the actual size of the column?
The column's ActualWidth property is 0.0 (zero) in this case, and the Width and WidthResolved properties only tell you that it's sized to InitialAuto. I need the real width in pixels that the column is actually sized to.
Thanks,
Mike
HI,
You could get the size of the the first cell and used that width.
Here a code snippet:
CellValuePresenter cvp = CellValuePresenter.FromCell(xgrid1.ActiveCell);
MessageBox.Show(cvp.ActualWidth.ToString());
Sincerely,
Matt
Developer Support Engineer
That seems to be a WPF class for XamDataGrid, not a Silverlight class for XamGrid (which is what I'm asking about).
Anything for Silverlight?
Hello Michael,
The analog code for XamGrid is :
CellControl cc = xamGrid1.ActiveCell.Control as CellControl;
MessageBox.Show(cc.ActualWidth.ToString());
If you need any further assistance on this matter, feel free to ask.
I'll give that a try.
But what I'm really interested in is determining the actual width of a column. What't the best way to get that? The ActiveCell isn't column specific, so I'll need some way to select a cell in each column I am interested in.
Hello Mike,
To get the actual width of the selected cell you can use the following code :
Column col = xamGrid1.ActiveCell.Column as Column;
MessageBox.Show(col.ActualWidth.ToString());
No, if you go back to the first message, you'll see the probelm I'm complaining about is that ActualWidth is zero.
Hi Mike,
I have been trying to find out some other approach in order to delay an operation execution but my tries was without success.
This scenario seems not related to any Infragistics product so I can suggest you ask for a suggestion in the MSDN community, as the operation execution is related to .Net scenarios.
That sounds right.
I was hoping that using Dispatcher.BeginInvoke after changing to each tab item would do it, but apparently it doesn't. Is there something else you can suggest?
The issue that you are having does not depend on the XamGrid. In order to get the ‘ActualWidth’ the control must be initialized and its columns to be drown. It seems that the time for looping through your all tab items is not necessary the group columns to be initialized.
That doesn't look like it works (reliably?). When I added that code most of the time I get the 0 column widths, but sometimes I do get the right widths. Do a refresh on the browser and the press the button immediately.
I actually have code (in my big application) that iterates over all the tab, doing DispatcherBeginInvoke every time I change the tab, and for each tab I expand the groups (again, using Dispatcher.BeginInvoke) to ensure things are loaded, and it still doesn't work. I've even tried doing many Dispatcher.BeginInvoke's.
There's something else going on here, but I can't figure out what it is.
Any ideas?
Thank you for the provided sample application and your explanation. Your issue occurs because the XamGrid in the second tab item is not initialized when you are trying to get the value for the columns.
I can suggest you to handle the ‘Loaded’ event of the TabControl and to switch through the tabs like e.g. :
private void tabControl_Loaded(object sender, RoutedEventArgs e)
{
tabControl.SelectedItem = tabControl.Items[1];
Dispatcher.BeginInvoke(new Action(() => tabControl.SelectedItem = tabControl.Items[0]));
tabControl.SelectedItem = tabControl.Items[0];
}
This way you can get the desired results.