3

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.

Bryan Hong
  • 1,483
  • 13
  • 28
weweber3
  • 31
  • 2

2 Answers2

2

Under the Activate event of the screen, use this codeblock:

  1. Get an IControlItemProxy using the name of the grid.
  2. Get the control itself.
  3. Access the column by its index and set its visibility dynamically.
  4. Add a 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;
        });
}
Bryan Hong
  • 1,483
  • 13
  • 28
2

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.

Yann Duran
  • 3,842
  • 1
  • 24
  • 24