Monthly Archives: June 2017

Print a ListView control’s contents on multiple pages in C#

This example continues the following two examples: Print a ListView with large contents in C# Print the contents of a ListView control in C# Read those examples for an overview of the basic procedure. This example prints the contents of … Continue reading

Posted in controls, extension methods, printing | Tagged , , , , , , , , , , , , , | 4 Comments

Update a DataTable that is bound to a DataGridView in C#

The example Build a DataTable and bind it to a DataGridView in C# shows how you can bind a DataTable to a DataGridView to display data. This example shows how you can add new data to the display. When the … Continue reading

Posted in controls, database | Tagged , , , , , , , , , , , | Leave a comment

Print a ListView with large contents in C#

The example Print the contents of a ListView control in C# explains how to print the data in a ListView control when its View property is set to Details. One difficulty when printing this kind of data is that a … Continue reading

Posted in controls, drawing, graphics, printing | Tagged , , , , , , , , , , , , , , | Leave a comment

Print the contents of a ListView control in C#

The ListView control, like most controls, includes no support for printing. If you want to display a ListView control’s contents on a print out, you need to do all of the printing yourself. Unfortunately printing in C# is extremely flexible … Continue reading

Posted in controls, drawing, graphics, printing | Tagged , , , , , , , , , , , , | 24 Comments

Make rectangle extension methods in C#

This example shows how to add rectangle extension methods to the Rectangle and RectangleF structs. The Rectangle and RectangleF structs have several useful properties for determining their geometry such as Left, Right, Top, and Bottom, but they have no midpoint … Continue reading

Posted in drawing, extension methods, graphics | Tagged , , , , , , , , , , , , , , | Leave a comment

Use string extension methods to validate Social Security numbers in C#

This example defines three extension methods that return true if strings contain Social Security numbers. Recall that you must add extension methods to a static class and that the methods must be static. This example begins by defining a Matches … Continue reading

Posted in extension methods, extensions, regular expressions, strings | Tagged , , , , , , , , , | 2 Comments

Understand the @ symbol in C#

The @ symbol can be pretty confusing for some C# developers. I’ve even known a few who have been programming for quite a while but who still have incorrect assumptions about what @ does. In your code (and only in … Continue reading

Posted in strings, syntax | Tagged , , , , , , , , , , | 1 Comment

Center a form on the screen at run time in C#

You can center a form at design time by setting its StartPosition property to CenterScreen. Note that you cannot do this in the form’s Load event handler because the form’s position is already set when that event handler executes. You … Continue reading

Posted in forms | Tagged , , , , , , , | Leave a comment

Understand when a finally block is executed in C#

Many programmers don’t understand (and many have forgotten) how the try catch finally block works. The basic syntax is: try { // Statements that could cause an error… } catch (Exception ex) { // Statements to execute if there is … Continue reading

Posted in syntax | Tagged , , , , , , , , , , , , | Leave a comment

Use a ProgressBar in C#

This example shows how to use a ProgressBar to show the progress of a long task. This is a very simple example that performs a synchronous task. I created the ProgressBar at design time. I left its Minimum property set … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , | Leave a comment