Reputation: 31
FindControl seems to only reference the name of the grid, not the column name inside the grid. I can't find any documentation or examples regarding FindControlInCollection either.
I don't have any sophisticated logic to wrap this in at this point. Just need to hide columns. I am using C# and VS Update 2.
Upvotes: 3
Views: 1908
Reputation: 3879
Bryan's answer contains what you need.
FindControl only gets a proxy for the control. While there are a few things you can set using it, the only way to get to the actual control is to access it through the proxy's ControlAvailable handler, which provides a reference to the underlying control in its ControlAvailableEventArgs parameter.
Also, as you can see, you don't actually set column visibility via the controls that are used in the grid, you set it using the DataGrid's Columns collection directly instead.
Upvotes: 2
Reputation: 1483
Under the Activate event of the screen, use this codeblock:
IControlItemProxy
using the name of the grid. using
directive to System.Windows.Controls
..
partial void ScreenName_Activated()
{
IContentItemProxy proxy = this.FindControl("NameOfGrid");
proxy.ControlAvailable += new EventHandler<ControlAvailableEventArgs>((s1, e1) =>
{
DataGrid dataGrid = (DataGrid)e1.Control;
dataGrid.Columns[0].Visibility = System.Windows.Visibility.Collapsed;
dataGrid.Columns[1].Visibility = System.Windows.Visibility.Collapsed;
});
}
Upvotes: 2