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










Picture showing the Employee table in lightswitch designer

Click to Enlarge




Creation of an editable grid




Picture showing the Editable Grid Screen for the Employee table

Click to Enlarge




Adding data in the grid




Picture showing adding the data in the Editable Grid Screen

Click to Enlarge




Add buttons for show and hide
















Picture showing adding the new button in the editable grid screen

Click to Enlarge



Picture showing the popup window for adding a new button

Click to Enlarge





Picture showing the designer screen after adding the button

Click to Enlarge











Picture showing changing the display name of the button in the properties window

Click to Enlarge


Add a dll






Picture showing view change dropdown in the solution explorer

Click to Enlarge



Picture showing changing the view to File view for the project

Click to Enlarge



Picture showing the project in the File View

Click to Enlarge



Picture showing adding System.Windows.Control.Data as reference in the project

Click to Enlarge


Code for showing the grid column








Picture showing opening the code screen by clicking on the Edit Execute Code menu

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




Picture showing the output of Show and hide grid columns at runtime in lightswitch 2011

Click to Enlarge



Picture showing the output of Show and hide grid columns at runtime in lightswitch 2011

Click to Enlarge



Picture showing the output of Show and hide grid columns at runtime in lightswitch 2011

Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250