Articles → LIGHT SWITCH 2011 → Show and hide grid columns at runtime in lightswitch 2011

Show and hide grid columns at runtime

in lightswitch 2011




























Software requirement











Prerequisite knowledge















Creation of Employee entity











Click to Enlarge




Creation of an editable grid





Click to Enlarge




Adding data in the grid





Click to Enlarge




Add buttons for show and hide

















Click to Enlarge




Click to Enlarge






Click to Enlarge












Click to Enlarge


Add a dll







Click to Enlarge




Click to Enlarge




Click to Enlarge




Click to Enlarge


Code for showing the grid column









Click to Enlarge



private DataGrid _dataGrid;

partial void Command_Show_Execute()
{
            // Write your code here.
            this.FindControl("grid").ControlAvailable += ShowGrid;
}

private void ShowGrid(object sender, ControlAvailableEventArgs e)
{
            if (e.Control is DataGrid)
            {
                _dataGrid = (DataGrid)e.Control;
                _dataGrid.Columns[2].Visibility = System.Windows.Visibility.Visible;
            }
}





Code for hiding the grid column










partial void Command_Hide_Execute()
{
            // Write your code here.
            this.FindControl("grid").ControlAvailable += HideGrid;
}

private void HideGrid(object sender, ControlAvailableEventArgs e)
{
            if (e.Control is DataGrid)
            {
                _dataGrid = (DataGrid)e.Control;
                _dataGrid.Columns[2].Visibility = System.Windows.Visibility.Collapsed;
            }
}



Output





Click to Enlarge




Click to Enlarge




Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, April 10, 2012

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250