ALL SOFTWARE EXERCISES
- EXERCISES HOME PAGE (862)
- Access 2010 (66)
- Access VBA Macros (17)
- Advanced VBA (29)
- ASP.NET MVC (0)
- ASP.NET webforms - C# (25)
- ASP.NET webforms - VB (27)
- Excel 2010 (83)
- Excel 2013 (10)
- Excel 2016 (0)
- Excel VBA Macros (37)
- Power BI - Excel 2013 (25)
- Power BI - Excel 2016 (23)
- Power BI Desktop (26)
- PowerPivot 2010 (26)
- Report Builder 3.0 (42)
- SQL (156)
- SSAS - multidimensional (21)
- SSAS - tabular (29)
- SSIS Integration Services (40)
- SSRS Reporting Services (53)
- Visual Basic 2010 (42)
- Visual C Sharp 2010 (65)
- WPF - Visual C# (20)
WPF - VISUAL C# EXERCISES
Exercise: Create, bind and format a simple datagrid
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
The answer to the exercise will be included and explained if you attend the course listed below!
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
If necessary, run the SQL script in the above folder to generate the database of Top Trumps cards:
The table called tblCard whose CardTitle and Description fields we'll display.
Create a window called Geeks, and get it to show a DataGrid showing all of the cards whose PackId equals 1, using the default setting of autogenerating columns:
There is no shame - quite the opposite, in fact - in copying and pasting your code-behind to populate the data table of cards. You can then set the ItemsSource of the datagrid to bind to this table.
Now set AutoGenerateColumns to False, and add columns to your datagrid to show the card title and description:
The new version of the datagrid includes two columns only.
Now apply the following formatting and changes:
- Set the CanUserSortColumns property of the DataGrid and the SortMemberPath of each column so that sorting works (you could also set the SortDirection property of the card title column so that initially the geeks are sorted by their card title).
- Unset the CanUserAddRows property.
- Set a row background and alternating row background for the datagrid.
- Set suitable widths for each column.
You can see the effect of these changes on the next page.
This is how your datagrid might look after your formatting changes:
The datagrid with the above changes applied.
Finally, attach code to the MouseDoubleClick event of your datagrid so that you see the title of the chosen card as a message box title, and the description as the message:
What you would see if you were to double-click on Steve Jobs.
Close down this window!