Post on 16-Feb-2016
description
Introducing C# and the .NET Framework 1-1
Module 1
Introducing C# and the .NET Framework
Contents: Lesson 1: Introduction to the .NET Framework 4 1-4
Lesson 2: Creating Projects Within Visual Studio 2010 1-16
Lesson 3: Writing a C# Application 1-33
Lesson 4: Building a Graphical Application 1-44
Lesson 5: Documenting an Application 1-58
Lesson 6: Debugging Applications by Using Visual Studio 2010 1-66
Lab: Introducing C# and the .NET Framework 1-78
1-2 Programming in C# with Microsoft® .Visual Studio® 2010
Module Overview
Microsoft® Visual Studio® 2010 and the Microsoft .NET Framework 4 provide a comprehensive development platform to enable you to build, debug, deploy, and manage applications.
This module describes the purpose of the .NET Framework 4, and how to build applications by using Visual Studio 2010.
Objectives
After completing this module, you will be able to:
Explain the purpose of the .NET Framework 4.
Create Microsoft Visual C#® projects by using Visual Studio 2010.
Explain the structure of a Visual C# application.
Use the Windows® Presentation Foundation (WPF) Application template to build a simple graphical application.
Introducing C# and the .NET Framework 1-3
Use XML comments to document an application.
Use the debugger to step through a program.
1-4 Programming in C# with Microsoft® .Visual Studio® 2010
Lesson 1
Introduction to the .NET Framework 4
This lesson introduces the .NET Framework 4, and describes the key concepts of .NET and some of the tools that are provided to help simplify development.
Objectives
After completing this lesson, you will be able to:
Describe the purpose of the .NET Framework 4.
Describe the role of Visual C# for writing the code for .NET Framework 4
applications.
Describe the purpose of an assembly.
Explain how the common language runtime (CLR) compiles and runs
assemblies.
Describe the tools that the .NET Framework 4 provides.
Introducing C# and the .NET Framework 1-5
What Is the .NET Framework 4?
Key Points
The .NET Framework 4 provides a comprehensive development platform that offers a fast and efficient way to build applications and services. Using Visual Studio 2010, developers can utilize the .NET Framework 4 to create a wide range of solutions that operate across a broad range of computing devices.
The .NET Framework 4 provides three principal elements: the CLR, the .NET Framework class library, and a collection of development frameworks.
The Common Language Runtime
The .NET Framework 4 provides an environment called the CLR. The CLR manages the execution of code and simplifies the development process by providing a robust and secure execution environment that provides common services such as memory management, transactions, interprocess communications, multithreading, and many other features.
1-6 Programming in C# with Microsoft® .Visual Studio® 2010
The .NET Framework Class Library
The .NET Framework 4 provides a library of reusable classes that developers can use to build applications. The classes provide a foundation of common functionality and constructs that help simplify application development and remove the requirement for developers to constantly reinvent logic. For example, the System.IO.File class contains functionality that enables developers to manipulate files on the Windows file system. In addition to using the classes in the .NET Framework class library, you can extend these classes by creating your own libraries of classes.
Development Frameworks
The .NET Framework 4 provides several development frameworks that you can use to build common types of applications. These frameworks provide the necessary components and infrastructure to get you started. The development frameworks include:
ASP.NET. Enables you to build server-side Web applications.
WPF. Enables you to build rich client applications.
Windows Communication Foundation (WCF). Enables you to build secure and reliable service-oriented applications.
Windows Workflow Foundation (WF). Enables you to build workflow solutions to fulfill the complex business requirements of modern organizations.
Question: What is the purpose of the .NET Framework 4, and the three main
components that it provides?
Additional Reading
For more information about the .NET Framework, see the Microsoft .NET page at http://go.microsoft.com/fwlink/?LinkId=192876.
Introducing C# and the .NET Framework 1-7
The Purpose of Visual C#
Key Points
The CLR runs executable code that is generated by using a compiler. You can build applications for the .NET Framework by using any language that has a compiler that can generate executable code in the format that the CLR recognizes. Visual Studio 2010 provides compilers for C++, Visual Basic, F#, and C#. Compilers for other languages are available from a variety of third-party vendors.
C# is the language of choice for many developers. It uses a syntax that is very similar to C, C++, and Java, and has several extensions and features that are designed for operation with the .NET Framework. Because of its heritage, many developers who are familiar with other programming languages find C# easy to learn and can be productive very quickly.
The C# language has been standardized and is described by the ECMA-334 C# Language Specification. Several vendors apart from Microsoft produce C# compilers. The Microsoft implementation is called Visual C#, and is integrated into Visual Studio. Visual Studio supports Visual C# with a full-featured code editor, compiler, project templates, designers, code wizards, a powerful and easy-to-use debugger, and other tools. C# is also available from Microsoft as Visual C# Express
1-8 Programming in C# with Microsoft® .Visual Studio® 2010
Edition, which provides a subset of the features that are provided with Visual Studio.
Note: C# is an evolving language. Visual C# 2010 uses C# 4.0, which contains several
extensions to the C# language that are not yet part of the ECMA standard.
Question: Which programming languages have you used?
Additional Reading
For more information about the Microsoft implementation of Visual C# 2010, see the Visual C# page http://go.microsoft.com/fwlink/?LinkId=192877.
For more information about the new features of C# 4.0, see the What's New in Visual C# 2010 page at http://go.microsoft.com/fwlink/?LinkId=192878.
Introducing C# and the .NET Framework 1-9
What Is an Assembly?
Key Points
When you compile a Visual C# application by using Visual Studio 2010, the compiler generates an executable file that the CLR can run. This file is called an assembly. An assembly contains code in an intermediate format called Microsoft intermediate language (MSIL). All compilers for the .NET Framework generate code in this format, regardless of the programming language that was used to write an application. This enables the CLR to run code in the same way, regardless of the language that the developer used.
Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, and security.
You can think of an assembly as a collection of types and resources that work together and form a logical unit of functionality. An assembly provides the CLR with the information that it needs to be aware of type implementations.
An assembly can be of two types: an executable program, or a library that contains executable code that other programs can reuse. By using a library, developers can modularize the development of their applications into logical components.
1-10 Programming in C# with Microsoft® .Visual Studio® 2010
Typically, when you are distributing assemblies to customers as part of your application, you will want to ensure that the assembly contains versioning information, and that the assembly is signed.
Versioning your assemblies is important because ultimately, any applications that you build will have multiple releases. Versioning information can help you identify which versions customers already have and enable you to perform the necessary steps to upgrade the application. Similarly versioning information can also help when documenting and fixing bugs.
Signing your assemblies is equally important because it ensures that your assembly cannot easily be modified or replaced by an alternative implementation from a malicious source, and because it gives the assembly a strong name.
Information such as the assembly version and security identity is stored as metadata in an assembly manifest. The manifest also contains metadata that describes the scope of the assembly, and any references to classes and resources. The manifest is typically stored in a portable executable (PE) file.
Assembly Versioning
Assembly version information is stored in the assembly manifest and is used with the assembly name and culture to derive the assembly’s identity. An assembly version number consists of the following:
Major version number
Minor version number
Build number
Revision number
Assembly Signing
Assembly signing is an important step that developers should include in their build process because it provides the following benefits:
It protects assemblies from modification.
It enables you to include the signed assembly in the Global Assembly Cache (GAC), so you can share the assembly with multiple applications.
It guarantees that the name of the assembly is unique.
To sign your assembly, you can use the Sign Tool that is provided with the .NET Framework, or you can use the assembly-signing functionality in Visual Studio 2010.
Introducing C# and the .NET Framework 1-11
Question: Why would you choose to distribute an assembly rather than distribute
the source code?
Additional Reading
For more information about the purpose and features of assemblies, see the Assemblies in the Common Language Runtime page at http://go.microsoft.com/fwlink/?LinkId=192879.
For more information about assembly versioning, see the Assembly Versioning page at http://go.microsoft.com/fwlink/?LinkId=192880.
For more information about assembly signing, see the SignTool.exe (Sign Tool) page at http://go.microsoft.com/fwlink/?LinkId=192881.
1-12 Programming in C# with Microsoft® .Visual Studio® 2010
How the Common Language Runtime Loads, Compiles, and Runs Assemblies
Key Points
Assemblies contain MSIL code, which is not executable. When you run a .NET Framework application, the CLR loads the MSIL code from an assembly and converts it into the machine code that the computer requires.
The CLR is a fundamental component of the .NET Framework. It handles code execution and provides useful services for application development. The CLR contains several components that perform the following tasks when you run a .NET Framework application:
1. The Class Loader locates and loads all assemblies that the application requires. The assemblies will already be compiled into MSIL.
2. The MSIL-to-native compiler verifies the MSIL code and then compiles all assemblies into machine code ready for execution.
Introducing C# and the .NET Framework 1-13
Note: The CLR performs the verification step because it is possible to write your own
MSIL code. If you use a C# compiler, the MSIL code will be valid, but the CLR cannot
make any assumptions.
3. The Code Manager loads the executable assembly and runs the Main method.
4. The Garbage Collector provides automatic lifetime memory management of all objects that your application creates. The Garbage Collector disposes of any objects that your application is no longer using.
5. The Exception Manager provides structured exception handling for .NET applications, which is integrated with Windows structured exception handling.
Question: What steps does the CLR perform when you run your application?
1-14 Programming in C# with Microsoft® .Visual Studio® 2010
What Tools Does the .NET Framework Provide?
Key Points
The .NET Framework provides several tools to help simplify the development of .NET applications. The following table describes some of the key tools.
Tool Description
Code Access Security Policy Tool (Caspol.exe)
Enables users to modify the machine, user, and enterprise security policy. This can include defining a custom permission set and adding assemblies to the full trust list.
Certificate Creation Tool (Makecert.exe)
Enables users to create x.509 certificates for use in their development environment. Typically, you can use these certificates to sign your assemblies and define Secure Sockets Layer (SSL) connections.
Global Assembly Cache Tool (Gacutil.exe)
Enables users to manipulate the assemblies in the GAC. This can include installing and uninstalling assemblies in the GAC so that multiple applications can access them.
Introducing C# and the .NET Framework 1-15
Tool Description
Native Image Generator (Ngen.exe)
Enables users to improve the performance of .NET applications. The Native Image Generator improves performance by precompiling assemblies into images that contain processor-specific machine code. The CLR can then run the precompiled images instead of using just-in-time (JIT) compilation. Alternatively, if you use JIT compilation, your code is compiled just before it is executed.
MSIL Disassembler (Ildasm.exe) Enables users to manipulate assemblies, such as determining whether an assembly is managed, or disassembling an assembly to view the compiled MSIL code.
Strong Name Tool (Sn.exe) Enables users to sign assemblies with strong names. The Strong Name Tool includes commands to create a new key pair, extract a public key from a key pair, and verify assemblies.
Question: You have created two applications that both use an assembly called
Contoso.ReportGenerator.dll. Both applications will run on the same machine.
What is the best approach to share the Contoso.ReportGenerator.dll assembly
and which tool would you use?
Additional Reading
For more information about the tools that the .NET Framework provides, see the .NET Framework Tools page at http://go.microsoft.com/fwlink/?LinkId=192882.
1-16 Programming in C# with Microsoft® .Visual Studio® 2010
Lesson 2
Creating Projects Within Visual Studio 2010
This lesson introduces you to Visual Studio 2010 and describes how it can help simplify the development of .NET applications through the use of predefined application templates, and features of the integrated development environment (IDE).
Objectives
After completing this lesson, you will be able to:
Describe the features that are available in Visual Studio 2010 that aid programming productivity.
Describe the various project types that Visual Studio 2010 supports and when to use them.
Describe the primary files that are found in most Visual Studio solutions.
Introducing C# and the .NET Framework 1-17
Explain how to create a console application by using the Console Application template in Visual Studio 2010.
Use Visual Studio to compile and run an application.
1-18 Programming in C# with Microsoft® .Visual Studio® 2010
Key Features of Visual Studio 2010
Key Points
Visual Studio 2010 presents a single development environment that enables you to rapidly design, implement, build, test, and deploy various types of applications and components by using a range of programming languages.
Some of the key features of Visual Studio 2010 are:
Intuitive integrated development environment. The Visual Studio 2010 IDE
provides all of the features and tools that are necessary to design, implement,
build, test, and deploy applications and components.
Rapid application development. Visual Studio 2010 provides design views for
graphical components that enable you to build complex user interfaces easily.
Alternatively, you can use the Code Editor views, which provide more control.
Visual Studio 2010 also provides wizards that help speed up the development
of particular components.
Introducing C# and the .NET Framework 1-19
Server and data access. Visual Studio 2010 provides the Server Explorer, which
enables you to log on to servers and explore their databases and system
services. It provides a familiar way to create, access, and modify databases that
your application uses.
Debugging features. Visual Studio 2010 provides a debugger, which enables you
to step through local or remote code, pause at breakpoints, and follow
execution paths.
Error handling. Visual Studio 2010 provides the Error List window, which
displays any errors, warnings, or messages that are produced as you edit and
build your code.
Help and documentation. Visual Studio 2010 also provides help and guidance
through Microsoft IntelliSense®, code snippets, and the integrated help system,
which contains documentation and samples.
Question: What are the main reasons why you may choose Visual Studio 2010
over a text editor such as Notepad++?
1-20 Programming in C# with Microsoft® .Visual Studio® 2010
Templates in Visual Studio 2010
Key Points
Visual Studio 2010 supports the development of different types of applications such as Windows-based client applications, Web-based applications, services, and libraries. To help you get started, Visual Studio 2010 provides several application templates that provide a structure for the different types of applications. These templates:
Provide starter code that you can build on to quickly create a functioning
application.
Include supporting components and controls that are relevant to the project
type.
Configure the Visual Studio 2010 IDE to the type of application that you are
developing.
Add references to any initial assemblies that this type of application usually
requires.
Introducing C# and the .NET Framework 1-21
Types of Templates
The following table describes some of the common application templates that you can use when you develop .NET Framework applications by using Visual Studio 2010.
Template Description
Console Application Provides the environment settings, tools, project references, and starter code to develop an application that runs in a command-line interface. This type of application is considered lightweight compared to the Windows Forms application template because there is no graphical user interface.
WPF Application Provides the environment settings, tools, project references, and starter code to build a rich graphical Windows application. A WPF application enables you to create the next generation of Windows applications, with much more control over user interface design.
Class Library Provides the environment settings, tools, and starter code to build a .dll assembly. You can use this type of file to store functionality that you might want to invoke from many other applications.
Windows Forms Application Provides the environment settings, tools, project references, and starter code to build a graphical Windows Forms application.
ASP.NET Web Application Provides the environment settings, tools, project references, and starter code to create a server-side, compiled ASP.NET Web application.
ASP.NET MVC 2 Application Provides the environment settings, tools, project references, and starter code to create a Model-View-Controller (MVC) Web application. An ASP.NET MVC Web application differs from the standard ASP.NET Web application in that the application architecture helps you separate the presentation layer, business logic layer, and data access layer.
Silverlight Application Provides the environment settings, tools, project references, and starter code to build a rich, graphical Web application.
1-22 Programming in C# with Microsoft® .Visual Studio® 2010
Template Description
WCF Service Application Provides the environment settings, tools, project references, and starter code to build Service Orientated Architecture (SOA) services.
Question: What project templates would you use for each of the following:
A client application that will run on a Windows-based computer.
A library of functionality that you want to use in other applications.
A Web site that you will host on an Internet Information Services (IIS) Web server.
Introducing C# and the .NET Framework 1-23
The Structure of Visual Studio Projects and Solutions
Key Points
Visual Studio 2010 uses solutions and projects as conceptual containers to organize your source files during development. Categorizing your source files in this way simplifies the build and deployment process for your .NET Framework applications.
Visual Studio Projects
A project is used to organize source files, references, and project-level configuration settings that make up a single .NET Framework application or library. When you create a project in Visual Studio, the project is automatically organized into a solution.
The following table describes some of the common file types that you will find in a Visual Studio project.
1-24 Programming in C# with Microsoft® .Visual Studio® 2010
File Description
.cs Code files that can belong to a single project solution. This type of file can represent any of the following:
Modules
Windows Forms files
Class files
.csproj Project files that can belong to multiple project solutions. The .csproj file also stores settings for the project, such as the output path for the build output and the target platform.
.aspx Files that represent ASP.NET Web pages. An ASP.NET file can contain your Visual C# code or you can use an accompanying .aspx.cs file to store your code in addition to the page markup.
.config Configuration files are XML-based files that you can use to store application-level settings such as database connection strings, which you can then modify without recompiling your application.
.xaml XAML files are used in WPF and Microsoft Silverlight® applications to define user interface elements.
Visual Studio Solutions
A single Visual Studio solution is a container for one or more projects. By default, when you create a new project, Visual Studio automatically creates a solution for the project. You can add additional projects to a solution. This is useful if, for example, you are building a library assembly and an application that tests this library. You can build and compile both projects as part of the same solution rather than having to run multiple instances of Visual Studio.
A solution can also contain project-independent items that any of the projects in the solution can use. For example, an ASP.NET solution can contain a single cascading style sheet (.css) file that applies a standard look and feel to any of the included ASP.NET projects.
Categorizing multiple projects into a single Visual Studio solution provides the following advantages:
It enables you to work on multiple projects within a single Visual Studio 2010
session.
It enables you to apply configuration settings globally to multiple projects.
Introducing C# and the .NET Framework 1-25
It enables you to deploy multiple projects within a single solution.
The following table describes the solution definition files.
File Description
.sln A Visual Studio 2010 solution file that provides a single point of access to multiple projects, project items, and solution items. The .sln file is a standard text file, but it is not recommended to change it outside Visual Studio 2010.
.suo A solution user options file that stores any settings that you have changed to customize the Visual Studio 2010 IDE.
Question: What role does the .sln file play in Visual Studio solutions?
1-26 Programming in C# with Microsoft® .Visual Studio® 2010
Creating a .NET Framework Application
Key Points
The application templates that Visual Studio 2010 provides enable you to start creating an application with minimal effort. You can then add your code and customize the project to meet your own requirements.
The following steps describe how to create a console application.
Create a new console project by using the Console Application
template in Visual Studio 2010
1. Open Visual Studio 2010.
2. On the File menu, point to New, and then click Project.
3. In the New Project dialog box, specify the following settings for the project,
and then click OK:
a. In the Installed Templates list, under Visual C#, click Windows.
b. In the center pane, click Console Application.
Introducing C# and the .NET Framework 1-27
c. In the Name box, specify a name for the project.
d. In the Location box, specify the path where you want to save the project.
Programmer Productivity Features
Visual Studio 2010 provides a host of features that can help you to write code. When writing code, developers need to recall information about many program elements. Instead of manually looking up information by searching help files or other source code, the IntelliSense feature in Visual Studio provides the information that developers need directly from the editor. IntelliSense provides the following features:
Quick Info. The Quick Info option displays the complete declaration for any identifier in your code. Move the mouse so that the cursor rests on an identifier to display Quick Info for that identifier, which appears in a yellow pop-up box.
Complete Word. The Complete Word option types the rest of a variable, command, or function name after you have entered enough characters to disambiguate the term. Type the first few letters of the name and then press ALT+RIGHT ARROW or CTRL+SPACEBAR to complete the word.
Often, when you are building a .NET Framework application, you will need to repeat common constructs in your code. Examples might be a loop, or code to handle exceptions. Code snippets are designed to ease the burden of having to implement such common code by providing boilerplate code templates that can be readily inserted into your code and amended to suit your needs. You can access these code snippets by using the Code Snippet Picker.
You can manage code snippets by using the Code Snippet Manager dialog box, which is available on the Tools menu. The Code Snippet Manager enables you to add new code snippets by specifying new folders that the Code Snippet Picker will look in for code snippets; by importing code snippets; or by searching for code snippets online. The Code Snippets Manager is also useful for discovering the shortcut key sequence that is associated with a code snippet.
Finally, Visual Studio 2010 provides a host of other features on the shortcut menu that appears when you right-click a code statement. These include Refactor, Organize, Create Unit Tests, Go To Definition, Find All References, and Outline. These features will be covered in more detail in later modules.
1-28 Programming in C# with Microsoft® .Visual Studio® 2010
Question: What is the purpose of code snippets?
Introducing C# and the .NET Framework 1-29
Building and Running a .NET Framework Application
Key Points
Visual Studio provides an integrated environment that enables you to quickly compile and run your applications.
You can also build and run an application from the command line if you do not have Visual Studio available.
The following steps describe how to build and run an application.
Build and run an application in Visual Studio 2010
The following steps assume that you have created a new console application.
1. In Visual Studio 2010, on the Build menu, click Build Solution.
2. On the Debug menu, click Start Debugging.
1-30 Programming in C# with Microsoft® .Visual Studio® 2010
Build an application from the command line
The following steps assume that you have created a new console application called MyProject, which is saved in the C:\Users\Student\Documents \Visual Studio 2010\MyProject\ folder.
1. Click Start, point to All Programs, click Microsoft Visual Studio 2010, click
Visual Studio Tools, and then click Visual Studio Command Prompt
(2010).
2. In the Visual Studio Command Prompt window, type the text in the following
code example, and then press ENTER.
csc.exe /t:exe /out:"C:\Users\Student\Documents\Visual Studio
2010\MyProject\myApplication.exe" "C:\Users\Student\Documents\Visual
Studio 2010\MyProject\*.cs"
3. Right-click the Start menu, click Open Windows Explorer, and then move to
C:\Users\Student\Documents\Visual Studio 2010\MyProject\.
The MyProject folder should now contain the myApplication.exe executable assembly, which you can run.
Question: Describe two ways to build and run a .NET Framework application.
Introducing C# and the .NET Framework 1-31
Demonstration: Disassembling a .NET Framework Assembly
Key Points
Run an existing .NET Framework application.
Open Ildasm.
Disassemble an existing .NET Framework assembly.
Examine the disassembled .NET Framework assembly.
Demonstration Steps
1. Log on to the 10266A-GEN-DEV virtual machine as Student with the password Pa$$word.
2. Run MyFirstApplication.exe in the E:\Demofiles\Mod1\Demo1 folder, and examine the applications output.
3. Close MyFirstApplication.exe.
4. Run ildasm.exe in the C:\Program Files\Microsoft SDKs \Windows\v7.0A\bin folder.
1-32 Programming in C# with Microsoft® .Visual Studio® 2010
5. Using ildasm, open the MyFirstApplication.exe in the E:\Demofiles\Mod1\Demo1 folder, and then inspect the contents of the MyFirstApplication assembly. Examine the following items:
The public key token and the version number in the assembly Manifest.
The constructor and Main method in the MyFirstApplication.Program node.
6. Close ildasm.exe.
Question: When developing a .NET Framework application, how would you find
Ildasm useful?
Introducing C# and the .NET Framework 1-33
Lesson 3
Writing a C# Application
This lesson describes the structure of a simple C# application, and how a C# application contains one or more classes. This lesson describes how to reference functionality that is defined in classes in other assembles and libraries, and how you can use the Console class in the .NET Framework class library to perform simple input and output operations. Finally, this lesson explains how and why you should add comments to your applications.
Objectives
After completing this lesson, you will be able to:
Describe how Visual C# uses namespaces and classes.
Describe the structure of an application.
Perform input and output operations by using methods that the Console class provides.
Apply best practices commenting a Visual C# application.
1-34 Programming in C# with Microsoft® .Visual Studio® 2010
What Are Classes and Namespaces?
Key Points
Visual C# is an object-oriented language that uses classes and namespaces to modularize .NET Framework applications into logical components.
A class is essentially a blueprint that defines the characteristics of an entity, and includes properties that define the types of data that the object can contain and methods that describe the behavior of the object. A namespace represents a logical collection of classes. Classes are stored in assemblies, and a namespace is simply a device to disambiguate classes that might have the same name in different assemblies.
For example, the System.IO namespace includes the following classes that enable you to manipulate the Windows file system. However, you could create classes with the same name under your own namespace:
File
FileInfo
Directory
Introducing C# and the .NET Framework 1-35
DirectoryInfo
Path
To use a class that is defined in the .NET Framework, perform the following tasks:
1. Add a reference to the assembly that contains the compiled code for the class.
2. Bring the namespace that contains the class into scope.
If you are writing a .NET Framework application to write text to a new file on the file system, you can bring the System.IO namespace into scope and then use the WriteAllText method of the File class.
To bring a namespace into scope in a Visual C# application, you can use the using statement. The following code example shows how to bring the System, System.IO, and System.Collections namespaces into scope.
using System;
using System.IO;
using System.Collections;
The using statement is simply a convenience and you can manage without it. For example, you can use System.Console rather than Console.
Question: In your console application, you want to use the Console class, which
is part of the System namespace. How do you bring the System namespace into
scope?
1-36 Programming in C# with Microsoft® .Visual Studio® 2010
The Structure of a Console Application
Key Points
When you create a new console application by using the Console Application template, Visual Studio 2010 performs the following tasks:
It creates a new .csproj file to represent the console project and structure all of the default components in a console project.
It adds references to the assemblies in the .NET Framework class library that console applications most commonly require. This set of assemblies includes the System assembly.
It creates the Program.cs file with a Main method, which provides an entry point into the console application.
The Program.cs file that Visual Studio 2010 creates resembles the following code example.
Introducing C# and the .NET Framework 1-37
using System;
namespace MyFirstApplication
{
class Program
{
static void Main(string[] args)
{
}
}
}
The following table describes the code items in the Program.cs file.
Code item Description
using System; Brings the System namespace into scope.
namespace MyFirstApplication
{
...
}
Defines a new namespace called MyFirstApplication. Typically, in a new project, this defaults to the project name.
class Program
{
...
}
Defines a new internal class called Program.
static void Main(string[] args)
{
...
}
Defines a new private static Main method with a void return type that accepts a parameter of type string array.
What Is the Main Method?
Every .NET Framework application that compiles into an executable file must have a Main method. This method provides the CLR with an entry point into the application. When you run a .NET Framework application, the Main method is the first method that the CLR executes.
1-38 Programming in C# with Microsoft® .Visual Studio® 2010
When you develop your .NET Framework applications, it is good practice to keep the Main method lightweight, and let it serve as just an entry point, not a container for most of the logic in your application.
The Main method has the following significant characteristics:
It is private. This means that it is not visible to other classes outside the Program class.
It uses the static key, so it can be called without creating an instance of the Program class.
It uses the void return type, so it is a method that does not return data.
It accepts data in the form of a string array. Therefore, when you run the console application, any command-line arguments that you provide will be available in the args parameter.
Question: In your console application, you have a method called Main. What is
the purpose of the Main method?
Additional Reading
For more information about command-line arguments, see the Main() and Command-Line Arguments (C# Programming Guide) page at http://go.microsoft.com/fwlink/?LinkId=192889.
Introducing C# and the .NET Framework 1-39
Performing Input and Output by Using a Console Application
Key Points
The System namespace provides the Console class, which contains several methods that enable you to add basic console I/O functionality to an application, such as accepting input and displaying data.
The following table describes some of the key methods that the Console class provides.
Method Description
Clear() Clears the console window and console buffer of any data. The following code example provides an example of this.
using System;
...
Console.Clear(); // clears the console display
1-40 Programming in C# with Microsoft® .Visual Studio® 2010
Method Description
Read() Reads the next character from the console window. The following code example provides an example of this.
using System;
...
int nextCharacter = Console.Read();
ReadKey() Reads the next character or key press from the console window. The following code example provides an example of this.
using System;
...
ConsoleKeyInfo key = Console.ReadKey();
ReadLine() Reads the next line of characters from the console window. The following code example provides an example of this.
using System;
...
string line = Console.ReadLine();
Write() Writes the text to the console window. The following code example provides an example of this.
using System;
...
Console.Write("Hello there!");
WriteLine() Writes the text followed by a line break to the console window. The following code example provides an example of this.
using System;
...
Console.WriteLine("Hello there!");
Question: Which two methods would you use to do the following:
Display the message "Please press any key" on a new line.
Capture the key that the user pressed.
Introducing C# and the .NET Framework 1-41
Additional Reading
For more information about the Console class, see the Console Class page at http://go.microsoft.com/fwlink/?LinkId=192883.
1-42 Programming in C# with Microsoft® .Visual Studio® 2010
Best Practices for Commenting C# Applications
Key Points
It is good programming practice to begin all procedures with a brief comment that describes the functional characteristics of the procedure. This is for your own benefit and the benefit of anyone else who examines the code.
In Visual C#, comments begin with two slash marks (//). Comments can follow a statement on the same line, or occupy an entire line. Both are illustrated in the following code example.
// This is a comment on a separate line.
string message = "Hello there!"; // This is an inline comment.
The Comment and Uncomment Toolbar Buttons
You can add or remove comment symbols for a block of code by selecting the lines of code and choosing the Comment or Uncomment buttons on the Text Editor toolbar.
Introducing C# and the .NET Framework 1-43
Commenting Guidelines
As your code becomes more complex, use comments to make your code more readable and easier to maintain. You should use comments to explain the purpose of a section of code in natural language, especially when the purpose might not be obvious or clear.
The following list provides some guidelines regarding when you should comment your code:
Begin procedures with a comment block. This block should include information such as the purpose of the procedure, the value returned, the arguments, and so on.
In longer procedures, use comments to break up units of work within the procedure.
When you declare variables, use a comment to indicate how the variable will be used.
When you write a decision structure, use a comment to indicate how the decision is made and what it implies.
Question: Why is it important for you to comment your code?
1-44 Programming in C# with Microsoft® .Visual Studio® 2010
Lesson 4
Building a Graphical Application
This lesson introduces you to applications that have a graphical user interface, and provides the example of a WPF application.
This lesson also explains what WPF is, how WPF applications are structured, and how you can create your own WPF applications by using Visual Studio 2010.
Objectives
After completing this lesson, you will be able to:
Describe the purpose of WPF.
Describe the structure of a WPF application.
Describe the controls that WPF provides, and how to set control properties.
Describe the concept of events, and how WPF controls use events.
Explain how to build a simple WPF application by using Visual Studio 2010.
Introducing C# and the .NET Framework 1-45
What Is WPF?
Key Points
Windows Presentation Foundation is the unified graphical subsystem for Windows that provides the foundation for building applications and high-fidelity experiences. It unifies how Windows creates, displays, and manipulates documents, media, and user interfaces. This enables you to create visually stunning user experiences.
Features of Windows Presentation Foundation
The main features of Windows Presentation Foundation are:
Extensive support for client application development. Developers can create eye-
catching, highly functional applications. WPF includes several text-rendering
features such as OpenType and TrueType.
Ease of user interface design. WPF provides a set of built-in controls. It uses the
concept that there is a logical separation of a control from its appearance,
which is generally considered to be a good architectural principle.
1-46 Programming in C# with Microsoft® .Visual Studio® 2010
Use of XAML. XAML enables developers to use an XML-based model to
declaratively manipulate the object model. XAML is faster and easier to
implement than procedural code. XAML is used to define the user interface in
a WPF application.
Support for interoperability with older applications. Developers can use WPF
inside existing Win32 code or existing Win32 code inside WPF.
Question: Why would you choose to use WPF to create an application instead of
Windows Forms?
Additional Reading
For more information about what WPF is, see the Introduction to WPF page at http://go.microsoft.com/fwlink/?LinkId=192884.
Introducing C# and the .NET Framework 1-47
The Structure of a WPF Application
Key Points
When you create a new WPF application by using the WPF Application template, Visual Studio 2010 performs the following tasks:
It creates a new .csproj file to represent the WPF project and structure all of the default components in a WPF project.
It adds references to the necessary assemblies, which include the PresentationCore, PresentationFramework, System, System.Core, and System.Xaml assemblies.
It creates the App.xaml markup file and an App.xaml.cs code-behind file, which you can use to define application-level resources and functionality.
It creates the MainWindow.xaml markup file and the MainWindow.xaml.cs code-behind file, which you use as a starting point to building your first WPF window.
The default markup that is generated in the MainWindow.xaml markup file is shown in the following code example.
1-48 Programming in C# with Microsoft® .Visual Studio® 2010
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
This markup defines a simple window with a default title, width, and height. You can change these properties by editing the XAML code, or by using the Properties window in Visual Studio. You can also change these properties dynamically, by using code when the application runs. The Grid control governs the layout of controls that you add to the window. If you want to use an alternative layout, you can replace the markup for the Grid control with a different layout control.
The default markup that is generated in the App.xaml markup file is shown in the following code example.
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Note that the Application element contains a StartupUri attribute that points to the window that you want to open when the application runs.
Both the App.xaml and MainWindow.xaml markup files use XAML to represent resources and user interface elements. XAML is a markup language for declarative application programming. Using the XAML markup at design time enables you to separate the user interface design from the application logic, which is stored in code-behind files. XAML directly represents the instantiation of managed objects.
Question: Can you think of any other markup languages that behave in a similar
way to XAML?
Introducing C# and the .NET Framework 1-49
The WPF Control Library
Key Points
WPF includes a rich library of controls that you can use to build your WPF applications. The controls that are included in the library are common user interface components that you would typically find in every Windows-based application, such as the button and the text box. You can also define your own custom controls.
WPF Common Controls
The following table describes some of the commonly used controls in the WPF control library. It also provides a simple XAML example for each, showing the common properties that you can set at design time.
1-50 Programming in C# with Microsoft® .Visual Studio® 2010
Control Description XAML example
Button The Button control represents a typical clickable button that you would find in most Windows applications.
<Button Name="myButton"
BorderBrush="Black"
BorderThickness="1"
Click="myButtonOnClick"
ClickMode="Press">
Click Me
</Button>
Canvas The Canvas control represents a layout panel that enables you to position child controls absolutely.
<Canvas Background="Black"
Height="200" Width="200">
<!-- Child controls -->
</Canvas>
ComboBox The ComboBox control represents a drop-down list that a user can scroll through and make a selection from.
<ComboBox Name="myComboBox">
<ComboBoxItem>
Item a
</ComboBoxItem>
<ComboBoxItem>
Item b
</ComboBoxItem>
</ComboBox>
Grid The Grid control represents a flexible table that can contain multiple columns and rows. You typically use the Grid control to position child controls.
<Grid ShowGridLines="True"
Width="200" Height="200">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<!-- Child controls -->
</Grid>
Label The Label control represents a read-only text block that you could use to display some static text.
<Label Name="myLabel">
Hello
</Label>
Introducing C# and the .NET Framework 1-51
Control Description XAML example
StackPanel The StackPanel control enables you to stack child controls horizontally or vertically.
<StackPanel
Name="myStackPanel"
Orientation="Vertical">
<Label>Item 1</Label>
<Label>Item 2</Label>
<Label>Item 3</Label>
</StackPanel>
TextBox The TextBox control represents an editable field that you can use to display and capture text.
<TextBox Name="myTextBox">
</TextBox>
Note that you can also define controls dynamically by using Visual C# in your code-behind file.
WPF Control Properties
Each control in WPF has an associated set of properties that you can use to define the appearance and behavior of a control. For example, most controls have a Height property and a Width property that specify the dimensions of the control, and a Margin property that indicates where the control should appear relative to the layout control it is contained within.
You can set control properties:
In the XAML window declaratively by editing the XAML directly.
In the Properties window. This approach modifies the XAML definition of a control on your behalf.
At run time, by using Visual C# code. This approach does not change the XAML definition of any controls.
Question: You are building a simple form to capture user credentials and enable
users to log on. Which controls could you use to build this form?
Additional Reading
For more information about the controls in the WPF control library, see the Control Library page at http://go.microsoft.com/fwlink/?LinkId=192886.
1-52 Programming in C# with Microsoft® .Visual Studio® 2010
WPF Events
Key Points
When you create a WPF, ASP.NET, or Windows Forms application in Visual Studio 2010, you create an event-driven application. Event-driven applications execute code in response to an event. Each form and control that you create exposes a predefined set of events. When one of these events occurs, and there is code in the associated event handler, that code is invoked.
Handling Events
You can specify the events that a control responds to at design time by editing the XAML definition of a control (you specify the event and the name of an event-handling method to run when the event occurs). Alternatively, you can use the Events tab in the Properties window (this technique modifies the XAML definition of a control automatically).
You must provide the methods that handle the events by using code in the code-behind file.
The following code examples show the XAML markup for a Button control with a Click event handler, and the C# code that defines the event handler. When the
Introducing C# and the .NET Framework 1-53
user clicks the button, the myButton_Click method is called. The parameters to the myButton_Click method are defined by WPF, and they are populated with information about the button and the event at run time.
[XAML control declaration]
<Button Name="myButton" Click="myButton_Click">ClickMe</Button>
[Visual C# event handler]
private void myButton_Click(object sender, RoutedEventArgs e)
{
// Code to do something goes here.
}
The following code examples show how you can define a closing event handler for a Window control.
[XAML control declaration]
<Window x:Class="WpfApplication.MainWindow" Name="myWindow"
xmlns="..."
xmlns:x="..."
Title="MainWindow" Height="350" Width="525"
Closing="myWindow_Closing">
</Window>
[Visual C# event handler]
private void myWindow_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// Code to do something goes here.
}
Question: When you develop your WPF applications, what two ways can you use
to specify events for controls?
1-54 Programming in C# with Microsoft® .Visual Studio® 2010
Building a Simple WPF Application
Key Points
You can create a WPF application in Visual Studio 2010 by using the WPF Application template.
Create a new WPF application
1. Click Start, point to All Programs, click Microsoft Visual Studio 2010, and then click Microsoft Visual Studio 2010.
2. In Visual Studio 2010, on the File menu, click New, and then click Project.
3. In the New Project dialog box, perform the following, and then click OK:
In the center pane, click WPF Application.
In the Name box, type a name for your WPF application.
In the Location box, type a path where you would like to save your project.
Download from www.eBookTM.com
Introducing C# and the .NET Framework 1-55
Add controls to the WPF application
1. On the View menu, click Toolbox.
2. In the Toolbox window, double-click the control that you want to add to your application.
3. You can then use the Design window or the XAML window to customize the control.
Set control properties
1. In the Design window, click the control that you want to customize.
2. You can then set the properties as follows:
Switch to the XAML window, and then edit the XAML directly.
Switch to the Properties window, and then set the predefined properties.
Note: You can also set properties in Visual C# by using the Code Editor window.
Add event handlers to controls
1. In the Design window, click the control that you want to add an event handler to.
2. In the Properties window, on the Events tab, double-click the event that you want to add, for example, a Click event handler for a button.
Add code to the WPF application
1. In the Solution Explorer window, right-click the XAML file that you want to add code to, and then click View Code.
2. You can then use the Code Editor window to define the logic behind your controls.
Question: What windows in Visual Studio 2010 do you typically use when you
are building your applications?
1-56 Programming in C# with Microsoft® .Visual Studio® 2010
Demonstration: Building a Simple WPF Application
Key Points
Create a new WPF application.
Add controls to the WPF application.
Set the properties for the controls.
Add code to the application.
Build and run the application.
Demonstration Steps
1. Open Microsoft Visual Studio 2010.
2. In Visual Studio 2010, create a new project with the following characteristics:
Type: WPF Application
Name: MyFirstWpfApp
Introducing C# and the .NET Framework 1-57
Location: E:\Demofiles\Mod1\Demo2\Starter
3. Use the Toolbox to add a button control to the application.
4. Examine the XAML mark-up generated by Visual Studio 2010.
5. Use the Properties window to set the following properties for the button control:
FontSize: 20
Height: 50
Width: 150
6. Use the XAML window to perform the following:
In the Button element, set the Content attribute to Click Me.
In the Window element, set the Height attribute to 150.
In the Window element, set the Width attribute to 190.
7. Use the Events tab in the Properties window to generate a Click event handler for the button control.
8. Open the MainWindow.xaml.cs file, and in the ClickMeButton_Click method add the following code:
... private void ClickMeButton_Click(object sender, RoutedEventArgs e) { MessageBox.Show("You clicked me!!"); } ...
9. Build and run the application.
Question: When you are developing a WPF application in Visual Studio 2010,
what are the two main ways in which you can set properties for WPF controls?
1-58 Programming in C# with Microsoft® .Visual Studio® 2010
Lesson 5
Documenting an Application
This lesson introduces XML comments and explains how you can use them when you are developing your .NET applications. This lesson also shows how to build a formatted help file by using the Sandcastle tool.
Objectives
After completing this lesson, you will be able to:
Describe what XML comments are and how you can use them in .NET applications.
Describe some of the commonly used XML comment tags.
Explain how to generate an XML documentation file and how to use Sandcastle to generate a formatted help file by using this XML documentation file.
Introducing C# and the .NET Framework 1-59
What Are XML Comments?
Key Points
In Visual Studio 2010, you can add comments to your source code that will be processed to an XML file. This file can then be the input to a process that creates Help documentation for the classes in your code. You can also use an XML file to support IntelliSense on your component.
Inline comments are part of the Visual C# standard, whereas XML comments are a Microsoft extension and are typically used by third-party tools such as Sandcastle Help File Builder.
XML Documentation Comments
Documentation comments in Visual C# begin with three slash marks (///) followed by an XML documentation tag.
In the following code example, the Hello class contains <summary> and <seealso> documentation tags.
1-60 Programming in C# with Microsoft® .Visual Studio® 2010
/// <summary> The Hello class prints a greeting on the screen
/// </summary>
public class Hello
{
/// <summary> We use console-based I/O. For more information about
/// WriteLine, see <seealso cref="System.Console.WriteLine()"/>
/// </summary>
public static void Main( )
{
Console.WriteLine("Hello World");
}
}
Question: Why would you use XML comments rather than standard comments?
Additional Reading
For more information about XML comments, see the XML Documentation Comments (C# Programming Guide) page at http://go.microsoft.com/fwlink/?LinkId=192887.
Introducing C# and the .NET Framework 1-61
Common XML Comment Tags
Key Points
There are several suggested XML tags that you can use. You can also create your own custom tags. The following table shows some XML tags and their uses.
Tag Purpose
<summary> … </summary> Provides a brief description. Use the <remarks> tag for a longer description.
<remarks> … </remarks> Provides a detailed description. This tag can contain nested paragraphs, lists, and other types of tags.
<example> … </example> Provides an example of how a method, property, or other library member should be used. It often involves the use of a nested <code> tag.
<code> … </code> Indicates that the enclosed text is application code.
<returns> … </returns> Documents the return value and type of a method.
1-62 Programming in C# with Microsoft® .Visual Studio® 2010
Question: Which tag would you use to provide a detailed description of a
method?
Additional Reading
For more information about XML comment tags, see the Recommended Tags for Documentation Comments (C# Programming Guide) page at http://go.microsoft.com/fwlink/?LinkId=192888.
Introducing C# and the .NET Framework 1-63
Generating Documentation from XML Comments
Key Points
You can compile the XML tags and documentation into an XML file by selecting the XML documentation file check box in the Properties window for a project, or by using the /doc command-line switch when you build an application that has embedded XML comments.
If there are no errors, you can view the XML file that is generated by using an application such as Windows Internet Explorer®, and you can generate a help file by using a tool such as Sandcastle.
Note: Sandcastle is not provided as part of Visual Studio, but it is available separately
from the CodePlex Web site.
Generate an XML file by using Visual Studio 2010
1. In Solution Explorer, right-click a project, and then click Properties.
2. In the Properties window, on the Build tab, select the XML documentation file check box.
1-64 Programming in C# with Microsoft® .Visual Studio® 2010
Generate an XML file by using csc.exe
1. Click Start, point to All Programs, click Microsoft Visual Studio 2010, click Visual Studio Tools, and then click Visual Studio Command Prompt (2010).
2. In the Visual Studio Command Prompt (2010) window, type the command in the following code example.
csc.exe /t:exe /doc:"C:\Users\Student\Documents\Visual Studio
2010\MyProject\myComments.xml" /out:"C:\Users\Student\Documents\Visual
Studio 2010\MyProject\myApplication.exe"
"C:\Users\Student\Documents\Visual Studio 2010\MyProject\*.cs"
Note: The /doc switch instructs the compiler to generate an XML file that contains the
XML comments.
The XML that the compiler generates should resemble the following code example.
<?xml version="1.0"?>
<doc>
<assembly>
<name>MyProject</name>
</assembly>
<members>
<member name="T:Hello">
<summary> The Hello class prints a greeting on the screen
</summary>
</member>
<member name="M:Hello.Main">
<summary> We use console-based I/O. For more information
about WriteLine,
see <seealso cref="M:System.Console.WriteLine"
/>
</summary>
</member>
</members>
</doc>
Introducing C# and the .NET Framework 1-65
Generate a .chm file by using Sandcastle Help File Builder
Now that you have an XML file that contains the comments that were extracted from your project, you can create a .chm file by using a tool such as Sandcastle Help File Builder.
1. Click Start, point to All Programs, click Sandcastle Help File Builder, and then click Sandcastle Help File Builder GUI.
2. In Sandcastle Help File Builder, on the File menu, click New Project.
3. In the Save New Help Project As dialog box, perform the following, and then click Save:
a. Browse to the path where you want to save the project.
b. Specify a name for the Sandcastle project.
4. In the Project Explorer window, right-click Documentation Sources, and then click Add Documentation Source.
5. In the Select the documentation source(s) dialog box, browse to the XML file folder, and then click Open.
6. On the Documentation menu, click Build Project.
Wait for the project to successfully build. This will take a minute.
Question: Which switch do you need to provide to get csc.exe to produce XML
output?
Additional Reading
For more information about Sandcastle Help File Builder, see the Sandcastle Help File Builder page at http://www.codeplex.com/SHFB.
1-66 Programming in C# with Microsoft® .Visual Studio® 2010
Lesson 6
Debugging Applications by Using Visual Studio 2010
In this lesson, you will learn how to use Visual Studio 2010 to help you debug your applications. You will learn how to use the Debug toolbar, breakpoints, and debug windows to examine your application and step through application code at run time.
Objectives
After completing this lesson, you will be able to:
Describe the functions that Visual Studio 2010 provides to aid debugging.
Explain how to set, disable, enable, and remove breakpoints.
Explain how to step into, step over, and step out of code.
Describe how to use the debug windows to examine information about an application.
Introducing C# and the .NET Framework 1-67
Debugging in Visual Studio 2010
Key Points
Debugging is an essential part of application development. You may notice errors as you write code, but some errors—especially logic errors—may only occur in specific circumstances that you do not test for. Users may report these errors to you, and you will have to correct them.
Visual Studio 2010 provides several tools to help you debug code. You might use these while you develop code, during a test phase, or after the application has been released. You will use the tools in the same way regardless of the circumstances.
You can run an application with or without debugging enabled. When debugging is enabled, your application is said to be in Debug mode. To access the numerous debug functions, including the ability to step through code line by line, you can use the controls on the Debug menu, the controls on the Debug toolbar, and keyboard shortcuts.
Debug Controls
The following table lists the main debug controls on the Debug menu and the Debug toolbar, and the corresponding keyboard shortcuts.
1-68 Programming in C# with Microsoft® .Visual Studio® 2010
Menu option Toolbar button Keyboard shortcut Description
Start
Debugging
Start/continue F5 This button is available when your application is not running and when you are in break mode. It will start your application in Debug mode or resume the application if you are in break mode.
Break All Break all CTRL+ALT+BREAK This button causes application processing to pause and break mode to be entered. The button is available when an application is running.
Stop
Debugging
Stop SHIFT+F5 This button stops debugging. It is available when an application is running or in break mode.
Restart Restart CTRL+SHIFT+F5 This button is equivalent to stop followed by start. It will cause your application to be restarted from the beginning. It is available when an application is running or in break mode.
Step Into Step into F11 This button is used for stepping through code. See the next topic in this lesson.
Step Over Step over F10 This button is used for stepping through code. See the next topic in this lesson.
Step Out Step out SHIFT+F11 This button is used for stepping through code. See the next topic in this lesson.
Windows Windows Various This button enables access to various debug windows, each of which has its own shortcut key.
Introducing C# and the .NET Framework 1-69
Question: What are some of the debug functions that Visual Studio 2010
provides?
1-70 Programming in C# with Microsoft® .Visual Studio® 2010
Using Breakpoints
Key Points
When you run an application in Debug mode, you can pause execution and enter break mode. In break mode, no further execution takes place until you restart the application or step through the code line by line. You can also view and change variable values, execute additional code or evaluate expressions, and more. When you are in break mode, the current line of code is indicated by a yellow arrow in the gray bar to the left of the code and by a yellow background for the next statement due to be executed.
The Break All debug function enables you to enter break mode. However, this function does not give you much control over exactly where code execution pauses.
Breakpoints enable you to choose exactly where code execution will pause. If you place a breakpoint on a line of code, the application will enter break mode as soon as that line of code is reached, before it executes that line of code.
Introducing C# and the .NET Framework 1-71
Set a breakpoint
1. Locate the line of code where you want to set a breakpoint.
2. Add a breakpoint by using one of the following steps:
a. Click the gray bar to the left of the line of code.
b. Position the cursor on the line of code, and then press F9.
c. Position the cursor on the line of code, and then, on the Debug menu, click Toggle Breakpoint.
d. Right-click the line of code, point to Breakpoint, and then click Insert Breakpoint.
The breakpoint is indicated by a solid red circle in the gray bar to the left of the code and by a red background for the line of code that contains the breakpoint.
Disable or enable a breakpoint
1. Locate a line of code that has an enabled or disabled breakpoint.
2. Disable or enable the breakpoint by using one of the following steps:
a. Right-click the solid red circle in the gray bar to the left of the line of code, and then click Disable Breakpoint or Enable Breakpoint.
b. Right-click the line of code that contains the breakpoint, point to Breakpoint, and then click Disable Breakpoint or Enable Breakpoint.
c. If the breakpoint is disabled, click the solid red circle to the left of the code to enable it.
Disabled breakpoints are indicated by a red circle outline in the gray bar to the left of the code and a red outline around the code that contains the breakpoint.
Remove a breakpoint
1. Locate a line of code that has a breakpoint.
2. Remove the breakpoint by using one of the following steps:
a. If the breakpoint is enabled, click the solid red circle in the code to the left of the code to remove it.
b. Position the cursor on the line of code, and then press F9.
1-72 Programming in C# with Microsoft® .Visual Studio® 2010
c. Position the cursor on the line of code, and then, on the Debug menu, click Toggle Breakpoint.
d. Right-click the line of code, point to Breakpoint, and then click Delete Breakpoint.
e. Right-click the solid red circle in the gray bar to the left of the line of code, and then click Delete Breakpoint.
Question: How would you use the debug functions in Visual Studio 2010 to
debug your application and pause on a specific line of code?
Introducing C# and the .NET Framework 1-73
Stepping Through and Over Code
Key Points
You can step through code one statement at a time to see exactly how processing proceeds through your application. This is an extremely useful debugging technique because it enables you to test the logic that your application uses. Between statement executions, you can view and edit variable values. Each time your code reaches a branching statement such as a conditional statement, you can verify that the correct code executes and modify the code if it does not.
The various tools that you use to step through code enable you to step through code in exactly the way you want to. You can, for example, step through each line in each method that is executed, or you can ignore the statements inside a method that you know is working correctly. You can also skip over code completely, which prevents some statements from execution.
Step Into, Step Over, and Step Out
There are three debug functions that are essential for stepping through code. These are as follows:
1-74 Programming in C# with Microsoft® .Visual Studio® 2010
Step into. This function executes the statement at the current execution
position. If the statement is a method call, the current execution position will
move to the code inside the method. After you have stepped into a method,
you can continue executing statements inside the method one line at a time.
This also applies to properties. In addition, you can use the Step into function
to start an application in Debug mode. If you do this, the application will enter
break mode as soon as it starts.
Step over. As with Step into, the Step over function executes the statement at
the current execution position. However, this function does not step into code
inside a method or property. Instead, the code inside the method or property
is executed and the executing position moves to the statement after the
method call or property access. The exception to this is where the code for the
method or property contains a breakpoint. If this is the case, execution will
continue up to the breakpoint.
Step out. The Step out function enables you to execute the remaining code in
a method, property accessor, or loop. Execution will continue to the statement
that called the method or accessed the property, or to the statement following
the loop code. Execution will pause at this point.
Skipping Code
In break mode, the next statement to be executed is indicated by a yellow arrow in the gray bar to the left of the code and a yellow background for the statement. You can override this and set a different statement as the next one to execute. To do this, right-click the statement that you want to be executed next, and then click Set next statement. The arrow and yellow background will move to the statement that you have chosen.
If you use this technique, you should be aware that you will change the way in which your application works. If you skip important code such as variable assignments or critical method calls, you risk introducing errors that would not otherwise occur. You should skip statements with caution.
Continuing and Restarting
When you have finished stepping through your code, you can return to Debug mode with the start/continue functions. Execution will then continue until you
Introducing C# and the .NET Framework 1-75
enter break mode again, either with the Break all button or if the code encounters a breakpoint.
If you want to terminate the application and then run it again in Debug mode, you can use the Restart function. This is useful if you want to test the code that executes when an application first runs or any code that is only executed once when an application is used.
Question: Why would you use the Step into and Step over debug functions?
1-76 Programming in C# with Microsoft® .Visual Studio® 2010
Using the Debug Windows
Key Points
Visual Studio 2010 includes several windows that you can use to help debug your applications. These windows are available at run time, mostly in break mode.
The following table describes some of the commonly used debug windows in Visual Studio 2010.
Window Description
QuickWatch This is a modal window that enables you to evaluate variables and expressions. Type variable names or expressions in Expression, and then click Reevaluate to view the value and type of the variable or the result of the expression. Click Close to exit the QuickWatch window.
Locals This window enables you to view and edit local (in-scope) variables. You can expand variables, view members, and edit the contents of some variables in the Value column.
Introducing C# and the .NET Framework 1-77
Window Description
Immediate This window enables you to evaluate expressions, execute statements, and print out variable values. You can use this window to issue Visual Studio 2010 commands such as Debug.Print? to print the value of a variable or expression.
Output In this window, you can view error and information messages. One of the main uses of this window is to view traces from your applications by using the System.Diagnostics.Debug.WriteLine() method.
Memory This window enables you to examine and edit the contents of the memory that an application uses. This is an advanced function and can cause your application to behave unpredictably if you do not use this window carefully.
Call Stack This window enables you to view the stack of method calls that are used to reach the current code location. The current position is shown at the top of the window, and the series of calls that the application has processed to reach this location is shown below.
Modules This window enables you to view information about the modules (assemblies and executable files) that an application uses. Each module is listed along with its location, version, and other information.
Processes In this window, you can view information about the processes that the debugger is attached to.
Threads In this window, you can examine and control threads in an application.
Question: Why would you use the Locals and Immediate windows when
developing your application?
!""#$%&'%(")$*%+,-%.#$/0#1" !"#$%&'(' )
*+,,-.'(/'0,1.2'3#4' -.56-7,
2$%/3)"%1!""#$4%5#6%1!70$%/#%6"!%+,-%8#$/0#1"%9#0%+,-%7::1)87/)#$%;!<!1#:=!$/%7$;%3#>%/#%6"!%
)$;)<);671%8#$/0#1"4%)/!=%8#$/0#1"4%7$;%175#6/%8#$/0#1"4%!783%#9%>3)83%)"%$!8!""705%9#0%80!7/)$*%
+,-%7::1)87/)#$"?
!"#$%"&'(%)#((*+,%-*.%/'))%0#%10)#%"*2%
■ @A:17)$%>37/%7%8#$/!$/%8#$/0#1%)"?
■ B!"80)C!%7$;%6"!%"!<!071%8#==#$%+,-%8#$/0#1"?
■ ("!%7%;!:!$;!$85%:0#:!0/5?
■ .0!7/!%7$;%6"!%7$%)/!=%8#$/0#1%)$%5#60%6"!0%)$/!0978!?
■ .0!7/!%7%=!$6?
■ .0!7/!%7%/##1C70?
■ .0!7/!%7%"/7/6"%C70?
■ @A:17)$%/3!%:0#:!0/)!"%#9%7%8#$/0#1%/37/%=7$7*!%175#6/?
■ @A:17)$%3#>%/#%6"!%/3!% !"#%8#$/0#1?
■ @A:17)$%3#>%/#%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'>%8#$/0#1"4%?/%7%8#$/0#1"4%7$;%=!//@"/A%
8#$/0#1"?%G3!"!%8#$/0#1"%/5:)87115%!$7C1!%/3!%6"!0%/#%"!1!8/%7$%)/!=%90#=%7%1)"/%7$;%:!09#0=%7$%
!"#$%"&'(%)#((*+,%-*.%/'))%0#%10)#%"*2%
■ @A:17)$%>37/%7%8#$/!$/%8#$/0#1%)"?
■ B!"80)C!%7$;%6"!%"!<!071%8#==#$%+,-%8#$/0#1"?
■ ("!%7%;!:!$;!$85%:0#:!0/5?
■ .0!7/!%7$;%6"!%7$%)/!=%8#$/0#1%)$%5#60%6"!0%)$/!0978!?
■ .0!7/!%7%=!$6?
■ .0!7/!%7%/##1C70?
■ .0!7/!%7%"/7/6"%C70?
■ @A:17)$%/3!%:0#:!0/)!"%#9%7%8#$/0#1%/37/%=7$7*!%175#6/?
■ @A:17)$%3#>%/#%6"!%/3!% !"#%8#$/0#1? !"#
■ @A:17)$%3#>%/#%6"!%/3!%$%"&'!( !"#%8#$/0#1?$%"&'!( !"#
■ @A:17)$%3#>%/#%6"!%/3!%)*+,-.+%/0%8#$/0#1?)*+,-.+%/0
■ @A:17)$%3#>%/#%6"!%/3!%1!+2.+%/0%8#$/0#1?1!+2.+%/0
■ @A:17)$%3#>%/#%6"!%/3!%3',-.+%/0%8#$/0#1?3',-.+%/0
■ @A:17)$%3#>%/#%6"!%/3!%4+%5+6%8#$/0#1?
■ .#$D*60!%8#$/0#1%")E)$*?
■ F1)*$%8#$/!$/%7/%;!")*$%/)=!?
■ ("!%/3!% !"#)20"**/!%8#$/0#1? !"#)20"**/!
3("'41"#5%)#((*+%"'4#2%6%&*.$(
www.it-ebooks.info
' 8 !"#$%&'( K6)1;)$*%7%("!0%2$/!0978!
78/)#$%>)/3%/37/%)/!=?%2/!=%8#$/0#1"%87$%8#$/7)$%=61/):1!%$!"/!;%!1!=!$/"?%G3!"!%8#$/0#1"%70!%
;)"86""!;%17/!0%)$%/3)"%1!""#$?
-)$71154%0+B'7*8,'%*!'064%>3)83%8#$/7)$%=61/):1!%$!"/!;%8#$/0#1"%#9%7$5%/5:!4%:0#<);!%C6)1/H)$%
1#*)8%9#0%/3!%<)"671%175#6/%#9%/3#"!%8#$/0#1"?%@A7=:1!"%)$816;!% !"#4%)*+,-.+%/04%7$;%4+%5+6?%
G3!"!%8#$/0#1"%70!%71"#%;)"86""!;%17/!0%)$%/3)"%1!""#$?%
:*+"#+"%:*+"$*)(L7$5%#9%/3!%8#$/0#1"%5#6%6"!%/#%C6)1;%5#60%+,-%7::1)87/)#$%70!%8#$/!$/%8#$/0#1"?%M)=:154%7%
8#$/!$/%8#$/0#1%;!0)<!"%90#=%/3!%4'%*/%*4'%*!'0%817""%7$;%87$%8#$/7)$%7%")$*1!%$!"/!;%!1!H
=!$/?%G3)"%$!"/!;%!1!=!$/%87$%C!%#9%7$5%/5:!%7$;%87$%C!%"!/%#0%0!/0)!<!;%)$%8#;!%/30#6*3%/3!%
4'%*/%*%:0#:!0/5?%G3!%9#11#>)$*%NFL %!A7=:1!%;!=#$"/07/!"%"!//)$*%/3!%8#$/!$/%#9%7%:7**'%%
8#$/0#1%/#%7%"/0)$*%<716!%O"3#>$%)$%C#1;P'
<Button Height="23" Margin="36,0,84,15" Name="button2"
VerticalAlignment="Bottom">This is the content string</Button>
Q#6%71"#%87$%"!/%/3!%8#$/!$/%)$%8#;!4%7"%"3#>$%)$%/3!%9#11#>)$*%!A7=:1!'
=14>)#%*!%?'(.1)%@1('A%:*5#
Button2.Content = "This is the content string"
=14>)#%*!%:B%:*5#%
button2.Content = "This is the content string";
G3!%/5:!%#9%/3!%4'%*/%*%:0#:!0/5%)"%C<D/,*4%"#%)/%87$%788!:/%7$5%#CR!8/%7"%8#$/!$/?%S#>%
8#$/!$/%)"%0!$;!0!;4%3#>!<!04%;!:!$;"%#$%/3!%/5:!%#9%/3!%#CR!8/%)$%/3!%4'%*/%*%:0#:!0/5?%
-#0%)/!="%/37/%;#%$#/%;!0)<!%90#=%$EF0/(/%*4%/3!%=')*!"%G%=!/3#;%)"%8711!;4%7$;%/3!%0!"61/H
)$*%"/0)$*%)"%0!$;!0!;%7"%/3!%8#$/0#1%8#$/!$/?%2/!="%/37/%;!0)<!%90#=%$EF0/(/%*9%3#>!<!04%70!%
;)":175!;%7"%8#$/7)$!;%>)/3)$%/3!%8#$/!$/%8#$/0#1?%G3!%9#11#>)$*%!A7=:1!%8#;!%;!=#$"/07/!"%
3#>%/#%0!$;!0%7%C6//#$%/37/%37"%7$%)=7*!%7"%)/"%8#$/!$/'
<Button Margin="20,20,29,74" Name="button1">
<Image Source="C:\Pictures\HumpbackWhale.jpg"/>
</Button>
F""6=)$*%/37/%/3!%:7/3%/#%/3!%)=7*!%)"%<71);4%/3)"%8#;!%>)11%0!$;!0%7%C6//#$%/37/%;)":175"%7%
:)8/60!%D1!%#9%7%36=:C78I%>371!%$7=!;%S6=:C78I+371!?R:*?
T#/!%/37/%!<!$%/3#6*3%8#$/!$/%8#$/0#1"%87$%8#$/7)$%#$15%7%")$*1!%$!"/!;%!1!=!$/4%/3!0!%
)"%$#%)$3!0!$/%1)=)/%#$%/3!%$6=C!0%#9%$!"/!;%!1!=!$/"%/37/%/3!%8#$/!$/%87$%8#$/7)$?%-#0%
!A7=:1!4%)/%)"%:#"")C1!%9#0%7%8#$/!$/%8#$/0#1%/#%3#"/%7%175#6/%8#$/0#1%/37/%)/"!19%8#$/7)$"%"!<!071%
7;;)/)#$71%(2%!1!=!$/"?%G3!%9#11#>)$*%8#;!%"3#>"%7%")=:1!%!A7=:1!%#9%:7**'%%>)/3%7%$!"/!;%
)*+,-.+%/0%8#$/0#1%/37/%)/"!19%37"%$!"/!;%!1!=!$/"'
<Button Margin="20,20,-12,20" Name="button1">
<StackPanel>
<Image Source="C:\Pictures\HumpbackWhale.jpg"></Image>
<TextBlock>This is a Humpback Whale</TextBlock>
www.it-ebooks.info
% !""#$%&'%(")$*%+,-%.#$/0#1"% !"#$%&'(' 9
</StackPanel>
</Button>
F/%06$%/)=!4%/3)"%>)11%C!%0!$;!0!;%7"%7$%)=7*!%#9%7%36=:C78I%>371!%>)/3%/!A/%C!$!7/3%)/?
C10#)%:*+"$*)%1+5%D+#4*+'A%E#-(
G3!%;+</0%8#$/0#1%)"%#$!%#9%/3!%")=:1!"/%+,-%8#$/0#1"?%2/%)"%=#"/15%R6"/%7%8#$/7)$!0%9#0%8#$/!$/?%
G5:)871%6"7*!%9#0%7%;+</0%8#$/0#1%)"%7"%9#11#>"'
<Label Name="label1">This is a Label</Label>
7C!1"%8#$/7)$%C6)1/H)$%"6::#0/%9#0%=$!=#$)8%I!5"4%>3)83%=#<!%/3!%9#86"%/#%7%;!")*$7/!;%
8#$/0#1%>3!$%/3!%F1/%I!5%)"%:0!""!;%>)/3%/3!%=$!=#$)8%I!5?%-#0%!A7=:1!4%)9%U%>!0!%/3!%=$!H
=#$)8%I!5%9#0%7%:70/)86170%8#$/0#14%/3!%9#86"%>#61;%"3)9/%/#%/37/%8#$/0#1%>3!$%F1/VU%)"%:0!""!;?
G5:)871%6"7*!%9#0%=$!=#$)8%I!5"%)$%17C!1"%#8860"%>3!$%/3!%17C!1%;!")*$7/!"%7%8#$/0#1%
/37/%87$%0!8!)<!%/3!%9#86"4%"683%7"%=/>*:'>H%G3!%=$!=#$)8%I!5%)"%":!8)D!;%C5%:0!8!;)$*%/3!%
;!")0!;%I!5%>)/3%/3!%6$;!0"8#0!%OWP%"5=C#1%7$;%7::!70"%6$;!01)$!;%7/%06$%/)=!%>3!$%/3!%F1/%
I!5%)"%:0!""!;?%-#0%!A7=:1!4%/3!%9#11#>)$*%8#;!%7::!70"%7"%,0!""%F1/VF%7/%06$%/)=!%>3!$%5#6%
:0!""%/3!%F1/%I!5'
<Label>Press Alt+_A</Label>
F1/3#6*3%/3)"%8#;!%;!")*$7/!"%/3!%=$!=#$)8%I!5%9#0%/3!%17C!14%)/%37"%$#%!99!8/%6$1!""%5#6%
;!")*$7/!%7%/70*!/%8#$/0#1%7"%>!11?%Q#6%87$%;!")*$7/!%7%/70*!/%8#$/0#1%C5%"!//)$*%/3!%=+!G/*%
:0#:!0/5%#9%/3!%;+</0%8#$/0#1?%G3!%9#11#>)$*%!A7=:1!%;!=#$"/07/!"%3#>%/#%80!7/!%7%=$!=#$H
)8%I!5%>)/3%7%/70*!/%8#$/0#1%$7=!;%=/>*:'>IJ
<Label Target="{Binding ElementName=TextBox1}" Height="27"
HorizontalAlignment="Left" VerticalAlignment="Top" Width="51">_Name
</Label>
<TextBox Name="TextBox1" Margin="53,1,94,0" Height="26"
VerticalAlignment="Top">
</TextBox>
G3!%"5$/7A%!A!=:1)D!;%C5%XK)$;)$*%@1!=!$/T7=!YG!A/K#A&Z%>)11%C!%;)"86""!;%960/3!0%)$%
.37:/!0%[4%\+#0I)$*%>)/3%B7/7%K)$;)$*?]
!""#$%:*+"$*)
G3!%:7**'%%8#$/0#1%"3#61;%C!%97=)1)70%/#%=#"/%;!<!1#:!0"?%G3)"%8#$/0#1%)"%;!")*$!;%/#%C!%
81)8I!;%/#%!$7C1!%/3!%6"!0%/#%=7I!%7%83#)8!4%/#%81#"!%7%;)71#*%C#A4%#0%/#%:!09#0=%7$#/3!0%78H
/)#$?%Q#6%87$%!A!86/!%8#;!%C5%81)8I)$*%/3!%C6//#$%/#%37$;1!%/3!%40",-%!<!$/?%O-#0%)$9#0=7/)#$%
7C#6/%37$;1)$*%!<!$/"4%"!!%.37:/!0%^4%\+#0I)$*%>)/3%@<!$/"%7$;%.#==7$;"?]P
G3!8:7**'%%8#$/0#1%!A:#"!"%/>#%)=:#0/7$/%:0#:!0/)!"%6"!961%>3!$%C6)1;)$*%6"!0%)$/!0978!"'%
/3!%E63/&+70*%:0#:!0/5%7$;%/3!%E64+%,/0%:0#:!0/5?
G3!%E63/&+70*%:0#:!0/5%;!/!0=)$!"%>3!/3!0%7%:70/)86170%C6//#$%)"%8#$");!0!;%/3!%;!9761/%
C6//#$%9#0%/3!%6"!0%)$/!0978!?%+3!$%E63/&+70*%)"%"!/%/#%=!7/4%/3!%C6//#$_"%40",-%!<!$/%)"%07)"!;%
>3!$%5#6%:0!""%@$/!0?%M)=)170154%/3!%E64+%,/0%:0#:!0/5%;!/!0=)$!"%>3!/3!0%/3!%C6//#$%"3#61;%
www.it-ebooks.info
' : !"#$%&'( K6)1;)$*%7%("!0%2$/!0978!
C!%8#$");!0!;%7%4+%,/0%C6//#$?%+3!$%E64+%,/0%)"%"!/%/#%=!7/4%/3!%C6//#$_"%40",-%!<!$/%)"%07)"!;%
>3!$%@"8%)"%:0!""!;?
::3==%E3F=
K6//#$"%:0#<);!%"6::#0/%9#0%788!""%I!5"4%>3)83%70!%")=)170%/#%/3!%=$!=#$)8%I!5"%"6::#0/!;%
C5%17C!1"?%+3!$%7%1!//!0%)$%7%C6//#$_"%8#$/!$/%)"%:0!8!;!;%C5%7$%6$;!0"8#0!%"5=C#1%OWP4%/37/%
1!//!0%>)11%7::!70%6$;!01)$!;%>3!$%/3!%F1/%I!5%)"%:0!""!;4%7$;%/3!%C6//#$%>)11%C!%81)8I!;%>3!$%
/3!%6"!0%:0!""!"%F1/%7$;%/37/%I!5%/#*!/3!0?%-#0%!A7=:1!4%7""6=!%5#6%37<!%7%C6//#$%;!D$!;%7"%
9#11#>"'
<Button>_Click Me!</Button>
G3!%/!A/%)$%/3!%C6//#$%7::!70"%7"%\.1)8I%L!]%>3!$%F1/%)"%:0!""!;4%7$;%/3!%C6//#$%)"%81)8I!;%
>3!$%F1/V.%)"%:0!""!;?%29%=#0!%/37$%#$!%C6//#$%;!D$!"%/3!%"7=!%788!""%I!54%$!)/3!0%)"%78/)H
<7/!;%>3!$%/3!%788!""%I!5%8#=C)$7/)#$%)"%:0!""!;4%C6/%9#86"%71/!0$7/!"%C!/>!!$%/3!%C6//#$"%
/37/%;!D$!%/37/%I!5?
%&'%( )*%:;GHI;C
G3!%4K/,-<'>%8#$/0#1%78/67115%)$3!0)/"%90#=%/3!%:7**'%:+6/%817""%7$;%/5:)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?
("671154%711%L+#"':7**'%%8#$/0#1"%)$%7%")$*1!%8#$/7)$!0%70!%76/#=7/)87115%)$%/3!%"7=!%*0#6:?%
29%5#6%>7$/%/#%37<!%7%")$*1!%*0#6:%#9%/30!!%L+#"':7**'%%8#$/0#1"%)$%7%>)$;#>4%711%5#6%$!!;%
/#%;#%)"%7;;%/3!=%/#%5#60%>)$;#>J%/3!5%70!%76/#=7/)87115%*0#6:!;?%Q#6%87$%37<!%=61/):1!%
*0#6:"%)$%7%")$*1!%8#$/7)$!0%C5%"!//)$*%/3!% !'72M+(/%:0#:!0/5?%G3!%9#11#>)$*%!A7=:1!%
;!=#$"/07/!"%/>#%*0#6:"%#9%/>#%07;)#%C6//#$"%!783?
<RadioButton GroupName="Group1" Name="RadioButton1" Height="22"
VerticalAlignment="Top" Margin="15,10,0,0"
HorizontalAlignment="Left" Width="76">Button 1</RadioButton>
<RadioButton GroupName="Group1" Name="RadioButton2"
Margin="15,34,0,0" Height="22" VerticalAlignment="Top"
www.it-ebooks.info
!""#$%&'%(")$*%+,-%.#$/0#1" !"#$%&'(' ;
HorizontalAlignment="Left" Width="76">Button 2</RadioButton>
<RadioButton GroupName="Group2" Name="RadioButton3"
Margin="15,58,0,0" Height="21" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="76">Button 3</RadioButton>
<RadioButton GroupName="Group2" Name="RadioButton4"
Margin="15,85,0,0" Height="22" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="76">Button 4</RadioButton>
Q#6%71"#%87$%80!7/!%*0#6:"%#9%07;)#%C6//#$"%C5%>07::)$*%/3!=%)$%8#$/7)$!0"4%"683%7"%)$%/3!%
8#;!%"3#>$%3!0!'
<StackPanel Height="29" VerticalAlignment="Top">
<RadioButton Name="RadioButton1">Button 1</RadioButton>
<RadioButton Name="RadioButton2">Button 2</RadioButton>
</StackPanel>
<StackPanel Height="34" Margin="0,34,0,0" VerticalAlignment="Top">
<RadioButton Name="RadioButton3">Button 3</RadioButton>
<RadioButton Name="RadioButton4">Button 4</RadioButton>
</StackPanel>
!"#$%&'
J"%'(%'4>*$"1+"%"*%$#1)'K#%"&1"%#<#+%"&*.L&%1%A*+"#+"%A*+"$*)%A1+%&*("%*+)-%1%('+L)#%#)#4#+",%
"&#%#)#4#+"%"&1"%'"%&*("(%A1+%'"(#)!%&*("%A&')5%#)#4#+"(M%H&.(,%1%A*+"#+"%A*+"$*)%4'L&"%&*("%
1%L$'5,%/&'A&%'+%".$+%4'L&"%&*("%1%+.40#$%*!%*0N#A"(M
;"&#$%:*+"$*)(G3!0!%70!%#/3!0%8#$/0#1"%)$%/3!%+,-%"6)/!%/37/%70!%$#/%8#$/!$/%8#$/0#1"?%G3!5%;#%$#/%37<!%7%
4'%*/%*%:0#:!0/5%7$;%/5:)87115%70!%=#0!%1)=)/!;%)$%3#>%/3!5%;)":175%#0%=#0!%":!8)71)E!;%)$%
/!0="%#9%/3!%8#$/!$/%/3!5%;)":175?%-#0%!A7=:1!4%/3!%=/>*:0',-%8#$/0#1%;)":175"%/!A/4%7$;%/3!%
E(+G/%8#$/0#1%0!:0!"!$/"%7$%)=7*!?
023" 4#567:*+"$*)%
=/>*:0',-%)"%#$!%#9%/3!%")=:1!"/%+,-%!1!=!$/"?%2/%R6"/%0!:0!"!$/"%7$%70!7%#9%/!A/%/37/%7::!70"%
)$%7%>)$;#>?%G3!%9#11#>)$*%!A7=:1!%;!=#$"/07/!"%7%=/>*:0',-%8#$/0#1'%
<TextBlock>Here is some text</TextBlock>
29%5#6%>7$/%/#%837$*!%/3!%/!A/%)$%7%=/>*:0',-%8#$/0#1%)$%8#;!4%5#6%=6"/%"!/%/3!%M+(/%:0#:H
!0/5%#9%/3!%=/>*:0',-%8#$/0#1%"#%/37/%5#6%87$%0!9!0%/#%)/%)$%8#;!4%7"%"3#>$%3!0!'
<TextBlock Name="TextBlock1">Here is some text</TextBlock>
G3!$%5#6%87$%837$*!%/3!%/!A/%#0%7$5%#/3!0%:0#:!0/5%C5%0!9!00)$*%/#%)/%)$%/3!%8#;!4%7"%
"3#>$%3!0!'
=14>)#%*!%?'(.1)%@1('A%:*5#
TextBlock1.Text = "Here is the changed text"
www.it-ebooks.info
' < !"#$%&'( K6)1;)$*%7%("!0%2$/!0978!
=14>)#%*!%:B%:*5#
TextBlock1.Text = "Here is the changed text";
K5%;!9761/4%/3!%9#$/%#9%/3!%/!A/%)$%/3!%=/>*:0',-%!1!=!$/%>)11%C!%/3!%"7=!%7"%/3!%9#$/%#9%/3!%
>)$;#>?%29%5#6%>7$/%;)99!0!$/%9#$/%"!//)$*"%9#0%/3!%=/>*:0',-4%5#6%87$%"!/%9#$/H0!17/!;%:0#:!0H
/)!"4%7"%"3#>$%3!0!'
<TextBlock FontFamily="Batang" FontSize="12"
FontStyle="Italic" FontWeight="Bold"
FontStretch="Normal">Here is some text</TextBlock>
.89:2%:*+"$*)%
G3!%E(+G/%8#$/0#1%0!:0!"!$/"%7$%)=7*!?%G3!%83)!9%:0#:!0/5%#9%/3!%E(+G/%8#$/0#1%)"%/3!%)'7!,/%
:0#:!0/54%>3)83%/7I!"%7%)B6*/(H1"%#'A6H?/#"+HE(+G/)'7!,/%817""%)$%8#;!4%C6/4%>3!$%"!/%)$%
NFL 4%)/%87$%C!%"!/%7"%/3!%($)9#0=%U!"#608!%2;!$/)D!0%O(U2P%90#=%>3)83%/3!%)=7*!%)"%1#7;!;?%
-#0%!A7=:1!4%1##I%7/%/3!%9#11#>)$*%8#;!?
<Image Source="C:\Pictures\Humpbackwhale.jpg"/>
G3!%(U2%87$%C!%!)/3!0%7%1#871%;)"I%0!"#608!%#0%7%+!C%0!"#608!?
G3!%E(+G/H)*!/*,K%:0#:!0/5%;!/!0=)$!"%3#>%7$%)=7*!%)"%;)":175!;4%>3!/3!0%)/%)"%"3#>$%
7/%78/671%")E!%7$;%80#::!;%O)9%$!8!""705P%/#%D/%/3!%)=7*!%C#6$;"4%#0%>3!/3!0%)/%)"%"306$I%#0%
"/0!/83!;%/#%D/%/3!%C#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0/5?%Q#6%87$%6"!%7%=/>*:'>%8#$/0#1%"#1!15%9#0%/!A/%;)":175%C5%
"!//)$*%/3!%E6L/+#C%0B%:0#:!0/5%/#%G06!4%7"%"3#>$%)$%C#1;%3!0!'
<TextBox IsReadOnly="True" Height="93" Margin="16,14,97,0"
Name="TextBox1" VerticalAlignment="Top"/>
G3!%:0!8!;)$*%8#;!%;)"7C1!"%6"!0%)$:6/%9#0%/3!%=/>*:'>I%8#$/0#1?
F1/3#6*3%/3!%=/>*:'>%8#$/0#1%87$%C!%80!7/!;%7"%7%0!8/7$*1!%#9%7$5%")E!4%)/%)"%")$*1!H1)$!%
C5%;!9761/?%G#%!$7C1!%/!A/%>07::)$*%)$%7%=/>*:'>9%"!/%/3!%=/>*1!+22"%G8:0#:!0/5%/#%1!+29%7"%
"3#>$%)$%C#1;%3!0!'
<TextBox TextWrapping="Wrap" Height="93" Margin="16,14,97,0"
Name="TextBox1" VerticalAlignment="Top"/>
Q#6%87$%71"#%"!/%/3!%=/>*1!+22"%G8:0#:!0/5%/#%1!+21"*KC5/!O'A9%>3)83%711#>"%"#=!%
>#0;"%/#%#<!0c#>%/3!%!;*!"%#9%/3!%/!A/%C#A%)9%/3!%>07::)$*%71*#0)/3=%)"%6$7C1!%/#%C0!7I%/3!%
/!A/%)$%7$%7::0#:0)7/!%1#87/)#$?
G3!%=/>*:'>%8#$/0#1%)$816;!"%76/#=7/)8%"6::#0/%9#0%"80#11%C70"?%Q#6%87$%!$7C1!%<!0/)871%
"80#11%C70"%C5%"!//)$*%/3!%@/!*",+0),!'00:+!@"6"<"0"*B%:0#:!0/5%/#%P7*'%#0%@"6"<0/9%7"%"3#>$%)$%
C#1;%3!0!'
<TextBox VerticalScrollBarVisibility="Visible" Height="93"
Margin="16,14,97,0" Name="TextBox1" VerticalAlignment="Top"/>
M!//)$*%@/!*",+0),!'00:+!@"6"<"0"*B%/#%@"6"<0/%=7I!"%/3!%<!0/)871%"80#11%C70%<)")C1!%7/%711%/)=!"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%7;;!;%/#%#0%"6C/078/!;%90#=%/3!%@+07/%:0#:H
!0/5%>3!$%7%170*!%837$*!%)"%0!d6)0!;?
?+>"(7( G3!%?+>"(7(%<716!%9#0%/3!%.!'G!/66:+!%8#$/0#1?%+3!$%/3!%@+07/%
:0#:!0/5%!d671"%/3!%?+>"(7(%:0#:!0/54%/3!%.!'G!/66:+!%8#$/0#1%)"%
D11!;?
?"%"(7( G3!%?"%"(7(%<716!%9#0%/3!%.!'G!/66:+!%8#$/0#1?%+3!$%/3!%@+07/%
:0#:!0/5%!d671"%/3!%?"%"(7(%:0#:!0/54%/3!%.!'G!/66:+!%8#$/0#1%)"%
!=:/5?
C!"/%*+*"'% B!/!0=)$!"%>3!/3!0%/3!%:0#*0!""%C70%)"%"3#>$%3#0)E#$/7115%#0%
%<!0/)87115?
)(+004K+%G/ U!:0!"!$/"%/3!%7=#6$/%7;;!;%/#%#0%"6C/078/!;%90#=%/3!%@+07/%:0#:H
!0/5%>3!$%7%"=711%837$*!%)"%0!d6)0!;?
@+07/ G3!%b716!%;)":175!;%)$%/3!%.!'G!/66:+!%8#$/0#1?%G3!%b716!%>)11%71>75"%
C!%C!/>!!$%/3!%<716!"%#9%/3!%?"%"(7(%7$;%?+>"(7(%:0#:!0/)!"?
2$%8#;!4%5#6%87$%837$*!%/3!%.!'G!/66:+!%;)":175%C5%7;;)$*%/#%#0%"6C/078/)$*%90#=%/3!%
@+07/%:0#:!0/54%7"%"3#>$%3!0!'
=14>)#%*!%?'(.1)%@1('A%:*5#
' Adds 1 to the Value
ProgressBar1.Value += 1
=14>)#%*!%:B%:*5#
// Adds 1 to the Value
ProgressBar1.Value += 1;
>4?@2<%:*+"$*)%
G3!%)0"#/!%8#$/0#1%!$7C1!"%/3!%6"!0%/#%"!/%7%<716!%C5%*07CC)$*%7%*07:3)8%37$;1!4%#0%*K7(<9%
>)/3%/3!%=#6"!%7$;%=#<)$*%)/%71#$*%7%/078I?%G3)"%)"%#9/!$%6"!;%/#%8#$/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#9%>3)83%3#"/"%7%")$*1!%$!"/!;%!1!=!$/?%G3!%")=:1!"/%
>75%/#%:#:617/!%7%;"6*:'>%8#$/0#1%)"%C5%7;;)$*%)/!="%;)0!8/15%)$%NFL 4%7"%"3#>$%3!0!'
<ListBox Margin="19,0,0,36" Name="listBox1">
<ListBoxItem>This</ListBoxItem>
<ListBoxItem>Is</ListBoxItem>
<ListBoxItem>A</ListBoxItem>
<ListBoxItem>List</ListBoxItem>
</ListBox>
www.it-ebooks.info
% !""#$%&'%(")$*%+,-%.#$/0#1"% !"#$%&'(' ()
G3!8;"6*:'>%8#$/0#1%76/#=7/)87115%175"%#6/%)/"%8#$/!$/%)$%7%"/78I%7$;%7;;"%7%<!0/)871%"80#11%
C70%)9%/3!%1)"/%)"%1#$*!0%/37$%/3!%7<7)17C1!%":78!%)$%/3!%8#$/0#1?
K5%;!9761/4%/3!%;"6*:'>%8#$/0#1%!$7C1!"%5#6%/#%"!1!8/%7%")$*1!%)/!=?%Q#6%87$%0!/0)!<!%/3!%
)$;!A%#9%/3!%"!1!8/!;%)/!=%90#=%/3!%;"6*:'>H)/0/,*/#E%#/>%:0#:!0/54%#0%5#6%87$%0!/0)!<!%/3!%
"!1!8/!;%)/!=%)/"!19%/30#6*3%/3!%;"6*:'>H)/0/,*/#E*/(%:0#:!0/5?%G3!%;"6*:'>E*/(%8#$/0#1%71"#%
!A:#"!"%7$%E6)/0/,*/#%:0#:!0/5%/37/%)"%:#")/)<!%>3!$%/3!%)/!=%)"%"!1!8/!;?
Q#6%87$%"!/%/3!%)/0/,*"'%?'#/%:0#:!0/5%/#%!$7C1!%/3!%6"!0%/#%"!1!8/%=61/):1!%)/!="?%
G7C1!%&Hf%"3#>"%/3!%:#"")C1!%<716!"%9#0%/3!%)/0/,*"'%?'#/%:0#:!0/5?
$"=*%'(>8' b716!"%9#0%/3!%)/0/,*"'%?'#/%,0#:!0/5
?"*0% @%A &B#$BCD
)"%G0/ G3!%6"!0%87$%"!1!8/%#$15%#$!%)/!=%7/%7%/)=!?
?70*"20/ G3!%6"!0%87$%"!1!8/%=61/):1!%)/!="%>)/3#6/%3#1;)$*%;#>$%7%=#;)D!0%
I!5?%L#;)D!0%I!5"%37<!%$#%!99!8/?
F>*/%#/# G3!%6"!0%87$%"!1!8/%=61/):1!%8#$"!86/)<!%)/!="%>3)1!%3#1;)$*%;#>$%/3!%
M3)9/%I!5%#0%$#$8#$"!86/)<!%)/!="%C5%3#1;)$*%;#>$%/3!%./01%I!5%7$;%
81)8I)$*%/3!%)/!="?%
Q#6%87$%"!/%/3!%)/0/,*"'%?'#/%:0#:!0/5%)$%NFL %7"%"3#>$%3!0!'
<ListBox SelectionMode="Extended">
</ListBox>
+3!$%=61/):1!%)/!="%70!%"!1!8/!;4%5#6%87$%0!/0)!<!%/3!%"!1!8/!;%)/!="%/30#6*3%/3!%;"6*:'>H
)/0/,*/#E*/(6%:0#:!0/5?
F1/3#6*3%/3!%;"6*:'>%8#$/0#1%)"%6"!;%=#"/%8#==#$15%>)/3%;"6*:'>E*/(88#$/0#1"9%)/%87$%
;)":175%7%1)"/%#9%7$5%)/!=%/5:!"?%-#0%!A7=:1!4%5#6%=)*3/%>7$/%/#%80!7/!%7%1)"/%#9%4K/,-:'>%
8#$/0#1"?%Q#6%87$%788#=:1)"3%/3)"%C5%")=:15%7;;)$*%4K/,-:'>%8#$/0#1"%/#%/3!%;"6*:'>%8#$/0#14%
7"%"3#>$%3!0!'
<ListBox Name="listbox1" VerticalAlignment="Top">
<CheckBox Name="Chk1">Option 1</CheckBox>
<CheckBox Name="Chk2">Option 2</CheckBox>
<CheckBox Name="Chk3">Option 3</CheckBox>
<CheckBox Name="Chk4">Option 4</CheckBox>
</ListBox>
%#8B# #37:*+"$*)%G3!%4'(<':'>%8#$/0#1%>#0I"%<!05%")=)17015%/#%/3!%;"6*:'>%8#$/0#1?%2/%87$%8#$/7)$%7%1)"/%#9%)/!="4%
!783%#9%>3)83%87$%C!%7$%#CR!8/%#9%7$5%/5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4%1)I!%)$%7%/!A/%C#A?%G#%=7I!%/3!%4'(<':'>%8#$/0#1%!;)/7C1!4%5#6%=6"/%"!/%/3!%
%E6L/+#C%0B%:0#:!0/5%/#%N+06/%7$;%"!/%/3!%E6F#"*+<0/%:0#:!0/5%/#%=!7/?
Q#6%87$%#:!$%7$;%81#"!%/3!%4'(<':'>%8#$/0#1%:0#*07==7/)87115%C5%"!//)$*%/3!%
%E63!'23'A%C2/%%:0#:!0/5%/#%=!7/%O/#%#:!$%)/P%7$;%N+06/%O/#%81#"!%)/P?
0<22C?2D%:*+"$*)%1+5%0<22C?2D."28%:*+"$*)%=!//@"/A%)"%7%")=:1!%)/!=%8#$/0#1%/37/%)"%<!05%")=)170%/#%;"6*:'>%)$%)/"%)=:1!=!$/7/)#$4%C6/%
)$%:078/)8!4%)/%)"%d6)/!%;)99!0!$/?%G3!%:0)=705%:60:#"!%#9%/3!%=!//@"/A%8#$/0#1%)"%/#%3#"/%
%=!//@"/AE*/(%8#$/0#1"4%>3)83%!$7C1!%/3!%8#$"/068/)#$%#9%/0!!"%#9%8#$/!$/?%
G3!%=!//@"/AE*/(%8#$/0#1%)"%/3!%:0)=705%8#$/0#1%6"!;%/#%8#$"/068/%/0!!"?%2/%!A:#"!"%7%Q/+#/!%
:0#:!0/5%/37/%!$7C1!"%5#6%/#%"!/%/3!%/!A/%;)":175!;%)$%/3!%/0!!?%G3!%=!//@"/AE*/(%8#$/0#1%
)/"!19%71"#%3#"/"%7%1)"/%#9%)/!="?%G3!%1)"/%#9%)/!="%3#"/!;%)$%7%=!//@"/AE*/(%87$%C!%!A:7$;!;%#0%
8#117:"!;%C5%81)8I)$*%/3!%)8#$%/#%/3!%1!9/%#9%/3!%3!7;!0?%G3!%9#11#>)$*%NFL %;!=#$"/07/!"%7%
=!//@"/A%8#$/0#1%:#:617/!;%C5%7%/0!!%#9%)/!="?
<TreeView>
<TreeViewItem Header="Boy's Names">
<TreeViewItem Header="Jack"/>
<TreeViewItem Header="Jim"/>
<TreeViewItem Header="Mark"/>
<TreeViewItem Header="Ray"/>
</TreeViewItem>
<TreeViewItem Header="Girl's Names">
<TreeViewItem Header="Betty"/>
<TreeViewItem Header="Libby"/>
<TreeViewItem Header="Janet"/>
<TreeViewItem Header="Sandra"/>
</TreeViewItem>
</TreeView>
Q#6%87$%80!7/!%=!//@"/A%8#$/0#1"%/37/%37<!%8#$/0#1"%7"%/3!%/!0=)$71%$#;!"%R6"/%7"%!7")154%7"%
"3#>$%)$%/3)"%!A7=:1!'
<TreeView>
<TreeViewItem Header="Pizza Toppings">
<CheckBox Content="Pepperoni"/>
<CheckBox Content="Sausage"/>
<CheckBox Content="Mushroom"/>
<CheckBox Content="Tomato"/>
www.it-ebooks.info
% !""#$%&'%(")$*%+,-%.#$/0#1"% !"#$%&'(' (9
</TreeViewItem>
<TreeViewItem Header="Sandwich Items">
<CheckBox Content="Lettuce"/>
<CheckBox Content="Tomato"/>
<CheckBox Content="Mustard"/>
<CheckBox Content="Hot Peppers"/>
</TreeViewItem>
</TreeView>
Q#6%87$%#C/7)$%7%0!9!0!$8!%/#%/3!%"!1!8/!;%)/!=%)$%/3!%=!//@"/A%8#$/0#1%>)/3%/3!%=!//@"/AH
)/0/,*/#E*/(%:0#:!0/5?
D#+.(L!$6"%!$7C1!%5#6%/#%:0!"!$/%/3!%6"!0%>)/3%7%1)"/%#9%8#$/0#1"%/37/%70!%/5:)87115%7""#8)7/!;%>)/3%
8#==7$;"?%L!$6"%70!%;)":175!;%)$%3)!07083)871%1)"/"%#9%)/!="4%6"67115%*0#6:!;%)$/#%0!17/!;%
70!7"?%+,-%:0#<);!"%/>#%/5:!"%#9%=!$6%8#$/0#1"'%?/%74%>3)83%)"%;!")*$!;%/#%C!%<)")C1!%)$%/3!%
6"!0%)$/!0978!4%7$;%4'%*/>*?/%74%>3)83%)"%;!")*$!;%/#%96$8/)#$%7"%7%:#:H6:%=!$6%)$%8!0/7)$%
")/67/)#$"?
+3!0!7"%/3!%?/%7%8#$/0#1%87$%C!%:6/%7$5>3!0!%)$%/3!%6"!0%)$/!0978!4%)/%/5:)87115%)"%;#8I!;%
/#%/3!%/#:%#9%/3!%>)$;#>?%L!$6"%!A:#"!%7$%E6?+"%?/%7%:0#:!0/5?%+3!$%/3)"%:0#:!0/5%)"%=!7/4%
:0!"")$*%F1/%#0%-&g%876"!"%/3!%=!$6%/#%0!8!)<!%9#86"4%/3!0!C5%!$7C1)$*%8#==#$%+)$;#>"%
7::1)87/)#$%C!37<)#0?
F1/3#6*3%7%?/%788#$/0#1%87$%8#$/7)$%8#$/0#1"%#9%7$5%I)$;4%/3!%=''0<+!88#$/0#1%)"%C!//!0%
"6)/!;%9#0%:0!"!$/)$*%8#$/0#1"%/#%/3!%6"!0?%G3!%?/%788#$/0#1%)"%;!")*$!;%9#0%:0!"!$/)$*%1)"/"%#9%
?/%7E*/(88#$/0#1"H
E2$!."28%:*+"$*)%
G3!%?/%7E*/(%8#$/0#1%)"%/3!%=7)$%6$)/%6"!;%/#%C6)1;%=!$6"?%F%?/%7E*/(%8#$/0#1%0!:0!"!$/"%7%
81)8I7C1!%"!8/)#$%#9%/3!%=!$6%7$;%37"%7""#8)7/!;%/!A/?%?/%7E*/(%8#$/0#1"%70!%/3!="!1<!"%)/!=%
8#$/0#1"%7$;%87$%8#$/7)$%/3!)0%#>$%1)"/%#9%8#$/0#1"4%>3)83%/5:)87115%70!%71"#%?/%7E*/(88#$/0#1"?%
G3!%9#11#>)$*%NFL %!A7=:1!%;!=#$"/07/!"%7%")=:1!%=!$6'
<Menu Height="22" Name="menu1" VerticalAlignment="Top"
HorizontalAlignment="Left" Width="278">
<MenuItem Header="_File">
<MenuItem Header="Open"/>
<MenuItem Header="Close"/>
<MenuItem Header="Save" Command="ApplicationCommands.Save"/>
</MenuItem>
</Menu>
G3!%4'((+%#%:0#:!0/5%)$;)87/!"%/3!%8#==7$;%7""#8)7/!;%>)/3%/37/%=!$6%)/!=?%+3!$%
/3!%6"!0%81)8I"%/3!%=!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%"!:707/#0%C70%C!/>!!$%=!$6%)/!="%C5%6")$*%/3!%)/2+!+*'!%8#$/0#14%7"%"3#>$%
3!0!'
<MenuItem Header="Close"/>
<Separator/>
<MenuItem Header="Save" Command="ApplicationCommands.Save"/>
G3!%"!:707/#0%C70%7::!70"%7"%7%3#0)E#$/71%1)$!%C!/>!!$%=!$6%)/!="?
( )%$'*"+%&+ ) !"#$%! ' CD$&C*A'3B$!'A0=>B$%IA!
J"%'(%0#("%>$1A"'A#%+*"%"*%1(('L+%1%A*441+5%"*%E2$!."28%A*+"$*)(%"&1"%A*+"1'+%(.0O'"#4(M%
;"&#$/'(#,%"&#%A*441+5%'(%#P#A."#5%#<#$-%"'4#%"&#%.(#$%/1+"(%"*%<'#/%"&#%)'("%*!%(.0O
'"#4(M
www.it-ebooks.info
% !""#$%&'%(")$*%+,-%.#$/0#1"% !"#$%&'(' (;
%#$"23"E2$!%:*+"$*)%
($1)I!%?/%7%8#$/0#1"4%/3!%4'%*/>*?/%7%8#$/0#1%;#!"%$#/%37<!%7%DA!;%1#87/)#$%)$%/3!%6"!0%
)$/!0978!?%U7/3!04%)/%)"%7""#8)7/!;%>)/3%#/3!0%8#$/0#1"?%G#%80!7/!%7%4'%*/>*?/%7%8#$/0#1%9#0%7%
8#$/0#14%;!D$!%)/%)$%/3!%NFL %8#;!%9#0%/3!%4'%*!'0H4'%*/>*?/%7%:0#:!0/54%7"%"3#>$%)$%/3!%
9#11#>)$*%!A7=:1!%>)/3%7%;"6*:'>%8#$/0#1'
<ListBox Margin="77,123,81,39" Name="listBox1">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Cut" Command="ApplicationCommands.Cut"/>
<MenuItem Header="Copy" Command="ApplicationCommands.Copy"/>
<MenuItem Header="Paste" Command="ApplicationCommands.Paste"/>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
F9/!0%7%4'%*/>*?/%7%8#$/0#1%37"%C!!$%"!/%9#0%7%8#$/0#14%)/%)"%;)":175!;%>3!$!<!0%/3!%6"!0%
0)*3/H81)8I"%/3!%8#$/0#1%#0%:0!""!"%M3)9/V-&g%>3)1!%/3!%8#$/0#1%37"%/3!%9#86"?
F$#/3!0%8#==#$%"8!$70)#%9#0%7;;)$*%4'%*/>*?/%7%8#$/0#1"%/#%7%8#$/0#1%)"%/#%7;;%/3!=%
7"%7%0!"#608!%)$%/3!%1"%#'AHL/6'7!,/6%8#11!8/)#$?%U!"#608!"%70!%;)"86""!;%)$% !""#$%^%#9%/3)"%
837:/!04%\(")$*%U!"#608!"?]
0##4 9<%:*+"$*)% )I!%=!$6"4%/3!%=''0:+!%8#$/0#1%)"%;!")*$!;%/#%:0!"!$/%8#$/0#1"%/#%/3!%6"!0?%G3!%=''0:+!%
8#$/0#1%)"%);!7115%"6)/!;%/#%3#"/%8#$/0#1"%"683%7"%:7**'%4%4'(<':'>4%=/>*:'>4%4K/,-:'>4%7$;%
L+#"':7**'%?%G3!%=''0:+!%8#$/0#1%71"#%87$%6"!%/3!%)/2+!+*'!%8#$/0#1%;!"80)C!;%)$%/3!%:0!<)#6"%
"!8/)#$?
G##1C70"%76/#=7/)87115%#<!00);!%/3!%"/51!%#9%"#=!%#9%/3!%8#$/0#1"%/3!5%3#"/?%K6//#$"4%9#0%
!A7=:1!4%7::!70%c7/%>3!$%"3#>$%)$%7%/##1C70%7$;%70!%3)*31)*3/!;%)$%C16!%>3!$%/3!%=#6"!%)"%
#<!0%/3!%8#$/0#1?%G3)"%*)<!"%8#$/0#1"%)$%7%/##1C70%7%8#$")"/!$/%7::!707$8!%C5%;!9761/?
Q#6%7;;%)/!="%/#%/3!%=''0:+!%8#$/0#1%)$%/3!%"7=!%=7$$!0%7"%7$5%#/3!0%)/!=%8#$/0#1?%F$%
!A7=:1!%)"%"3#>$%3!0!'
<ToolBar Height="26" Margin="43,23,35,0" Name="toolBar1"
VerticalAlignment="Top">
<Button>Back</Button>
<Button>Forward</Button>
<TextBox Name="textbox1" Width="100"/>
</ToolBar>
0##4 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H8C5/!O'A?'#/%:0#:!0/5%"!/%/#%M/5/!%/37$%87$%C!%
;)":175!;%)$%/3!%":78!%711#//!;%/#%/3!%/##1C704%"#=!%8#$H
/0#1"%>)11%C!%86/%#99%7$;%6$7<7)17C1!%/#%/3!%6"!0?
G3!%9#11#>)$*%!A7=:1!%;!=#$"/07/!"%3#>%/#%"!/%/3!%G##1C70?i<!0c#>L#;!%:0#:!0/5'
<ToolBar Height="26" Margin="43,23,35,0" Name="toolBar1"
VerticalAlignment="Top">
<Button ToolBar.OverflowMode="Always">Back</Button>
</ToolBar>
0##4 9<0<9I%:)1((%
+,-%:0#<);!"%7%":!8)71%8#$/7)$!0%817""%9#0%=''0:+!%8#$/0#1"4%8711!;%=''0:+!=!+BH%=''0:+!=!+B%
!$7C1!"%/3!%6"!0%/#%0!")E!%#0%=#<!%=''0:+!88#$/0#1"%/37/%70!%8#$/7)$!;%)$%/3!%/075%7/%06$%/)=!?%
+3!$%=''0:+!%8#$/0#1"%70!%3#"/!;%)$%7%=''0:+!=!+B88#$/0#19%/3!%6"!0%87$%=#<!%/3!%=''0:+!%
8#$/0#1"%C5%*07CC)$*%/3!%37$;1!%#$%/3!%1!9/%");!%#9%/3!%/##1C70?%G3!%9#11#>)$*%!A7=:1!%;!=H
#$"/07/!"%/3!%=''0:+!=!+B%8#$/0#1?
<ToolBarTray Name="toolBarTray1" Height="65" VerticalAlignment="Top">
<ToolBar Name="toolBar1" Height="26" VerticalAlignment="Top">
<Button>Back</Button>
<Button>Forward</Button>
<Button>Stop</Button>
</ToolBar>
<ToolBar>
<TextBox Width="100"/>
<Button>Go</Button>
</ToolBar>
</ToolBarTray>
www.it-ebooks.info
!""#$%&'%(")$*%+,-%.#$/0#1" !"#$%&'(' (E
>"9"!= 9<%:*+"$*)%G3!%)*+*76:+!%8#$/0#1%)"%d6)/!%")=)170%/#%/3!%=''0:+!%8#$/0#1?%G3!%:0)=705%;)99!0!$8!%)"%)$%6"H
7*!?%)*+*76:+!%)"%6"!;%=#"/%8#==#$15%/#%3#"/%8#$/0#1"%/37/%8#$<!5%)$9#0=7/)#$4%"683%7"%;+</0%
7$;%.!'G!/66:+!%8#$/0#1"?% )I!%/3!%/##1C704%/3!%"/7/6"%C70%#<!00);!"%/3!%<)"671%"/51!%#9%=7$5%
#9%/3!%8#$/0#1"%)/%3#"/"4%C6/%)/%:0#<);!"%7%;)99!0!$/%7::!707$8!%7$;%C!37<)#0%/37$%/3!%/##1C70?%
G3!%9#11#>)$*%!A7=:1!%;!=#$"/07/!"%7%")=:1!%)*+*76:+!%8#$/0#1%>)/3%3#"/!;%8#$/0#1"?
<StatusBar Height="32" Name="statusBar1" VerticalAlignment="Bottom">
<Label>Application is Loading</Label>
<Separator/>
<ProgressBar Height="20" Width="100" IsIndeterminate="True"/>
</StatusBar>
JK1LM' N+LM
■% Q#(A$'0#%"&#%5'!!#$#+A#%0#"/##+%1%E2$!%A*+"$*)%1+5%1%%#$"23"E2$!%A*+"$*)M
JK1LM' N+LM'".,O+6
■% @*"&%E2$!%#)#4#+"(%1+5%%#$"23"E2$!%#)#4#+"(%1$#%)'("%A*+"$*)(%"&1"%&*("%
E2$!."28%#)#4#+"(M%H&#%>$'41$-%5'!!#$#+A#%0#"/##+%"%'(%"&1"%E2$!%#)#O
4#+"(%1$#%<'('0)#%#)#4#+"(%"&1"%1$#%>1$"%*!%"&#%<'(.1)%"$##%1+5%A1+%0#%&*("#5%
0-%A*+"#+"%A*+"$*)(M%%#$"23"E2$!%#)#4#+"(,%&*/#<#$,%&1<#%+*%5'$#A"%<'(.1)%
$#>$#(#+"1"'*+%1+5%1$#%155#5%"*%1+*"&#$%'+5'<'5.1)%A*+"$*)%0-%(#""'+L%"&#%
*"&#$%A*+"$*)R(%%#$"23"E2$!%>$*>#$"-M
C1-*."%:*+"$*)(+,-%#99!0"%6$:0!8!;!$/!;%"6::#0/%9#0%7%<70)!/5%#9%175#6/%"/51!"?%G3!%7;;)/)#$%#9%"!<!071%":!H
8)71)E!;%8#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(/%* k!/"%#0%"!/"%/3!%<!0/)871%71)*$=!$/%837078/!0)"/)8"%7:H
:1)!;%/#%/3)"%!1!=!$/%>3!$%)/%)"%8#=:#"!;%>)/3)$%7%:70H
!$/%!1!=!$/%"683%7"%7%175#6/%#0%)/!=%8#$/0#1?
@/!*",+04'%*/%*P0"G%(/%* k!/"%#0%"!/"%/3!%<!0/)871%71)*$=!$/%#9%/3!%8#$/0#1_"%
8#$/!$/?
1"#*K k!/"%#0%"!/"%/3!%>);/3%#9%/3!%8#$/0#1?%+3!$%"!/%/#%P7*'4%
#/3!0%175#6/%:0#:!0/)!"%;!/!0=)$!%/3!%>);/3?
F%9!>%#9%/3!"!%:0#:!0/)!"%70!%>#0/3%7%81#"!0%1##I?
E9<:?$%8$*>#$"-%
G3!%?+!G"%%:0#:!0/5%0!/60$"%7$%)$"/7$8!%#9%/3!%=K",-%/66%"/068/60!%/37/%;!"80)C!"%/3!%":78!%
C!/>!!$%/3!%!;*!"%#9%/3!%8#$/0#1%7$;%#/3!0%!1!=!$/"%/37/%70!%7;R78!$/?%B!:!$;)$*%#$%>3)83%
175#6/%:7$!1%)"%6"!;4%/3!%7;R78!$/%!1!=!$/%=)*3/%C!%/3!%!;*!%#9%/3!%8#$/7)$!04%"683%7"%7%:7$!1%
#0%k0);%8!114%#0%)/%=)*3/%C!%7%:!!0%8#$/0#14%7"%>#61;%C!%/3!%87"!%)$%/3!%<!0/)871%=70*)$"%)$%7%
)*+,-.+%/0%8#$/0#1H%
www.it-ebooks.info
!""#$%&'%(")$*%+,-%.#$/0#1" !"#$%&'(' G(
G3!%?+!G"%%:0#:!0/5%87$%C!%"!/%7"5==!/0)87115%/#%711#>%;)99!0!$/%7=#6$/"%#9%=70*)$%#$%
!783%");!?%.#$");!0%/3!%9#11#>)$*%!A7=:1!'
<Button Margin="0,48,96,1" Name="button1">Button</Button>
2$%/3)"%!A7=:1!4%7%;)99!0!$/%=70*)$%;)"/7$8!%)"%"!/%9#0%!783%8#$/0#1%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%G3!% !"#%8#$/0#1%7/H
/783!"%7%$6=C!0%#9%:0#:!0/)!"%/#%!<!05%8#$/0#1%)/%8#$/7)$"4%"683%7"%:0#:!0/)!"%/37/%;!/!0=)$!%
/3!%0#>%7$;%8#16=$%)$%>3)83%/3!%8#$/0#1%!A)"/"?%2$%NFL 4%5#6%"!/%7$%7//783!;%:0#:!0/5%>)/3%
8#;!%1)I!%/3!%9#11#>)$*'
<Button Grid.Row="1" Grid.Column="1"></Button>
U!9!0%/#%/3!%817""%$7=!%O/37/%)"4% !"#P%07/3!0%/37$%/#%/3!%)$"/7$8!%$7=!%O9#0%!A7=:1!4%*0);&P%
>3!$%"!//)$*%7$%7//783!;%:0#:!0/5%C!876"!%7//783!;%:0#:!0/)!"%70!%7//783!;%C5%/3!%817""%7$;%
,-% 3!%D'$!%&%'BA'DC'%44% $
J+%(*4#%A*+"1'+#$(,%(#""'+L%"&#(#%>$*>#$"'#(%4'L&"%&1<#%+*%#!!#A"M%9*$%#P14>)#,%'+%
>"956;9$24,%"&#%<#$"'A1)%)1-*."%'(%&1+5)#5%0-%"&#%A*+"1'+#$,%(*%(#""'+L%"&#%24 C2<"?594,4?:$82$"
>$*>#$"-%&1(%+*%#!!#A",%1)"&*.L&%(#""'+L%"&#%&#<?J#$"94,4?:$82$"%>$*>#$"-%("'))%5*#(M"
www.it-ebooks.info
'GG !"#$%&'( K6)1;)$*%7%("!0%2$/!0978!
$#/%C5%/3!%)$"/7$8!%#9%/3!%817""?%2$%"#=!%87"!"4%"683%7"%>)/3%/3!%=+<E%#/>%:0#:!0/5%O"3#>$%)$%
/3!%$!A/%"!8/)#$P4%/3!%817""%$7=!%)"%7""6=!;%7$;%87$%C!%#=)//!;%)$%NFL ?
S!0!_"%7%9611%!A7=:1!%#9%7% !"#%8#$/0#1%/37/%;!D$!"%/>#%0#>"%7$;%/>#%8#16=$"%7$;%8#$/7)$"%
7%")$*1!%C6//#$%/37/%6"!"%7//783!;%:0#:!0/)!"%/#%#0)!$/%)/"!19%)$%/3!%*0);'
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="139*"/>
<ColumnDefinition Width="139*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="126*"/>
<RowDefinition Height="126*"/>
</Grid.RowDefinitions>
<Button Grid.Row="1" Grid.Column="1"></Button>
</Grid>
C1-*."%81+#)(+,-%)$816;!"%7%<70)!/5%#9%175#6/%:7$!1"%>)/3%>3)83%/#%;!")*$%5#60%6"!0%)$/!0978!?%G3)"%"!8/)#$%
!A:1#0!"%/3!"!%:7$!1"%7$;%!A:17)$"%>3!$%/#%6"!%/3!=?
K<?@%81+#)%
!"#%)"%/3!%=#"/%8#==#$15%6"!;%:7$!1%9#0%80!7/)$*%6"!0%)$/!0978!"%)$%+,-?%G3!% !"#%:7$!1%
!$7C1!"%5#6%/#%80!7/!%175#6/"%/37/%;!:!$;%#$%/3!%?+!G"%4%Q'!"R'%*+0P0"G%(/%*4%7$;%
%@/!*",+0P0"G%(/%*%:0#:!0/)!"%#9%/3!%83)1;%8#$/0#1"%)/%8#$/7)$"?%.#$/0#1"%3#"/!;%)$%7% !"#%8#$/0#1%
70!%;07>$%)$%/3!%#0;!0%)$%>3)83%/3!5%7::!70%)$%=70I6:%#0%8#;!4%/3!0!C5%!$7C1)$*%5#6%/#%80!H
7/!%175!0!;%6"!0%)$/!0978!"?%2$%/3!%87"!%#9%#<!017::)$*%8#$/0#1"4%/3!%17"/%8#$/0#1%/#%C!%;07>$%
>)11%C!%#$%/#:?%
+)/3%/3!% !"#%8#$/0#14%5#6%87$%;!D$!%8#16=$"%7$;%0#>"%)$%/3!%*0);?%G3!$%5#6%87$%7"")*$%
83)1;%8#$/0#1"%/#%;!")*$7/!;%0#>"%7$;%8#16=$"%/#%80!7/!%7%=#0!%"/068/60!;%175#6/?%+3!$%
7"")*$!;%/#%7%8#16=$%#0%0#>4%7%8#$/0#1_"%?+!G"%4%Q'!"R'%*+0P0"G%(/%*4%7$;%%@/!*",+0P0"G%(/%*%
:0#:!0/)!"%#:!07/!%>)/3%0!":!8/%/#%/3!%!;*!%#9%/3!%0#>%#0%8#16=$4%$#/%/#%/3!%!;*!%#9%/3!%
!"#%8#$/7)$!0%)/"!19?%.#16=$"%7$;%0#>"%70!%;!D$!;%C5%80!7/)$*%4'07(%3/U%"*"'%%7$;%
%L'A3/U%"*"'%%:0#:!0/)!"4%7"%"!!$%3!0!'
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="125*"/>
<RowDefinition Height="125*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="120*"/>
</Grid.ColumnDefinitions>
</Grid>
www.it-ebooks.info
% !""#$%&'%(")$*%+,-%.#$/0#1"% !"#$%&'(' G)
U#>"%7$;%8#16=$"%87$%C!%!)/3!0%DA!;%#0%<70)7C1!%)$%/3!)0%>);/3%7$;%3!)*3/?%G#%;!")*$7/!%
7%DA!;%>);/3%#0%3!)*3/4%")=:15%"!/%/3!%1"#*K%#0%Q/"GK*%:0#:!0/5%/#%/3!%")E!%5#6%>#61;%1)I!4%7"%
"3#>$%3!0!'
<RowDefinition Height="125"/>
2$%8#$/07"/4%5#6%87$%=7I!%7%<70)7C1!H")E!;%0#>%#0%8#16=$%C5%7::!$;)$*%7$%7"/!0)"I%OnP%/#%
/3!%!$;%#9%/3!%1"#*K%#0%Q/"GK*%"!//)$*4%7"%"3#>$%3!0!'
<RowDefinition Height="125*"/>
+3!$%/3!%7"/!0)"I%)"%7;;!;4%/3!%0#>%#0%8#16=$%*0#>"%#0%"30)$I"%:0#:#0/)#$7115%/#%D/%/3!%
7<7)17C1!%":78!?% ##I%7/%/3!%9#11#>)$*%!A7=:1!'
<RowDefinition Height="10*"/>
<RowDefinition Height="20*"/>
K#/3%/3!%0#>"%80!7/!;%C5%/3)"%8#;!%*0#>%7$;%"30)$I%/#%D/%/3!%7<7)17C1!%":78!4%C6/%#$!%0#>%
)"%71>75"%/>)8!%/3!%3!)*3/%#9%/3!%#/3!0?%G3!"!%$6=C!0"%70!%:0#:#0/)#$71%#$15%7=#$*%/3!=H
"!1<!"?%G36"4%6")$*%&n%7$;%^n%>)11%37<!%/3!%"7=!%!99!8/%7"%6")$*%&ggn%7$;%^ggn?
Q#6%87$%37<!%7% !"#%8#$/0#1%/37/%8#$/7)$"%C#/3%DA!;%7$;%<70)7C1!%0#>"%#0%8#16=$"4%7"%"!!$%
3!0!'
<RowDefinition Height="125"/>
<RowDefinition Height="125*"/>
2$%/3)"%!A7=:1!4%/3!%D0"/%0#>%71>75"%=7)$/7)$"%7%3!)*3/%#9%&^h4%7$;%/3!%"!8#$;%*0#>"%#0%
"30)$I"%7"%/3!%>)$;#>%)"%0!")E!;?
K+.-% HH :T3Q%8I;83IHJ3=
!"# !"#$$%&'(%)#*(%+,-".#/''/$!"-#*(%*"(',".#'%#,'.#$!,)-#$%&'(%).0#1%2#$/&#*%.,',%&#$%&'(%).#
,&'%#.*"$,3$# !"#$(%4.#%(#$%)25&.$67#."'',&8#'!"#/''/$!"-#*(%*"(',".# !"#%&'()*+#/&-# !"#%
,'-.#/.#.!%4&#,%)-#!"("9
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="5*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="117"/>
<ColumnDefinition Width="161"/>
</Grid.ColumnDefinitions>
<Button Name="button2" Grid.Row="0" Grid.Column="1">Button</Button>
</Grid>
:$$/.,%&/))7;#7%2#5,8!'#!/+"#/#$%&'(%)#'!/'#.*/&.#5%("#'!/&#%&"#$%)25&#%(#(%40# %#,&-,<
$/'"#'!,.;#7%2#$/&#."'#'!"# !"#%&'()*+/01+#%(# !"#%,'-/01+#*(%*"('7#/.#.!%4&#!"("9
<Button Name="button2" Grid.ColumnSpan="2">Button</Button>
www.it-ebooks.info
!" #$%&'() * =2,)-,&8#/#>."(#?&'"(@/$"
!"#$%&'(%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!"##
$%&'(%)0#?&#@/$';#'!"#F+"D'!* !"##$%&'(%)#,.#+"(7#),5,'"-0#?'#/2'%5/',$/))7#)/7.#%2'#$%&'(%).#,&#/#
8(,-#%@#2&,@%(5#.,A";#/-B2.',&8#'!"#.,A"#/&-#&256"(#%@#(%4.#/&-#$%)25&.#/.#5%("#$%&'(%).#/("#
/--"-0#N(,-#$")).#/("#/)4/7.#'!"#./5"#.,A"0# !"#F+"D'!* !"##$%&'(%)#'7*,$/))7#,.#&%'#2."-#@%(#
-".,8&,&8#"&',("#2."(#,&'"(@/$".;#62'#,'#$/"#2."@2)#@%(#I2,$L)7#$("/',&8#)/7%2'.#'!/'#("I2,("#/#
8(,-#%@#2&,@%(5#.,A";#.2$!#/.#/#$!"$L"(6%/(-#%(#'!"#62''%&.#%&#/#$/)$2)/'%(0
1%2#$/&#."'#'!"#&256"(#%@#(%4.#/&-#$%)25&.#,&#'!"#F+"D'!* !"##$%&'(%)#67#."'',&8#'!"#
,'-=#/&-#&'()*+=#*(%*"(',".;#/.#.!%4&#!"("9
<UniformGrid Rows="2" Columns="2">
</UniformGrid>
?@#7%2#."'#'!"#&256"(#%@#(%4.#/&-#$%)25&.#,&#'!,.#5/&&"(;#7%2#3G#'!"#&256"(#%@#$")).#O/&-#
'!2.#'!"#$%&'(%).#'!/'#$/"#-,.*)/7"-P#,&#/#.,&8)"#2&,@%(5#8(,-0#?@#7%2#/--#5%("#$%&'(%).#
'!/&#/#2&,@%(5#8(,-#!/.#$")).;#'!"#$%&'(%).#4,))#&%'#6"#-,.*)/7"-0#F")).#-"3&"-#3(.'#,&#XSUQ#/("#
'!"#$")).#-,.*)/7"-#,&#.2$!#/#$/."0
?@#7%2#."'#%&)7#'!"#&256"(#%@#(%4.;#/--,',%&/)#$%)25&.#4,))#6"#/--"-#'%#/$$%55%-/'"#&"4#
$%&'(%).0#Q,L"4,.";#,@#7%2#."'#%&)7#'!"#&256"(#%@#$%)25&.;#/--,',%&/)#(%4.#4,))#6"#/--"-0
$1234%2*56%)-./0-1%
!"#/219GA1+3(#$%&'(%)#*(%+,-".#/#.,5*)"#)/7%2'#5%-")0#?'#.'/$L.#'!"#$%&'(%).#,'#$%&'/,&.#%&"#
%&#'%*#%@#'!"#%'!"(#,&#'!"#%(-"(#'!/'#'!"7#/("#-"3&"-0# 7*,$/))7;#/219GA1+3(#$%&'/,&"(.#.'/$L#
$%&'(%).#+"(',$/))70#1%2#$/&#/).%#$("/'"#/#!%(,A%&'/)#.'/$L#67#."'',&8#'!"#?!"3+212"'+#*(%*"('7#
'%#V%(,A%&'/);#/.#.!%4&#!"("9
<StackPanel Orientation="Horizontal">
</StackPanel>
www.it-ebooks.info
# Q"..%&#C9#>.,&8#REH#F%&'(%).# #$%&'() * !;
!,.#$("/'".#/#.'/$L#%@#$%&'(%).#@(%5#)"@'#'%#(,8!'0#?@#7%2#4/&'#'%#$("/'"#/#(,8!'<'%<)"@'#.'/$L#
%@#$%&'(%).;#7%2#$/&#."'#'!"#H('-@"!392"'+#*(%*"('7#'%#,"562:'C3D2;#/.#.!%4&#!"("9
<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
</StackPanel>
W%#$%56,&/',%&#%@#*(%*"('7#."'',&8.#,&#'!"#.'/$L#*/&")#$("/'".#/#6%''%5<'%<'%*#.'/$L0
W%'"#'!/'#'!"#)/7%2'#*(%*"(',".#%@#'!"#$%&'(%).#$%&'/,&"-#,&#'!"#/219GA1+3(#$%&'(%)#/).%#
,&M2"&$"#!%4#'!"#.'/$L#/**"/(.0#H%(#"G/5*)";#$%&'(%).#/**"/(#,&#'!"#$"&'"(#%@#'!"#/219GA1+3($
67#-"@/2)';#62'#,@#'!"#4'!"8'+21(7("5+*3+2#*(%*"('7#%@#/#.*"$,3$#$%&'(%)#,.#."'#/'#C3D2;#'!/'#
$%&'(%)#/**"/(.#%&#'!"#)"@'#.,-"#%@#'!"#/219GA1+3(%#
7.28%2*56%)-./0-1%
!"#E!10A1+3(#$%&'(%)#*(%+,-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%).#4,'!#/#!,8!"(#&1+>1=%IJ+#3K#+/)2"#/)4/7.#/**"/(#%&#'%*#%@#$%&'(%).#4,'!#/#
)%4"(#F/&+/.0^?&-"G#+/)2"0#S&#"G/5*)"#,.#.!%4&#!"("9
<Button Canvas.ZIndex="12">This one is on top</Button>
<Button Canvas.ZIndex="5">This one is on the bottom</Button>
www.it-ebooks.info
Q"..%&#C9#>.,&8#REH#F%&'(%). #$%&'() * <*
>?@AB #CDAB
■# 23450673%89:/%://:593;%<0-<30/634%:03%:.;%9-8%/93=%8-0>?
>?@AB #CDAB %EFGDH
■# @//:593;%<0-<30/634%:03%<0-<30/634%/9:/%:%5-./:6.6.A%313B3./C%4D59%:4%:%
1:=-D/%5-./0-1C%://:5934%/-%:%5-./:6.3;%313B3./%4D59%:4%:%5-./3./%5-./0-1?%
E0-<30/634%:03%43/%7=%/93%5-./:6.3;%313B3./%7D/%/=<65:11=%:FF35/%9-8%/9:/%
313B3./%64%03.;303;%-0%1:6;%-D/%6.%/93%5-./:6.6.A%313B3./?%@.%3G:B<13%64%/93%
.+0=!->%://:593;%<0-<30/=C%89659%64%://:593;%/-%:11%313B3./4%5-./:6.3;%7=%:%
.+0%313B3./?%H=%43//6.A%/93% .+0=!->%<0-<30/=%-.%:%5-./:6.3;%313B3./C%=-D%
43/%89:/%0-8%-F%/93%A06;%/9:/%313B3./%64%03.;303;%6.?
@553446.A%)961;%(13B3./4%E0-A0:BB:/65:11=Q/7%2'#$%&'(%).#"G*%."#/#&6"(#!3+#$%))"$',%&#'!/'#"&/6)".#7%2#'%#/$$"..#'!"#$!,)-#$%&'(%).#*(%<
8(/55/',$/))70#1%2#$/&#%6'/,&#/#("@"("&$"#'%#/#$!,)-#")"5"&'#67#'!"#,&-"G;#/.#.!%4&#!"("9
!:B<13%-F%I64D:1%H:465%)-;3
Dim aButton As Button
aButton = CType(grid1.Children(3), Button)
!:B<13%-F%)J%)-;3
Button aButton;
aButton = (Button)grid1.Children[3];
1%2#$/&#/--#/#$%&'(%)#*(%8(/55/',$/))7#67#2.,&8#'!"#&6"(#!3+%7###5"'!%-;#/.#.!%4&#!"("9
!:B<13%-F%I64D:1%H:465%)-;3
Dim aButton As New Button()
grid1.Children.Add(aButton)
!:B<13%-F%)J%)-;3
Button aButton = new Button();
grid1.Children.Add(aButton);
T,5,)/()7;#7%2#$/&#("5%+"#/#$%&'(%)#*(%8(/55/',$/))7#4,'!#'!"#&6"(#!3+%,3*'>3#5"'!%-9
!:B<13%-F%I64D:1%H:465%)-;3K
grid1.Children.Remove(aButton)
!:B<13%-F%)J%)-;3
grid1.Children.Remove(aButton);
S&-#7%2#$/&#("5%+"#/#$%&'(%)#/'#/#.*"$,3"-#,&-"G#67#2.,&8#'!"#,3*'>372$5"'!%-;#/.#
.!%4&#!"("9
!:B<13%-F%I64D:1%H:465%)-;3
grid1.Children.RemoveAt(3)
>?@AB #CDAB
■ 23450673%89:/%://:593;%<0-<30/634%:03%:.;%9-8%/93=%8-0>?
>?@AB #CDAB %EFGDH
■ @//:593;%<0-<30/634%:03%<0-<30/634%/9:/%:%5-./:6.6.A%313B3./C%4D59%:4%:%
1:=-D/%5-./0-1C%://:5934%/-%:%5-./:6.3;%313B3./%4D59%:4%:%5-./3./%5-./0-1?%
E0-<30/634%:03%43/%7=%/93%5-./:6.3;%313B3./%7D/%/=<65:11=%:FF35/%9-8%/9:/%
313B3./%64%03.;303;%-0%1:6;%-D/%6.%/93%5-./:6.6.A%313B3./?%@.%3G:B<13%64%/93%
.+0=!->%://:593;%<0-<30/=C%89659%64%://:593;%/-%:11%313B3./4%5-./:6.3;%7=%:% .+0=!->
.+0%313B3./?%H=%43//6.A%/93% .+0 .+0=!->%<0-<30/=%-.%:%5-./:6.3;%313B3./C%=-D% .+0=!->
43/%89:/%0-8%-F%/93%A06;%/9:/%313B3./%64%03.;303;%6.?
www.it-ebooks.info
<! #$%&'() * =2,)-,&8#/#>."(#?&'"(@/$"
!:B<13%-F%)J%)-;3
grid1.Children.RemoveAt(3);
@16A.6.A%)-./3./H("I2"&')7;#7%2#4/&'#'%#/),8&#'!"#$%&'"&'#$%&'/,&"-#,&#-,@@"("&'#$%&'(%).#/.#4"))#/.#'!"#"-8".#
%@#'!"#$%&'(%).#'!"5.")+".0#1%2#$/&#/),8&#$%&'(%)#"-8".#/&-#$%&'"&'#/'#-".,8&#',5"#67#2.,&8#
.&/*),&".0
/+10("+3=#/("#+,.2/)#/,-.#,&#'!"#_,.2/)#T'2-,%#?&'"8(/'"-#J"+")%*5"&'#`&+,(%&5"&'#O?J`P#
'!/'#*(%+,-"#@""-6/$L#'%#'!"#-"+")%*"(#4!"&#$%&'(%)#"-8".#/("#/),8&"-#%(#4!"&#$%&'(%)#
$%&'"&'#,.#/),8&"-0#R!"%2#*%.,',%&#$%&'(%).#5/&2/))7#4,'!#'!"#5%2."#,&#'!"#-".,8&"(;#
.&/*),&".#/**"/(#4!"&#'!"#!%(,A%&'/)#%(#+"(',$/)#"-8".#%@#'!"#$%&'(%)#/("#,&#/),8&5"&';#/.#
.!%4&#,&#H,82(".#C<a#/&-#C<D0#
6378)( *-; V%(,A%&'/)#.&/*),&".0
6378)( *-. _"(',$/)#.&/*),&".0
www.it-ebooks.info
# Q"..%&#C9#>.,&8#REH#F%&'(%).# #$%&'() * <<
T&/*),&".#/).%#,&-,$/'"#4!"&#$%&'"&'#,.#/),8&"-;#"&/6),&8#7%2#'%#/),8&#$%&'"&'#/$(%..#52)<
',*)"#$%&'(%).0#H,82("#C<b#.!%4.#/&#"G/5*)"#%@#$%&'"&'#.&/*),&".0
6378)( *-= F%&'"&'#.&/*),&".0
'()*+,*- #HDIJ@EK I 2@LMND %MMN@AIJ@OE
?&#'!,.#*(/$',$";#7%2#$("/'"#/#.,5*)"#/**),$/',%&#'%#$!/&8"#'!"#@%&'#%@#'"G'#,&#/#,"96:3K2;'K#
$%&'(%)#67#2.,&8#$%&'(%).#,&#/#'%%)6/(0
-.-(*,/- 46.A%,:=-D/%)-./0-14
!"# ?&#_,.2/)#T'2-,%;#$("/'"#/#&"4#REH#/**),$/',%&0
#"# ?&#XSUQ#+,"4;#$!/&8"#'!"# !"##%*"&,&8#/&-#$)%.,&8#'/8.#'%#6"#@'9GA1+3(#'/8.;#/.#
.!%4&#!"("9
<DockPanel>
</DockPanel>
$"# H(%5#'!"#'%%)6%G;#-(/8#/#:''(;1!#$%&'(%)#%&'%#'!"#4,&-%40#S--#/#@2))<)"&8'!#$)%.,&8#
'/8#/&-#."'#'!"#@'9GA1+3(%@'9G#*(%*"('7#'%#:'0;#/.#.!%4&#!"("9
<ToolBar DockPanel.Dock="Top" Height="26" Name="toolBar1" Width="276">
</ToolBar>
`+"&#'!%28!#7%2#!/+"#."'#'!"#@'9GA1+3(%@'9G#*(%*"('7#'%#:'0;#'!"#'%%)6/(#("5/,&.#,&#
'!"#$"&'"(#%@#'!"#4,&-%4#6"$/2."#'!"#@'9GA1+3(%C1=2&6"(#H"((#*(%*"('7#,.#."'#'%#:!)3#67#
-"@/2)';#/&-#'!,.#."'',&8#%+"((,-".#'!"#@'9GA1+3(%@'9G#*(%*"('70
%"# ?&#XSUQ#+,"4;#2."#'!"#@%))%4,&8#XSUQ#'%#/--#/# !"##$%&'/,&"(#'%#'!"#@'9GA1+3(#
#$%&'(%)L#
<Grid Name="grid1">
</Grid>
!"#'%%)6/(#&%4#,.#/'#'!"#'%*#%@#'!"#@'9GA1+3(#$%&'(%)%
www.it-ebooks.info
<" #$%&'() * =2,)-,&8#/#>."(#?&'"(@/$"
&"# ?&#XSUQ#+,"4;#/--#'!"#@%))%4,&8#&'()*+@3M+"2"'+$")"5"&'.#'%#'!"# !"##$%&'(%)9
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
0"# ?&#XSUQ#+,"4;#2."#'!"#@%))%4,&8#XSUQ#'%#/--#/#C"=2;'K#$%&'(%)#'%#'!"#3(.'#$%)25&9
<ListBox Grid.Column="0" Name="listBox1"></ListBox>
1"# ?&#XSUQ#+,"4;#2."#'!"#@%))%4,&8#XSUQ#'%#/--#/# !"#/0("223!#$%&'(%)#'%#'!"#."$%&-#
#$%)25&9
<GridSplitter Name="gridSplitter1" Margin="0" Width="5"
Grid.Column="1" HorizontalAlignment="Left"/>
?&#'!,.#*(/$',$";#'!"# !"#/0("223!#$%&'(%)#,.#8,+"&#/#-"-,$/'"-#$%)25&0
2"# ?&#XSUQ#+,"4;#2."#'!"#@%))%4,&8#XSUQ#'%#/--#/#,"96:3K2;'K#$%&'(%)#'%#'!"#'!,(-#
#$%)25&9
<RichTextBox Grid.Column="2" Name="richTextBox1"/>
3"# ?&#'!"#XSUQ#@%(#'!"#:''(;1!#$%&'(%);#2."#'!"#@%))%4,&8#XSUQ#'%#/--#'!(""#$%&'(%).#'%#
'!"#:''(;1!#$%&'(%)9
<Button>Bold</Button>
<Button>Italic</Button>
<Slider Name="Slider1" Minimum="2" Maximum="72" Width="100"/>
!4"# J%26)"<$),$L#'!"#62''%&#)/6")"-#=%)-#'%#%*"&#'!"#&("9G#"+"&'#!/&-)"(0#S--#'!"#@%))%4<
,&8#$%-"9
!:B<13%-F%I64D:1%H:465%)-;3
richTextBox1.Selection.ApplyPropertyValue(FontWeightProperty, _
FontWeights.Bold)
!:B<13%-F%)J%)-;3
richTextBox1.Selection.ApplyPropertyValue(FontWeightProperty,
FontWeights.Bold);
!!"# ?&#'!"#-".,8&"(;#-%26)"<$),$L#'!"#62''%&#)/6")"-#?'/),$#'%#%*"&#'!"#&("9G#"+"&'#!/&-)"(0#
S--#'!"#@%))%4,&8#$%-"9
!:B<13%-F%I64D:1%H:465%)-;3
richTextBox1.Selection.ApplyPropertyValue(FontStyleProperty, _
FontStyles.Italic)
!:B<13%-F%)J%)-;3
richTextBox1.Selection.ApplyPropertyValue(FontStyleProperty,
FontStyles.Italic);
www.it-ebooks.info
# Q"..%&#C9#>.,&8#REH#F%&'(%).# #$%&'() * <5
# !#"# ?&#'!"#-".,8&"(;#-%26)"<$),$L#'!"#.),-"(#'%#%*"&#'!"#B1()3&61+53##"+"&'#!/&-)"(0#S--#
'!"#@%))%4,&8#$%-"9
!:B<13%-F%I64D:1%H:465%)-;3
Try
richTextBox1.Selection.ApplyPropertyValue(FontSizeProperty, _
Slider1.Value.ToString())
Catch
End Try
!:B<13%-F%)J%)-;3
try
{
richTextBox1.Selection.ApplyPropertyValue(FontSizeProperty,
Slider1.Value.ToString());
}
catch { }
!$"# ?&#'!"#E"+#'-N#$%&.'(2$'%(;#/--#'!"#@%))%4,&8#$%-"#/@'"(#J+"2"1("83&'*0'+3+20#O?&#
_,.2/)#=/.,$;#7%2#4,))#!/+"#'%#/--#'!"#"&',("#$%&.'(2$'%(0P
!:B<13%-F%I64D:1%H:465%)-;3
Public Sub New()
InitializeComponent()
For Each F As FontFamily In Fonts.SystemFontFamilies
Dim l As ListBoxItem = New ListBoxItem()
l.Content = F.ToString()
l.FontFamily = F
listBox1.Items.Add(l)
Next
End Sub
!:B<13%-F%)J%)-;3
foreach (FontFamily F in Fonts.SystemFontFamilies)
{
ListBoxItem l = new ListBoxItem();
l.Content = F.ToString();
l.FontFamily = F;
listBox1.Items.Add(l);
}
!%"# ?&#'!"#-".,8&"(;#-%26)"<$),$L#'!"#Q,.'=%G#$%&'(%)#'%#%*"&#'!"#T")"$',%&F!/&8"-#"+"&'#
!/&-)"(0#S--#'!"#@%))%4,&8#$%-"9
!:B<13%-F%I64D:1%H:465%)-;3
richTextBox1.Selection.ApplyPropertyValue(FontFamilyProperty, _
CType(listBox1.SelectedItem, ListBoxItem).FontFamily)
!:B<13%-F%)J%)-;3
richTextBox1.Selection.ApplyPropertyValue(FontFamilyProperty,
((ListBoxItem)listBox1.SelectedItem).FontFamily);
www.it-ebooks.info
<9 #$%&'() * =2,)-,&8#/#>."(#?&'"(@/$"
!&"# E("..#H\#'%#62,)-#/&-#(2%2(#/**),$/',%&0#W%'"#'!/'#7%2#$/&#(".,A"#'!"#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7%2'#*(%*"(',".#%@#'!"#$%&'/,&"-#$%&'(%).0# !"#
4'!"8'+21(7("5+*3+2#/&-#B3!2"91(7("5+*3+2#*(%*"(',".#%@#$!,)-#$%&'(%).#-"'"(5,&"#!%4#
/#$%&'(%)#,.#/),8&"-#,&#'!"#!%(,A%&'/)#/&-#+"(',$/)#-,("$',%&.;#/&-#'!"#<1!5"+#*(%*"('7#
-"3&".#/&#/("/#%@#.*/$"#'!/'#.2((%2&-.#'!"#$%&'(%)0# !"#,5*/$'#%@#/#$%&'(%)d.#)/7%2'#
*(%*"(',".#$/&#-,@@"(;#-"*"&-,&8#%&#'!"#$%&'(%)#,!,$!#'!"7#/("#!%.'"-0
■# S''/$!"-#*(%*"(',".#/("#*(%*"(',".#*(%+,-"-#'%#/#$%&'(%)#67#,'.#$%&'/,&"(#%(#67#/&%'!"(#
$)/..0#F%&'(%).#!/+"#'!"."#*(%*"(',".#%&)7#4!"&#'!"7#/("#,&#'!"#$%(("$'#$%&'"G'#'%#
"G*("..#'!"50#`G/5*)".#%@#/''/$!"-#*(%*"(',".#,&$)2-"#'!"# !"#%,'-;# !"#%&'()*+;#/&-#
Q3RP'1!#S1>"512"'+%:1PJ+#3K#*(%*"(',".0
www.it-ebooks.info
Q"..%&#C9#>.,&8#REH#F%&'(%). #$%&'() * <;
■# !"# !"##$%&'(%)#,.#'!"#5%.'#$%55%&)7#2."-#)/7%2'#*/&")#@%(#'!"#-"+")%*5"&'#%@#2."(#
,&'"(@/$".0# !"# !"##$%&'(%)#"&/6)".#7%2#'%#-"3&"#8(,-#(%4.#/&-#$%)25&.#/&-#'%#!%.'#
52)',*)"#")"5"&'.#,&#"/$!#$"))0# !"# !"##$%&'(%)#*(%+,-".#/''/$!"-#*(%*"(',".#'%#$!,)-#
$%&'(%).#'!/'#-"'"(5,&"#'!"#8(,-#$%)25&#/&-#(%4#,!,$!#'!"7#/("#!%.'"-0#
■# !"# !"#/0("223!$$%&'(%)#"&/6)".#'!"#2."(#'%#(".,A"#8(,-#$%)25&.#/&-#(%4.#/'#(2&#',5"0
■# Q/7%2'#*/&").#.2$!#/.#F+"D'!* !"#;#/219GA1+3(;#E!10A1+3(;$@'9GA1+3(;#/&-#&1+>1=#
$%&'(%).#/("#$%55%&)7#2."-#'%#$("/'"#.*"$,/),A"-#*/('.#%@#'!"#2."(#,&'"(@/$"#/&-#/("#
2.2/))7#&%'#'!"#!,8!".'<)"+")#*/&")#,&#'!"#2."(#,&'"(@/$"0
,344-.%+3L6381%2#$/."#'!"#@%))%4,&8#I2".',%&.#'%#'".'#7%2(#L&%4)"-8"#%@#'!"#,&@%(5/',%&#,&#Q"..%&#C;#
e>.,&8#REH#F%&'(%).0f# !"#I2".',%&.#/("#/).%#/+/,)/6)"#%&#'!"#$%5*/&,%&#FJ#,@#7%2#*("@"(#'%#
("+,"4#'!"5#,&#")"$'(%&,$#@%(50
!"# %42P()2
@.48304%/-%/9343%MD34/6-.4%:.;%3G<1:.:/6-.4%-F%89=%3:59%:.4830%59-653%64%5-0035/%-0%6.5-0N
035/%:03%1-5:/3;%6.%/93%O@.48304P%435/6-.%:/%/93%3.;%-F%/93%7-->?
!"# V%4#5/&7#$!,)-#$%&'(%).#$/&#/#$%&'"&'#$%&'(%)#$%&'/,&g
)"# K
5"# C#
*"# W%#),5,'#
6"# J"*"&-.#%&#'!"#$%&'(%)#
#"# R!,$!#%@#'!"#@%))%4,&8#XSUQ#./5*)".#$%(("$')7#.!%4.#/#62''%&#,&#/#$"))#$("/'"-#67#'!"#
,&'"(."$',%&#%@#'!"#."$%&-#$%)25&#/&-#'!"#."$%&-#(%4#%@#/#8(,-#4,'!#@%2(#$")).g#
)"#
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Grid.Cell="1,1"></Button>
</Grid>
5"#
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
!"# %42P()2
@.48304%/-%/9343%MD34/6-.4%:.;%3G<1:.:/6-.4%-F%89=%3:59%:.4830%59-653%64%5-0035/%-0%6.5-0N
035/%:03%1-5:/3;%6.%/93%O@.48304P%435/6-.%:/%/93%3.;%-F%/93%7-->?
www.it-ebooks.info
<. #$%&'() * =2,)-,&8#/#>."(#?&'"(@/$"
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Grid.Column="1" Grid.Row="1"></Button>
</Grid>
*"#
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button></Button>
</Grid>
6"#
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Grid.Cell="2,2"></Button>
</Grid>
$"# R!,$!#XSUQ#./5*)"#$%(("$')7#-"3&".#/#$%&'"G'#5"&2#@%(#=2''%&Cg
)"#
<Grid>
<ContextMenu name="mymenu">
<MenuItem>MenuItem</MenuItem>
</ContextMenu>
<Button ContextMenu="mymenu" Height="23" HorizontalAlignment="Left"
Margin="54,57,0,0" Name="button1" VerticalAlignment="Top"
Width="75">Button</Button>
</Grid>
5"#
<ContextMenu Name="mymenu">
<MenuItem>MenuItem</MenuItem>
</ContextMenu>
<Grid>
<Button ContextMenu="mymenu" Height="23" HorizontalAlignment="Left"
www.it-ebooks.info
# Q"..%&#C9#>.,&8#REH#F%&'(%).# #$%&'() * <=
Margin="54,57,0,0" Name="button1" VerticalAlignment="Top"
Width="75">Button</Button>
</Grid>
*"#
<Menu Name="mymenu" ContextMenu="True">
<MenuItem>MenuItem</MenuItem>
</Menu>
<Grid>
<Button ContextMenu="mymenu" Height="23" HorizontalAlignment="Left"
Margin="54,57,0,0" Name="button1" VerticalAlignment="Top"
Width="75">Button</Button>
</Grid>
6"#
<Grid>
<Button Height="23" HorizontalAlignment="Left" Margin="54,57,0,0"
Name="button1" VerticalAlignment="Top" Width="75">
<Button.ContextMenu>
<ContextMenu>
<MenuItem>MenuItem</MenuItem>
</ContextMenu>
</Button.ContextMenu>
Button
</Button>
</Grid>
%"# R!/'#,.#'!"#5/G,525#&256"(#%@#$!,)-#")"5"&'.#'!/'#/&#,'"5#$%&'(%)#$/&#$%&'/,&g
)"# K
5"# C#
*"# W%#),5,'
6"# J"*"&-.#%&#'!"#$%&'(%)
&"# R!,$!#)/7%2'#*/&")#4%2)-#6"#'!"#6".'#$!%,$"#@%(#/#2."(#,&'"(@/$"#'!/'#("I2,(".#"+"&)7#
.*/$"-#$%&'(%).#)/,-#%2'#,&#/#("82)/(#*/''"(&g
$ )"$ !"##
$ 5"# &1+>1=#
$ *"$ F+"D'!* !"##
$ 6"$ E!10A1+3(#
0"# 1%2#/("#4%(L,&8#4,'!#/#;)22'+$$%&'(%)#$%&'/,&"-#,&#/#&1+>1=$$%&'(%)0#R!,$!#XSUQ#
./5*)"#4,))#*%.,',%&#'!"#62''%&$"-8".#YK#2&,'.#@(%5#'!"#6%''%5#"-8"#%@#'!"#$/&+/.#
/&-#YK#2&,'.#@(%5#'!"#(,8!'#"-8"#%@#'!"#$/&+/.#/.#4"))#/.#5/,&'/,&#'!/'#*%.,',%&,&8#
4!"&#'!"#$/&+/.#,.#(".,A"-g#O`/$!#$%(("$'#/&.4"(#*("."&'.#/#$%5*)"'"#.%)2',%&0#F!%%."#
/))#'!/'#/**)70P
www.it-ebooks.info
": #$%&'() * =2,)-,&8#/#>."(#?&'"(@/$"
)"#
<Button Margin="20" Canvas.Bottom="0" Canvas.Right="0"></Button>
5"#
<Button Margin="20"></Button>
*"#
<Button Canvas.Bottom="20" Canvas.Right="20"></Button>
6"#
<Button Margin="20" Canvas.Bottom="20" Canvas.Right="20"></Button>
www.it-ebooks.info
Q"..%&#Y9#>.,&8#h".%2($". #$%&'() * "*
,DFFOE !Q 8F@EK )DFO?HADF
h".%2($".#/("#3)".#%(#%6B"$'.#/&#/**),$/',%.".#62'#/("#&%'#$("/'"-#,&#'!"#/$'2/)#"G"$2'/6)"#
$%-"0#R,&-%4.#H%(5.#2.".#6,&/(7#(".%2($".#'%#/))%4#*(%8(/5.#/$$"..#'%#)/(8"#3)".#.2$!#/.#
,5/8".#%(#)/(8"#'"G'#3)".0#S)'!%28!#REH#'"$!&%)%87#2.".#6,&/(7#(".%2($".;#,'#/).%#,&'(%-2$".#
'!"#,-"/#%@#)%8,$/)#(".%2($".;#4!,$!#-"3&"#%6B"$'.#@%(#2."#,%2(#/**),$/',%&#/&-#/))%4#7%2#
'%#.!/("#%6B"$'.#/5%&8#")"5"&'.0#?&#'!,.#)"..%&;#7%2#)"/(&#!%4#'%#/$$"..#"&$%-"-#/&-#6,&/(7#
(".%2($".#,%'!#R,&-%4.#H%(5.#/&-#REH#/**),$/',%&.0#1%2#)"/(&#!%4#'%#$("/'"#(".%2($"<
%&)7#-7&/5,$<),&L#),6(/(,".#OJQQ.P#/&-#)%/-#(".%2($"<%&)7#/.."56),".0#1%2#/).%#)"/(&#!%4#'%#
$("/'"#)%8,$/)#(".%2($".#/&-#(".%2($"#-,$',%&/(,".#/&-#'%#/$$"..#(".%2($".#,&#$%-"#@%(#7%2(#
REH#/**),$/',%&.0#Q/.';#7%2#)"/(&#'!"#-,@@"("&$"#6"'4""&#.'/',$#/&-#-7&/5,$#(".%2($".#/&-#
4!"&#'%#2."#"/$!0
@F/30%/964%1344-.C%=-D%8611%73%:713%/-Q%
■ `56"-#/#6,&/(7#(".%2($"#,&#/&#/**),$/',%&0
■ h"'(,"+"#/#6,&/(7#(".%2($"#67#2.,&8#$%-"0
■ h"'(,"+"#/#6,&/(7#(".%2($"#67#2.,&8#*/$L#>h?#.7&'/G0
■ S$$"..#/#(".%2($"#,&#/&%'!"(#/.."56)7#67#2.,&8#*/$L#>h?#.7&'/G0
■ S--#/#$%&'"&'#3)"#'%#/&#/**),$/',%&0
■ F("/'"#/#(".%2($"<%&)7#JQQ0
■ Q%/-#/&-#/$$"..#/#(".%2($"<%&)7#JQQ0
■ F("/'"#/#)%8,$/)#(".%2($"0
■ F("/'"#/&#/**),$/',%&#(".%2($"0
■ S$$"..#/#(".%2($"#,&#XSUQ0
■ `G*)/,&#'!"#-,@@"("&$"#6"'4""&#/#.'/',$#(".%2($"#/&-#/#-7&/5,$#(".%2($"0
■ F("/'"#/#(".%2($"#-,$',%&/(70
■ U"(8"#(".%2($"#-,$',%&/(,".0
■ J"$,-"#4!"("#'%#.'%("#/#(".%2($"0
■ S$$"..#/#(".%2($"#%6B"$'#,&#$%-"0
(4/6B:/3;%1344-.%/6B3Q%R%9-D0
46.A%H6.:0=%+34-D0534=,&/(7#(".%2($".#"&/6)"#7%2#'%#$%5*,)"#)/(8"#6,&/(7#3)".#,%2(#/**),$/',%&#/.."56),".#/&-#
("'(,"+"#'!"5#@%(#2."#,%2(#/**),$/',%&0#=,&/(7#(".%2($".#/("#-,@@"("&'#@(%5#)%8,$/)#(".%2($<
".;#4!,$!#$/"#-"3&"-#/&-#/$$".."-#,&#XSUQ#3)".0#Q%8,$/)#(".%2($".#/("#-,.$2.."-#)/'"(#,&#
'!,.#)"..%&0
@F/30%/964%1344-.C%=-D%8611%73%:713%/-Q%
■ `56"-#/#6,&/(7#(".%2($"#,&#/&#/**),$/',%&0
■ h"'(,"+"#/#6,&/(7#(".%2($"#67#2.,&8#$%-"0
■ h"'(,"+"#/#6,&/(7#(".%2($"#67#2.,&8#*/$L#>h?#.7&'/G0
■ S$$"..#/#(".%2($"#,&#/&%'!"(#/.."56)7#67#2.,&8#*/$L#>h?#.7&'/G0
■ S--#/#$%&'"&'#3)"#'%#/&#/**),$/',%&0
■ F("/'"#/#(".%2($"<%&)7#JQQ0
■ Q%/-#/&-#/$$"..#/#(".%2($"<%&)7#JQQ0
■ F("/'"#/#)%8,$/)#(".%2($"0
■ F("/'"#/&#/**),$/',%&#(".%2($"0
■ S$$"..#/#(".%2($"#,&#XSUQ0
■ `G*)/,&#'!"#-,@@"("&$"#6"'4""&#/#.'/',$#(".%2($"#/&-#/#-7&/5,$#(".%2($"0
■ F("/'"#/#(".%2($"#-,$',%&/(70
■ U"(8"#(".%2($"#-,$',%&/(,".0
■ J"$,-"#4!"("#'%#.'%("#/#(".%2($"0
■ S$$"..#/#(".%2($"#%6B"$'#,&#$%-"0
(4/6B:/3;%1344-.%/6B3Q%R%9-D0
www.it-ebooks.info
"! #$%&'() * =2,)-,&8#/#>."(#?&'"(@/$"
(B73;;6.A%+34-D0534
`56"--,&8#(".%2($".#,%2(#/**),$/',%&#,.#@/,()7#"/.70#S))#7%2#&""-#'%#-%#,.#/--#'!"#3)"#'%#
7%2(#*(%B"$'#/&-#."'#'!"#3)"d.#;)"(#$792"'+#*(%*"('7#'%#,3=')!93%#R!"&#'!"#/**),$/',%&#,.#
$%5*,)"-;#'!"#(".%2($"#,.#$%5*,)"-#/2'%5/',$/))7#/.#/#(".%2($"#/&-#"56"--"-#,%2(#/*<
*),$/',%&0#1%2#$/."#'!,.#*(%$"-2("#'%#"56"-#(".%2($".#,%'!#R,&-%4.#H%(5.#/&-#REH#
/**),$/',%&.0
%#"56"-#/#(".%2($"#,%2(#/**),$/',%&;
!"# H(%5#'!"#E(%B"$'#5"&2;#$!%%."#S--#`G,.',&8#?'"50# !"#S--#`G,.',&8#?'"5#-,/)%8#6%G#
%*"&.0
#"# =(%4."#'%#'!"#3)"#7%2#4/&'#'%#/--0#F),$L#S--#'%#/--#,'#'%#7%2(#*(%B"$'0
$"# ?&#'!"#E(%*"(',".#4,&-%4;#."'#'!"#;)"(##792"'+#*(%*"('7#@%(#'!,.#3)"#'%#,3=')!930
!"# '$( !"#$%&'(")* &)/&()'0
2-%.-/%43/%/93%?@+60<A31+-*%<0-<30/=%/-%(B73;;3;%+34-D053C%89659%3B73;4%/93%03N
4-D053%D46.A%:%;6FF303./%034-D053%B:.:A3B3./%4593B3%/9:/%64%1344%:553446713%F0-B%SET%
:<<165:/6-.4?
1%2#$/*-/'"#/#(".%2($"#'!/'#!/.#6""&#*("+,%2.)7#/--"-#'%#/&#/**),$/',%C#@%))%4,&8#
'!"#*("+,%2.#*(%$"-2("#/&-#("$%5*,),&8#7%2(#/**),$/',%&0
,-:;6.A%+34-D0534
!"#REH#J*153#$)/..#,.#$/*/6)"#%@#,&'"(/$',&8#-,("$')7#4,'!#"56"--"-#(".%2($".0# %#.*"$,@7#/&#
,5/8"#(".%2($";#/))#7%2#!/+"#'%#-%#,.#("@"(#'%#'!"#"56"--"-#3)"#*/'!;#/.#.!%4&#,%)-#!"("9
<Image Source="myPic.bmp" Margin="17,90,61,22"
Name="Image1" Stretch="Fill"/>
!"#$%&'()*%$+%,%+#$-.$'$+%#./+0%$-!'-$!'#$1%%2$'33%3$3"+%0-*4$-.$4./+$)+.5%0-6$72$(.#-$
0'#%#8$4./$9'2-$-.$.+:'2";%$4./+$+%#./+0%#$"2$,.*3%+#$"2$4./+$'))*"0'-".26$<'-/+'**48$4./$(/#-$
"20*/3%$-!%$,.*3%+$2'(%$"2$4./+$)'-!8$'#$#!.92$"2$1.*3$!%+%=
<Image Source="myFolder/myPic.bmp" Margin="17,90,61,22"
Name="Image1" Stretch="Fill"/>
>!%2$'00%##"2:$%(1%33%3$+%#./+0%#8$-!%$,.+9'+3$#*'#!$?@A$"#$/#%3$"2$-!%$BC7$14$0.2D%2E
-".28$1/-$%"-!%+$-!%$,.+9'+3$#*'#!$.+$-!%$1'0F$#*'#!$?GA$9"**$9.+F6
!"#$%&'(
!%$#42-'&$)+%D"./#*4$#!.92$-.$'00%##$%(1%33%3$+%#./+0%#$"#$'0-/'**4$'$#!.+-!'23$#42-'&$
-!'-$+%)+%#%2-#$-!%$*.2:%+$#42-'&$,.+$)'0F$BC7#8$9!"0!$"#$'$9'4$>HI$'00%##%#$%(1%33%3$
+%#./+0%#$3"+%0-*4$14$#)%0",4"2:$'$BC7$-.$-!'-$+%#./+0%6$ !%$,/**$#42-'&$,.+$/#"2:$)'0F$BC7#$-.$
*.0'-%$'2$%(1%33%3$+%#./+0%$"#$'#$,.**.9#=
pack://<Authority>/<Folder>/<FileName>
!"# !"# !"#$%&'(")*#$%&$"% ')*
)*$+*,$(-,$,.-$ !"#$%&'(")*$/0*/-0,1$,*$234-55-5$&-(*60"-7$8.9".$-34-5($,.-$0-:
(*60"-$6(9+;$!$59<<-0-+,$0-(*60"-$3!+!;-3-+,$(".-3-$,.!,$9($=-(($!""-((94=-$<0*3$> ?$
!//=9"!,9*+(@
www.it-ebooks.info
$ J%##.2$K=$B#"2:$C%#./+0%#$ (!)$ "%#*# +,
!%$ !"#$%&'#()$#)%0"L%3$"2$-!%$)'0F$BC7$#42-'&$"#$.2%$.,$-9.$).##"1*%$D'*/%#6$7-$0'2$1%$
%"-!%+$*++,'-*#'%./000$9!"0!$3%#":2'-%#$-!'-$-!%$BC7$#!./*3$*..F$-.$-!%$'##%(1*4$-!%$0/++%2-$
'))*"0'-".2$"#$"2$,.+$+%#./+0%$.+$0.2-%2-$L*%#8$.+$1'#2343&'5'./000$9!"0!$"23"0'-%#$-!'-$-!%$')E
)*"0'-".2$#!./*3$*..F$-.$-!%$#"-%$.,$-!%$'))*"0'-".2M#$.+":"2$,.+$-!%$"23"0'-%3$+%#./+0%$L*%#6$ !%$
1'#2343&'5'.$#42-'&$"#$3"#0/##%3$,/+-!%+$"2$-!%$NC%-+"%D"2:$J..#%$I"*%#$9"-!$1'#2343&'5'.$H'0F$
BC7#O$#%0-".2$*'-%+$"2$-!"#$0!')-%+6$7,$'$+%*'-"D%$BC7$"#$/#%38$*++,'-*#'%./000$"#$'##/(%3$-.$1%$-!%$
!"#$%&'#()6
!/#8$-!%$)+%D"./#$%&'()*%$.,$'2$67*52$%*%(%2-$0./*3$1%$+%9+"--%2$-.$/#%$-!%$,/**$)'0F$
BC7$#42-'&8$'#$#!.92$"2$1.*3$!%+%=
<Image Source="pack://application:,,,/myFolder/myPic.bmp"
Margin="17,90,61,22" Name="Image1" Stretch="Fill"/>
!%$,/**$)'0F$BC7$#42-'&$0.(%#$"2$!'234$9!%2$4./$2%%3$-.$+%-+"%D%$'2$%(1%33%3$+%#./+0%$
"2$0.3%8$'#$#!.92$!%+%=
A!3/=-$*<$B9(6!=$C!(9"$D*5-$
Dim myImage As Image
myImage.Source = New BitmapImage(New _
Uri("pack://application:,,,/myFolder/myPic.bmp"))
A!3/=-$*<$DE$D*5-$
Image myImage;
myImage.Source = new BitmapImage(new
Uri("pack://application:,,,/myFolder/myPic.bmp"));
%(9+;$&-(*60"-($9+$F,.-0$G((-34=9-(
P./$0'2$'*#.$/#%$-!%$)'0F$BC7$#42-'&$-.$'00%##$+%#./+0%#$%(1%33%3$"2$.-!%+$'##%(1*"%#6$ !%$
,.**.9"2:$%&'()*%$3%(.2#-+'-%#$-!%$1'#"0$)'0F$BC7$#42-'&$,.+$'00%##"2:$%(1%33%3$+%#./+0%#$
"2$.-!%+$'##%(1*"%#=
pack://application:,,,/<AssemblyName>;component/<Folder>/<FileName>
!/#8$",$4./$9'2-%3$-.$*.0'-%$'$L*%$2'(%3$(4H"061()$"2$-!%$,.*3%+$(4I.*3%+$"2$'2.-!%+$
'##%(1*4$2'(%3$(4Q##%(1*48$4./$9./*3$/#%$-!%$,.**.9"2:$)'0F$BC7=
Pack://application:,,,/myAssembly;component/myFolder/myPic.bmp
Q#$9"-!$.-!%+$)'0F$BC7#8$",$-!%$%(1%33%3$L*%$3.%#$2.-$%&"#-$9"-!"2$'$,.*3%+8$-!%$,.*3%+$"#$
.("--%3$"2$-!%$BC76
D*+,-+,$?9=-(P./$3.$2.-$9'2-$-.$%(1%3$'**$-!%$L*%#$4./+$'))*"0'-".2$/#%#$'#$+%#./+0%#6$I.+$%&'()*%8$L*%#$
-!'-$2%%3$-.$1%$/)3'-%3$,+%R/%2-*4$#!./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2:$
V.2D%2-".2$?B<VA$)'-!$,+.($9!"0!$-!%$'))*"0'-".2$9'#$.+":"2'**4$3%)*.4%36
I.+$'$)'+-"'*E-+/#-$'))*"0'-".2$3%)*.4%3$9"-!$V*"0FS20%$.+$'2$WQXJ$T+.9#%+$Q))*"0'-".2$
?WTQHA8$1'#2343&'5'./000$+%,%+#$-.$-!%$BCJ$.+$B<V$)'-!$-!'-$!.#-#$-!%$'))*"0'-".26
H'0F$BC7#$-!'-$/#%$-!%$1'#2343&'5'./000$#42-'&$'*9'4#$)."2-$-.$*..#%$L*%#$?-!'-$"#8$L*%#$-!'-$
'+%$0.)"%3$-.$-!%$./-)/-$3"+%0-.+4$1/-$'+%$2.-$0.()"*%3AY$-!%4$2%D%+$)."2-$-.$%(1%33%3$
+%#./+0%#6$ !/#8$-!%$L*%#$-!%4$+%,%+%20%$#!./*3$'*9'4#$%&"#-$"2$-!%$3"+%0-.+4$#)%0"L%3$14$-!%$
1'#2343&'5'./008$#42-'&$"2$'$*..#%8$/20.()"*%3$#-'-%6
!%$,.**.9"2:$%&'()*%$3%(.2#-+'-%#$/#%$.,$-!%$1'#2343&'5'./000$#42-'&=
<Image Source="pack://siteOfOrigin:,,,/OfficeFrontDoor.jpg"/>
www.it-ebooks.info
$ J%##.2$K=$B#"2:$C%#./+0%#$ (!)$ "%#*# +-
&-,09-H9+;$&-(*60"-($J!+6!==1
P./$(":!-$2%%3$-.$/#%$+%#./+0%$L*%#$9"-!$.15%0-#$-!'-$3.$2.-$#/)).+-$-!%$)'0F$BC7$
#42-'&6$72$-!%#%$0'#%#8$4./$(/#-$+%-+"%D%$-!%$+%#./+0%#$('2/'**4$/#"2:$-!%$!++,'-*#'%.
B=C2#D21%"&-2E#&2*7$(%-!.36$ !"#$(%-!.3$+%-/+2#$'$E(1#27BF'.9%A1BD21%"&-21
B=E#&2*7D21%"&-26.4%$.15%0-$-!'-$%&).#%#$-9.$)+.)%+-"%#=$-!%$>%.#2.#?(+2$)+.)%+-48$9!"0!$
3%#0+"1%#$-!%$-4)%$.,$0.2-%2-$0.2-'"2%3$"2$-!%$+%#./+0%8$'23$-!%$E#&2*7$)+.)%+-48$9!"0!$0.2E
-'"2#$'2$G.7*.*529827%&(E#&2*7$.15%0-$-!'-$%&).#%#$-!%$+'9$3'-'$.,$-!%$+%#./+0%6$ !%2$
4./$0'2$('2")/*'-%$-!'-$3'-'$)+.:+'(('-"0'**46$ !%$,.**.9"2:$%&'()*%$3%(.2#-+'-%#$!.9$-.$
+%-+"%D%$-!%$-%&-$0.2-'"2%3$"2$'2$%(1%33%3$+%#./+0%$-%&-$L*%=
A!3/=-$*<$B9(6!=$C!(9"$D*5-$
Dim myInfo As System.Windows.Resources.StreamResourceInfo
Dim myString As String
myInfo = Application.GetResourceStream( _
New Uri("myTextFile.txt", UriKind.Relative))
Dim myReader As New System.IO.StreamReader(myInfo.Stream)
' myString is set to the text contained in myTextFile.txt
myString = myReader.ReadToEnd()
A!3/=-$*<$DE$D*5-$
System.Windows.Resources.StreamResourceInfo myInfo;
string myString;
myInfo = Application.GetResourceStream(
new Uri("myTextFile.txt", UriKind.Relative));
System.IO.StreamReader myReader =
new System.IO.StreamReader(myInfo.Stream);
// myString is set to the text contained in myTextFile.txt
myString = myReader.ReadToEnd();
D0-!,9+;$&-(*60"-:F+=1$)II(
P./$0'2$0+%'-%$ZJJ#$-!'-$0.2-'"2$.2*4$0.()"*%3$+%#./+0%#6$ !"#$0'2$1%$/#%,/*$"2$#"-/'-".2#$
9!%2$+%#./+0%$L*%#$2%%3$-.$0!'2:%$,+%R/%2-*4$1/-$+%0.()"*"2:$-!%$'))*"0'-".2$"#$2.-$'2$.)E
-".26$P./$0'2$/)3'-%$'23$+%0.()"*%$-!%$+%#./+0%#$'23$-!%2$#9')$-!%$.*3$+%#./+0%$ZJJ$,.+$-!%$
2%9$.2%6
V+%'-"2:$'$+%#./+0%E.2*4$ZJJ$"#$,'"+*4$#-+'":!-,.+9'+36$ .$0+%'-%$'$+%#./+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B9(6!=$C!(9"$D*5-$
Dim aName As System.Reflection.AssemblyName
aName = System.Reflection.AssemblyName.GetAssemblyName("C:\myAssembly.dll"))
A!3/=-$*<$DE$D*5-$
System.Reflection.AssemblyName aName;
aName = System.Reflection.AssemblyName.GetAssemblyName("C:\\myAssembly.dll"));
#"$ B#%$-!%$!1127H,(I*72$.15%0-$-.$*.'3$-!%$'##%(1*48$'#$#!.92$!%+%=
A!3/=-$*<$B9(6!=$C!(9"$D*5-
Dim asm As System.Reflection.Assembly
asm = System.Reflection.Assembly.Load(aName)
A!3/=-$*<$DE$D*5-$
System.Reflection.Assembly asm;
asm = System.Reflection.Assembly.Load(aName);
$"$ Q,-%+$-!%$'##%(1*4$!'#$1%%2$*.'3%38$4./$0'2$'00%##$-!%$2'(%#$.,$-!%$+%#./+0%#$
-!+./:!$-!%$!1127H,(BC2#8*.'421#D21%"&-2I*721$(%-!.3$'23$-!%$+%#./+0%$#-+%'(#$
-!+./:!$-!%$!1127H,(BC2#8*.'421#D21%"&-2E#&2*7$(%-!.36$ !%$,.**.9"2:$%&'()*%$
3%(.2#-+'-%#$!.9$-.$+%-+"%D%$-!%$2'(%#$.,$-!%$+%#./+0%#$"2$'2$'##%(1*4$'23$-!%2$*.'3$
'2$"(':%$,+.($-!%$+%#./+0%$#-+%'($"2-.$'$>"23.9#$I.+(#$H"0-/+%T.&$0.2-+.*=
A!3/=-$*<$B9(6!=$C!(9"$D*5-$
Dim res() As String = asm.GetManifestResourceNames
PictureBox1.Image = New _
System.Drawing.Bitmap(asm.GetManifestResourceStream(res(0)))
A!3/=-$*<$DE$D*5-
String res[] = asm.GetManifestResourceNames();
pictureBox1.Image = new
System.Drawing.Bitmap(asm.GetManifestResourceStream(res[0]));
%(9+;$I*;9"!=$&-(*60"-(J%5'-*,=&21%"&-21$%2'1*%$4./$-.$3%L2%$.15%0-#$"2$WQXJ$-!'-$'+%$2.-$)'+-$.,$-!%$D"#/'*$-+%%$1/-$
'+%$'D'"*'1*%$,.+$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#$(.#-$0.((.2$-.$3%L2%$+%#./+0%#$"2$-!%$D21%"&-21$0.**%0-".2$.,$
-!%$9"23.98$4./$0'2$3%L2%$'$+%#./+0%$"2$'24$%*%(%2-M#$D21%"&-21$0.**%0-".2$'23$'00%##$"-$#.$
*.2:$'#$-!%$'00%##"2:$%*%(%2-$"#$)'+-$.,$-!%$3%L2"2:$%*%(%2-M#$D"#/'*$-+%%6
)-"=!09+;$!$I*;9"!=$&-(*60"-
P./$3%0*'+%$'$*.:"0'*$+%#./+0%$14$'33"2:$"-$-.$'$D21%"&-21$0.**%0-".28$'#$#!.92$!%+%=
<Window.Resources>
<RadialGradientBrush x:Key="myBrush">
<GradientStop Color="CornflowerBlue" Offset="0" />
<GradientStop Color="Crimson" Offset="1" />
</RadialGradientBrush>
</Window.Resources>
7,$4./$3.2M-$"2-%23$'$+%#./+0%$-.$1%$'D'"*'1*%$-.$-!%$%2-"+%$9"23.90$4./$0'2$3%L2%$"-$"2$-!%$
D21%"&-21$0.**%0-".2$.,$'2$%*%(%2-$"2$-!%$9"23.90$'#$#!.92$"2$-!"#$%&'()*%=
<Grid>
<Grid.Resources>
<RadialGradientBrush x:Key="myBrush">
<GradientStop Color="CornflowerBlue" Offset="0" />
<GradientStop Color="Crimson" Offset="1" />
</RadialGradientBrush>
</Grid.Resources>
</Grid>
!%$/#%,/*2%##$.,$-!"#$"#$#.(%9!'-$*"("-%38$'23$-!%$(.#-$0.((.2$#0%2'+".$"#$-.$3%L2%$+%E
#./+0%#$"2$-!%$F'.9%ABD21%"&-21$0.**%0-".26$S2%$)."2-$-.$+%(%(1%+$"#$-!'-$9!%2$/#"2:$#-'-"0$
+%#./+0%#8$4./$(/#-$3%L2%$-!%$+%#./+0%$"2$-!%$WQXJ$0.3%$1%,.+%$4./$+%,%+$-.$"-6$\-'-"0$'23$
342'("0$+%#./+0%#$'+%$%&)*'"2%3$*'-%+$"2$-!"#$*%##.26
UD%+4$.15%0-$3%0*'+%3$'#$'$D21%"&-2$(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2-$.+$>"23.98$4./$0'2$3%L2%$
+%#./+0%#$-!'-$'+%$'00%##"1*%$14$'**$.15%0-#$"2$'$)'+-"0/*'+$'))*"0'-".26$P./$0'2$0+%'-%$'2$')E
)*"0'-".2$+%#./+0%$14$.)%2"2:$-!%$Q))6&'(*$L*%$?,.+$Va$)+.5%0-#A$.+$-!%$Q))*"0'-".26&'(*$L*%$
?,.+$["#/'*$T'#"0$)+.5%0-#A$'23$'33"2:$-!%$+%#./+0%$-.$-!%$!++,'-*#'%.BD21%"&-21$0.**%0-".28$'#$
#!.92$"2$1.*3$!%+%=
<Application x:Class="WpfApplication2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<SolidColorBrush x:Key="appBrush" Color="PapayaWhip" />
</Application.Resources>
</Application>
G""-((9+;$!$&-(*60"-$9+$KGJI
P./$0'2$'00%##$'$+%#./+0%$"2$WQXJ$14$/#"2:$-!%$,.**.9"2:$#42-'&=
{StaticResource myBrush}
72$-!"#$%&'()*%8$-!%$('+F/)$3%0*'+%#$-!'-$'$#-'-"0$+%#./+0%$9"-!$-!%$7(<&"1$$F%4$"#$'0E
0%##%3B$T%0'/#%$-!"#$+%#./+0%$"#$'$<&"1$$.15%0-8$4./$0'2$)*/:$-!'-$('+F/)$"2-.$'24$)*'0%$-!'-$
%&)%0-#$'$<&"1$$.15%0-6$ !"#$%&'()*%$3%(.2#-+'-%#$!.9$-.$/#%$'$+%#./+0%$"2$-!%$0.2-%&-$.,$'$
>HI$%*%(%2-=
<Grid Background="{StaticResource myBrush}">
</Grid>
>!%2$'$+%#./+0%$"#$+%,%+%20%3$"2$WQXJ8$-!%$D21%"&-21$0.**%0-".2$.,$-!%$3%0*'+"2:$.15%0-$"#$
L+#-$#%'+0!%3$,.+$'$+%#./+0%$9"-!$'$('-0!"2:$F%46$7,$.2%$"#$2.-$,./238$-!%$D21%"&-21$0.**%0-".2$
.,$-!'-$%*%(%2-M#$)'+%2-$"#$#%'+0!%38$'23$#.$.28$/)$-.$-!%$9"23.9$-!'-$!.#-#$-!%$%*%(%2-$'23$
-.$-!%$'))*"0'-".2$D21%"&-21$0.**%0-".26
A,!,9"$!+5$)1+!39"$&-(*60"-(
72$'33"-".2$-.$-!%$#42-'&$3%#0+"1%3$)+%D"./#*48$4./$0'2$+%,%+%20%$'$+%#./+0%$9"-!$-!%$,.**.9E
"2:$#42-'&=
{DynamicResource myBrush}
!%$3",,%+%20%$1%-9%%2$-!%$Z42'("0C%#./+0%$'23$\-'-"0C%#./+0%$#42-'&$*"%#$"2$!.9$-!%$
+%,%+%20"2:$%*%(%2-#$+%-+"%D%$-!%$+%#./+0%#6$C%#./+0%#$+%,%+%20%3$14$-!%$\-'-"0C%#./+0%$#42E
-'&$'+%$+%-+"%D%3$.20%$14$-!%$+%,%+%20"2:$%*%(%2-$'23$/#%3$,.+$-!%$*",%-"(%$.,$-!%$+%#./+0%6$
www.it-ebooks.info
$ J%##.2$K=$B#"2:$C%#./+0%#$ (!)$ "%#*# +1
C%#./+0%#$+%,%+%20%3$9"-!$-!%$Z42'("0C%#./+0%$#42-'&$'+%$'0R/"+%3$%D%+4$-"(%$-!%$+%,%+E
%20%3$.15%0-$"#$/#%36
7-$(":!-$#%%($"2-/"-"D%$-.$-!"2F$-!'-8$",$4./$/#%$\-'-"0C%#./+0%$#42-'&8$-!%$+%,%+%20"2:$
.15%0-$3.%#$2.-$+%`%0-$0!'2:%#$-.$-!%$/23%+*4"2:$+%#./+0%8$1/-$-!"#$"#$2.-$2%0%##'+"*4$-!%$
0'#%6$>HI$.15%0-#$-!'-$"()*%(%2-$3%)%23%204$)+.)%+-"%#$'/-.('-"0'**4$"20.+).+'-%$0!'2:%$
2.-"L0'-".28$'23$0!'2:%#$('3%$-.$-!%$)+.)%+-"%#$.,$-!%$+%#./+0%$'+%$)"0F%3$/)$14$'24$.15%0-#$
/#"2:$-!'-$+%#./+0%6$ 'F%$-!%$,.**.9"2:$%&'()*%=
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<SolidColorBrush x:Key="BlueBrush" Color="Blue" />
</Window.Resources>
<Grid Background="{StaticResource BlueBrush}">
</Grid>
</Window>
!"#$%&'()*%$+%23%+#$-!%$:+"3$"2$-!%$9"23.9$9"-!$'$1*/%$1'0F:+./236$7,$-!%$>%,%&$)+.)%+-4$
.,$-!%$E%,'9>%,%&<&"1$$3%L2%3$"2$-!%$F'.9%ABD21%"&-21$0.**%0-".2$9'#$0!'2:%3$"2$0.3%$-.$
+%38$,.+$"2#-'20%8$-!%$1'0F:+./23$.,$-!%$:+"3$9./*3$+%23%+$'#$+%3$1%0'/#%$0!'2:%$2.-"L0'-".2$
9./*3$2.-",4$'**$.15%0-#$/#"2:$-!'-$+%#./+0%$-!'-$-!%$)+.)%+-4$!'3$0!'2:%36
!%$3",,%+%20%$1%-9%%2$#-'-"0$'23$342'("0$+%#./+0%#$0.(%#$9!%2$-!%$/23%+*4"2:$.15%0-$
0!'2:%#6$7,$<&"1$$3%L2%3$"2$-!%$F'.9%A1BD21%"&-21$0.**%0-".2$9%+%$'00%##%3$"2$0.3%$'23$#%-$
-.$'$3",,%+%2-$.15%0-$"2#-'20%8$-!%$:+"3$"2$-!%$)+%D"./#$%&'()*%$9./*3$2.-$3%-%0-$-!"#$0!'2:%6$
b.9%D%+8$",$-!%$:+"3$/#%3$-!%$,.**.9"2:$('+F/)8$-!%$0!'2:%$.,$-!%$.15%0-$9./*3$1%$3%-%0-%38$
'23$-!%$:+"3$9./*3$+%23%+$-!%$1'0F:+./23$9"-!$-!%$2%9$1+/#!=
<Grid Background="{DynamicResource BlueBrush}">
</Grid>
Q00%##"2:$+%#./+0%#$"2$0.3%$"#$3"#0/##%3$"2$-!%$NC%-+"%D"2:$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#$!.9$-.$0+%'-%$'$2%9$+%#./+0%$3"0-".2'+4$"2$4./+$'))*"0'-".26
.$0+%'-%$'$+%#./+0%$3"0-".2'+4=
!"$ I+.($-!%$H+.5%0-$(%2/8$0!..#%$Q33$C%#./+0%$Z"0-".2'+46$ !%$Q33$<%9$7-%($3"'*.:$
1.&$.)%2#6$V!..#%$-!%$2'(%$,.+$-!%$+%#./+0%$3"0-".2'+4$'23$0*"0F$Q336$ !%$2%9$+%E
#./+0%$3"0-".2'+4$"#$.)%2%3$"2$WQXJ$D"%96
#"$ Q33$+%#./+0%#$-.$-!%$2%9$+%#./+0%$3"0-".2'+4$"2$WQXJ$D"%96$P./$0'2$'33$+%#./+0%#$-.$
-!%$L*%$"2$WQXJ$D"%98$'#$#!.92$"2$1.*3$!%+%=
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="appBrush" Color="DarkSalmon" />
</ResourceDictionary>
J-0;9+;$&-(*60"-$)9",9*+!09-(
I.+$.15%0-#$"2$4./+$'))*"0'-".2$-.$'00%##$+%#./+0%#$"2$'$+%#./+0%$3"0-".2'+48$4./$(/#-$(%+:%$
-!%$+%#./+0%$3"0-".2'+4$L*%$9"-!$'$D21%"&-21$0.**%0-".2$-!'-$"#$'00%##"1*%$"2$4./+$'))*"0'-".28$
#/0!$'#$-!%$F'.9%ABD21%"&-21$.+$!++,'-*#'%.BD21%"&-21$0.**%0-".26$P./$(%+:%$+%#./+0%$3"0E
-".2'+"%#$14$'33"2:$'$+%,%+%20%$-.$4./+$+%#./+0%$3"0-".2'+4$L*%$"2$-!%$$D21%"&-2@'-#'%.*&(
B82&529@'-#'%.*&'21$0.**%0-".26$ !%$,.**.9"2:$%&'()*%$3%(.2#-+'-%#$!.9$-.$(%+:%$-!%$
+%#./+0%#$"2$'$F'.9%ABD21%"&-21$0.**%0-".2$9"-!$-!%$+%#./+0%#$"2$+%#./+0%$3"0-".2'+4$L*%#$
2'(%3$Z"0-".2'+4e6&'(*$'23$Z"0-".2'+4K6&'(*=
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
<ResourceDictionary Source="Dictionary2.xaml" />
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="BlueBrush" Color="Blue" />
</ResourceDictionary>
</Window.Resources>
7,$4./$3%L2%$'33"-".2'*$+%#./+0%#$"2$4./+$D21%"&-21$0.**%0-".28$-!%4$(/#-$1%$3%L2%3$9"-!"2$
-!%$1./23#$.,$-!%$D21%"&-2@'-#'%.*&($-':#6
D.**(9+;$>.-0-$,*$A,*0-$!$&-(*60"-
P./$!'D%$#%%2$#%D%+'*$.)-".2#$+%:'+3"2:$9!%+%$+%#./+0%#$#!./*3$1%$#-.+%36$ !%$,'0-.+#$-!'-$
#!./*3$1%$9%":!%3$9!%2$3%0"3"2:$9!%+%$-.$#-.+%$'$+%#./+0%$"20*/3%$%'#%$.,$'00%##"1"*"-4$14$
+%,%+%20"2:$%*%(%2-#8$+%'3'1"*"-4$'23$('"2-'"2'1"*"-4$.,$-!%$0.3%8$'23$+%/#'1"*"-46
www.it-ebooks.info
$ J%##.2$K=$B#"2:$C%#./+0%#$ (!)$ "%#*# -*
I.+$+%#./+0%#$-.$1%$'00%##%3$14$'**$%*%(%2-#$"2$'2$'))*"0'-".28$#-.+%$+%#./+0%#$"2$-!%$
$!++,'-*#'%.BD21%"&-21$0.**%0-".26$ !%$F'.9%ABD21%"&-21$0.**%0-".2$('F%#$+%#./+0%#$'D'"*'1*%$
.2*4$-.$%*%(%2-#$"2$-!'-$9"23.98$1/-$-!'-$"#$-4)"0'**4$#/,L0"%2-$,.+$(.#-$)/+).#%#6$7,$4./$2%%3$
-.$#!'+%$"23"D"3/'*$+%#./+0%#$.D%+$(/*-")*%$)+.5%0-#$"2$'$#.*/-".28$4./+$1%#-$0!."0%$"#$-.$#-.+%$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SolidColorBrush
aBrush = CType(Button1.FindResource("myBrush"), SolidColorBrush)
A!3/=-$*<$DE$D*5-$
SolidColorBrush aBrush;
aBrush = (SolidColorBrush)Button1.FindResource("myBrush");
!%$M'.9D21%"&-2$(%-!.3$-!+.9#$'2$%&0%)-".2$",$-!%$2'(%3$+%#./+0%$0'22.-$1%$,./236$ .$
'D."3$).##"1*%$%&0%)-".2#8$4./$0'2$/#%$-!%$?&(M'.9D21%"&-2$(%-!.3$"2#-%'36
P./$'*#.$0'2$'00%##$+%#./+0%#$3"+%0-*4$-!+./:!$-!%$D21%"&-21$0.**%0-".2$.2$-!%$%*%(%2-$
-!'-$0.2-'"2#$"-6$ !%$0'D%'-$!%+%$"#$-!'-$4./$(/#-$F2.9$"2$9!"0!$0.**%0-".2$-!%$+%#./+0%$"#$
3%L2%3$'23$/#%$-!%$0.++%0-$D21%"&-21$0.**%0-".26$ !%$,.**.9"2:$%&'()*%$3%(.2#-+'-%#$!.9$
-.$'00%##$'$+%#./+0%$9"-!$-!%$L2($D'*/%$.,$7(<&"1$$-!+./:!$-!%$D21%"&-21$0.**%0-".2$.,$-!%$
9"23.9/
A!3/=-$*<$B9(6!=$C!(9"$D*5-$
Dim aBrush As SolidColorBrush
aBrush = CType(Me.Resources("myBrush"), SolidColorBrush)
A!3/=-$*<$DE$D*5-$
SolidColorBrush aBrush;
aBrush = (SolidColorBrush)this.Resources["myBrush"];
www.it-ebooks.info
#-3 (!)$ "%#* T/"*3"2:$'$B#%+$72-%+,'0%
>!%2$/#%3$"2$0.3%8$+%#./+0%#$'+%$+%'3E9+"-%6$ !/#8$4./$'0-/'**4$0'2$0!'2:%$-!%$.15%0-$-.$
9!"0!$'$+%#./+0%$+%,%+#6$ !"#$%&'()*%$3%(.2#-+'-%#$!.9$4./$0'2$0+%'-%$'$2%9$.15%0-$"2$0.3%$
'23$#%-$'2$%&"#-"2:$+%#./+0%$-.$"-=
A!3/=-$*<$B9(6!=$C!(9"$D*5-$
Dim aBrush As New SolidColorBrush(Colors.Red)
Me.Resources("myBrush") = aBrush
A!3/=-$*<$DE$D*5-$
SolidColorBrush aBrush = new SolidColorBrush(Colors.Red);
this.Resources["myBrush"] = aBrush;
7,$-!%$.15%0-$'$+%#./+0%$+%,%+#$-.$"#$0!'2:%3$"2$0.3%8$.15%0-#$-!'-$/#%$-!'-$+%#./+0%$1%!'D%$
3",,%+%2-*48$3%)%23"2:$.2$!.9$-!%$+%#./+0%$"#$+%,%+%20%36$C%#./+0%#$+%,%+%20%3$9"-!$-!%$
@(.*7'-D21%"&-2$('+F/)$/#%$-!%$2%9$.15%0-$9!%2$-!%$+%#./+0%$"#$0!'2:%3$"2$0.3%6$S15%0-#$
-!'-$+%,%+%20%$+%#./+0%#$9"-!$-!%$E#*#'-D21%"&-2$('+F/)$0.2-"2/%$-.$/#%$-!%$.15%0-$-!%4$"2"E
-"'**4$+%-+"%D%3$,+.($-!%$D21%"&-21$0.**%0-".2$'23$'+%$/2'9'+%$.,$-!%$0!'2:%6
'()*+,*- $4567869#:87;#<=>865?#%9@=A469@
72$-!"#$)+'0-"0%8$4./$0+%'-%$-9.$+%#./+0%$3"0-".2'+"%#$'23$(%+:%$-!%($9"-!$-!%$+%#./+0%#$"2$
4./+$9"23.96
-.-(*,/- D0-!,9+;$&-(*60"-$)9",9*+!09-(
!"$ S)%2$-!%$)'+-"'*$#.*/-".2$,.+$-!"#$)+'0-"0%6
#"$ I+.($-!%$H+.5%0-$(%2/8$0!..#%$Q33$C%#./+0%$Z"0-".2'+46$<'(%$-!%$L*%$
$B48C%9@=A469@DE5F?$'23$0*"0F$Q336
$"$ Q33$'2.-!%+$+%#./+0%$3"0-".2'+4$'23$2'(%$"-$GA77=H%9@=A469@DE5F?6
%"$ 72$\.*/-".2$U&)*.+%+8$3./1*%E0*"0F$_+"3C%#./+0%#6&'(*$-.$.)%2$-!%$C&'9D21%"&-21$+%E
#./+0%$3"0-".2'+46$Q33$-!%$,.**.9"2:$J'.2*&C&*9'2.#<&"1$$.15%0-$-.$-!%$_+"3C%#./+0%#6
&'(*$L*%=
<LinearGradientBrush x:Key="GridBackgroundBrush">
<GradientStop Color="AliceBlue" Offset="0" />
<GradientStop Color="Blue" Offset=".5" />
<GradientStop Color="Black" Offset="1" />
</LinearGradientBrush>
&"$ Z./1*%E0*"0F$T/--.2C%#./+0%#6&'(*$-.$.)%2$-!%$<"##%.D21%"&-21$+%#./+0%$3"0-".2'+46$
Q33$-!%$,.**.9"2:$+%#./+0%#$-.$-!"#$L*%=
<LinearGradientBrush x:Key="ButtonBackgroundBrush">
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Red" Offset="1" />
</LinearGradientBrush>
<SolidColorBrush Color="Purple" x:Key="ButtonForegroundBrush" />
<SolidColorBrush Color="LimeGreen" x:Key="ButtonBorderBrush" />
<Style TargetType="Button">
www.it-ebooks.info
$ J%##.2$K=$B#"2:$C%#./+0%#$ (!)$ "%#*# -,
<Setter Property="Background" Value="{StaticResource
ButtonBackgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource
ButtonForegroundBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource
ButtonBorderBrush}" />
</Style>
!%#%$+%#./+0%#$"20*/3%$1+/#!%#$,.+$-!%$1'0F:+./238$,.+%:+./238$'23$1.+3%+$'#$9%**$'#$
'$#-4*%$-!'-$'/-.('-"0'**4$'))*"%#$-!%#%$1+/#!%#$-.$<"##%.$%*%(%2-#6
0"$ Z./1*%E0*"0F$>"23.9e$-.$.)%2$-!%$3%#":2%+$,.+$-!%$9"23.9B$Q1.D%$-!%$3%L2"-".2$,.+$
-!%$C&'9$%*%(%2-8$'33$-!%$,.**.9"2:$D21%"&-21$#%0-".2$-.$-!%$WQXJ$0.3%$,.+$-!%$9"2E
3.9/
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ButtonResources.xaml" />
<ResourceDictionary Source="GridResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
1"$ X.3",4$-!%$C&'9$3%L2"-".2$-.$+%,%+%20%$-!%$+%#./+0%$-!'-$3%L2%#$-!%$1+/#!$-.$1%$/#%3$
,.+$-!%$1'0F:+./23$.,$-!%=:+"38$'#$#!.92$!%+%=
<Grid Background="{StaticResource GridBackgroundBrush}">
2"$ H+%##$Ic$-.$1/"*3$'23$+/2$4./+$'))*"0'-".26$ !%$<&"1$$.15%0-#$3%L2%3$"2$-!%$+%#./+0%$
3"0-".2'+"%#$'+%$'))*"%3$-.$4./+$9"23.9B
I-((*+$A633!01■$ P./$0'2$'33$1"2'+4$+%#./+0%#$-.$'2$'))*"0'-".2$14$/#"2:$-!%$Q33$U&"#-"2:$7-%($(%2/$"2$
["#/'*$\-/3".$'23$#%--"2:$-!%$<"',9=!-#'%.$)+.)%+-4$.,$-!%$'33%3$L*%$-.$D21%"&-26
■$ I.+$+%#./+0%E'9'+%$0*'##%#$#/0!$'#$-!%$67*52$%*%(%2-8$4./$0'2$+%-+"%D%$%(1%33%3$
+%#./+0%#$14$/#"2:$)'0F$BC7$#42-'&6$ !%$)'0F$BC7$#42-'&$'*#.$)+.D"3%#$,.+$'00%##"2:$
+%#./+0%#$"2$.-!%+$'##%(1*"%#6
■$ 7,$4./$'+%$9.+F"2:$9"-!$0*'##%#$-!'-$'+%$2.-$+%#./+0%E'9'+%8$4./$(/#-$+%-+"%D%$+%E
#./+0%#$('2/'**4$14$/#"2:$-!%$!++,'-*#'%.BC2#D21%"&-2E#&2*7$(%-!.3$-.$+%-+"%D%$-!%$
G.7*.*529827%&(E#&2*7$-!'-$%20.3%#$-!%$+%#./+0%6$ !%2$4./$0'2$/#%$-!%$I"*%$7S$
0*'##%#$-.$+%'3$-!%$#-+%'(6
■$ V.2-%2-$L*%#$0'2$1%$'33%3$'#$*..#%$L*%#8$9!"0!$'+%$L*%#$-!'-$'+%$0.)"%3$-.$-!%$./-)/-$
3"+%0-.+4$1/-$'+%$2.-$0.()"*%36$P./$(/#-$/#%$0.2-%2-$L*%#$-.$'33$#./23$.+$(%3"'$L*%#$
-.$'2$'))*"0'-".2$1%0'/#%$X%3"'H*'4%+$'23$X%3"'U*%(%2-$'+%$"20')'1*%$.,$+%'3"2:$
%(1%33%3$+%#./+0%#6
www.it-ebooks.info
Module 2: Working With Controls 1
Overview
� Creating an Event Handler for a Control
� Using Windows Forms Controls
� Using Dialogs
� Validating User Input
� Creating Controls at Run Time
� Creating Menus
*****************************ILLEGAL FOR NON-TRAINER USE******************************
When you design the user interface (UI) and develop the code that operates behind the UI of an application, you will need to work with controls and their events, properties, and methods to meet the design requirements that you have been given.
This module covers how to create event procedures (handlers) in your application that will run in response to user actions. You will learn how to add programming logic to the event procedures of a control, how to use the Windows Forms intrinsic controls, dialog boxes, and menus, and how to validate the data entered by users of your application.
After completing this module, you will be able to:
� Create an event handler for a control.
� Select and use the appropriate controls in a Windows Forms application.
� Use dialog boxes in a Windows Forms application.
� Validate user input in a Windows Forms application.
� Add controls to a form at run time.
� Create and use menus in a Windows Forms application.
Introduction
Objectives
2 Module 2: Working With Controls
Lesson: Creating an Event Handler for a Control
� Event Model in the .NET Framework
� What Are Delegates?
� What Is an Event Handler?
� How to Create Handlers for Control Events
� How to Add and Remove Event Handlers at Run Time
� Practice: Creating an Event Handler for a Control
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In the .NET Framework, an event is a message sent by an object to signal the occurrence of an action that is either user invoked by a user or programmatically. Each event has a sender that raises the event and a receiver that handles the event.
In this lesson, you will learn about events and the ways in which events can be handled in your application. You will then learn how to create procedures that handle events and how to add and remove event handlers at run time.
After completing this lesson, you will be able to:
� Describe the event model in the .NET Framework.
� Create and use event handlers.
� Create event procedures using the Handles and WithEvents keywords.
� Add and remove handles from event procedures at run time.
Introduction
Lesson objectives
Module 2: Working With Controls 3
Event Model in the .NET Framework
Button1
Invokes the
delegate
this.button1.Click += new
System.EventHandler(this.button1_Click);
private void button1_Click(object
sender, System.EventArgs e)
{
…
}
Delegate calls the
associated procedureDelegateDelegateDelegate
this.button1.Click += new
System.EventHandler(this.button1_Click);
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In the .NET Framework, an event is used to signal the occurrence of an action. For example, this action could be user invoked, such as the Click event of a Button control, or the event could be raised programmatically to signal the end of a long computation. The object that raises (triggers) the event is referred to as the event sender. The procedure that handles the event is referred to as the event receiver. In either case, the sender does not know which object or method will respond to the events that it raises. Therefore, it is necessary to have a component that links the event sender with the event receiver. The .NET Framework uses a Delegate type to work as a function pointer between the sender and the event receiver. In most cases, the .NET Framework creates the delegate and takes care of the details for you. However, you can create your own delegates for the cases where you want an event to call different event handlers under different circumstances.
Delegates are objects that you can use to call the methods of other objects. Delegates are useful in situations where you need an intermediary between a calling procedure and the procedure being called. You create a Delegate class that is used as the base class for a Delegate type. Within the Delegate class, you create the methods that are used to respond to the event or events that the delegate handles.
Introduction
Delegate class
4 Module 2: Working With Controls
What Are Delegates?
public delegate void AlarmEventHandler(objectsender, AlarmEventArgs e);
public delegate void AlarmEventHandler(objectsender, AlarmEventArgs e);
� Delegate
� Binds events to methods
� Can be bound to single or multiple methods
� When an event is recorded by an application
� The control raises the event by invoking the delegate for the event
� The delegate in turn calls the bound method
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In the .NET Framework, delegates are used to hold a reference to the method that will handle an event. For example, an event occurs when a user clicks a button. The button raises a click event, but does not know what behavior you, the programmer, want to occur when the button is clicked, so the button has a delegate member to which you assign your own method for handling the event. You can use the same infrastructure that is used by the .NET Framework to create your own delegates.
A delegate is a data structure, derived from the Delegate Class, which refers to a static method or to a class instance and an instance method of that class. Using delegates is useful when your application must perform an action by calling a method but you do not know what that action will be.
Delegates allow you to specify at runtime the method to be invoked. Delegates are object-oriented, type-safe, and secure.
By convention, event delegates in the .NET Framework have two parameters, the source that raised the event and the data for the event. The following example shows an event delegate declaration:
public delegate void AlarmEventHandler(object sender,
AlarmEventArgs e);
Event delegates are multicast, which means that they can hold references to more than one event handling method. Delegates allow for flexibility and fine-grain control in event handling. A delegate acts as an event dispatcher for the class that raises the event by maintaining a list of registered event handlers for the event. For more information on Delegates, see “Delegate Class” in the Visual Studio .NET help.
Introduction
Definition
Event delegate declaration
Module 2: Working With Controls 5
What Is an Event Handler?
� Event Handlers
� Methods bound to an event
� When the event is raised, the code within the event handler is executed
� Two Event Arguments with Event Handlers
� An object representing the object that raised the event
� An event object containing any event-specific information
private void button1_Click(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
}
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Functionality is added to controls by raising and consuming events. Before your application can respond to an event, you must create an event handler. The event handler (event procedure) contains the program logic that runs when the event is raised.
An event handler is a method (generally a sub procedure) that is bound to an event. When the event is raised, the code within the event handler runs. You can use the same event handler to handle more than one event. For example, you can create a single event handler to handle events of a button and a menu item that are used for the same purpose. Similarly, if you have a group of RadioButton controls on a form, you could create a single event handler and have each control's Click event bound to the single event handler.
The following code example is an event handler for the Click event of a button.
private void button1_Click(object sender, System.EventArgs e)
{
}
The following code example shows how you can use a single event handler to handle events for multiple controls.
Introduction
Definition
Example of event handler
6 Module 2: Working With Controls
// inside the Windows Form Designer generated code region
…
this.button1.Click += new
System.EventHandler(this.button1_Click);
// add the button2.click event to button1_click handler
this.button2.Click += new
System.EventHandler(this.button1_Click);
private void button1_Click(object sender, System.EventArgs e)
{
}
Each event handler provides two parameters that allow you to handle the event
properly.
� The first parameter (Sender in the previous code example), provides a
reference to the object that raised the event. It specifies the source that raised the event.
� The second parameter (e in the previous code example), passes an object specific to the event being handled. This parameter contains all of the data
that is required to handle the event.
Event handler parameters
Module 2: Working With Controls 7
How to Create Handlers for Control Events
private void button1_Click(object sender,
System.EventArgs e){
MessageBox.Show("MyHandler received the event");
}
private void button1_Click(object sender,
System.EventArgs e){
MessageBox.Show("MyHandler received the event");
}
� Use WithEvents keyword to declare object variables that will be used with the Handles statement
� Use the Handles keyword at the end of the procedure declaration
*****************************ILLEGAL FOR NON-TRAINER USE******************************
C# .NET uses the 'System.EventHandler += new …' syntax to define an event handler. The standard way to create an event handler in C# .NET is through the Properties pane of the control.
To create an event procedure for a control:
1. In the Designer view, click the control that you want to create an event
handler for.
2. In the Properties pane, click Event (the button displaying the lightning bolt).
3. Double-click the event that you want to handle. Code will be added to the Code view.
4. Add program logic to the event handler procedure using the supplied
arguments. The following code provides an example:
private void button1_Click(object sender,
System.EventArgs e)
{
MessageBox.Show("MyHandler received the event");
}
Introduction
Procedure
8 Module 2: Working With Controls
How to Add and Remove Event Handlers at Run Time
� To associate an event with an event handler at run time
� Use the AddHandler statement
� To remove the association of an event with an event handler at run time
� Use the RemoveHandler statement
this.button2.Click -= new System.EventHandler(this.button1_Click);
this.button2.Click -= new System.EventHandler(this.button1_Click);
this.button2.Click += new System.EventHandler(this.button1_Click);
this.button2.Click += new System.EventHandler(this.button1_Click);
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In C# .NET, you can add and remove event handlers at run time by using the System.EventHandler += new … and System.EventHandler -= new
…syntax.
To add event handlers by using System.EventHandler += new … syntax:
1. Use the System.EventHandler += new … syntax to specify the name of
the event sender and receiver, as shown in the following code example:
// inside the Windows Form Designer generated code region
…
this.button1.Click += new
System.EventHandler(this.button1_Click);
// add the button2.click event to button1_click handler
this.button2.Click += new
System.EventHandler(this.button1_Click);
private void button1_Click(object sender, System.EventArgs
e)
{
}
To remove event handlers by using System.EventHandler -= new …syntax:
• Use the System.EventHandler -= new …syntax to specify the name of the event sender and receiver.
// remove the button2.click event from button1_click
handler
this.button2.Click -= new
System.EventHandler(this.button1_Click);
Introduction
Procedure: Adding event handlers using AddHandler
Procedure: Removing event handlers using RemoveHandler
!"#$%&'(' )*
!" # $ % & ' (
!"#$%&'($)*'+,-%).'/%0'1!22/%0.
!"#$%& '$( )*++'$(& ,*-+ %.# /'&0& *, %.# '-).0%#)%1-# ,*- 0$%-'2'3340)'%0*$ )*++1$02
)'%0*$ 0$ 50$(*6& 7-#&#$%'%0*$ 8*1$('%0*$ 9578: '3340)'%0*$&; <*1%#( #"#$%& )'$ /#
-'0&#( /= +14%034# )*$%-*4& '$( #$'/4# ' >$# 4#"#4 *, )*$%-*4 *"#- 1&#- 0$31%; ?*++'$(&
'-# ' 6#4)*+# '((0%0*$ %* %.# @0)-*&*,% ;A!B 8-'+#6*-C '$( 3-*"0(# ' )#$%-'4 '-).0%#)%1-#
,*- #$'/40$D '$( (0&'/40$D .0D.24#"#4 %'&C&; E$0+'%0*$ %'C#& %.# )*$)#3% *, #"#$%& ' &%#3
,1-%.#- '$( #$'/4#& =*1 %* (#&0D$ 0$%#-')%0"0%= 0$%* =*1- '3340)'%0*$ /= %'C0$D '("'$%'D# *,
%.# 578 #"#$% 0$,-'&%-1)%1-#;
+3/2'!45-6)$,-.'$%')*$.'6*/7)-"8'■ @'$'D# -*1%#( #"#$%& 0$ 578;
■ ?*$>D1-# 578 )*++'$(0$D;
■ F+34#+#$% '$ '$0+'%0*$ 0$ 578;
9-..!%.'$%')*$.'6*/7)-"8
■ G#&&*$ HI ?*$>D1-0$D !"#$%& '$( !"#$% J'$(40$D ))
■ G#&&*$ KI ?*$>D1-0$D ?*++'$(& +,
■ G#&&*$ LI F+34#+#$%0$D E$0+'%0*$ -.(
www.it-ebooks.info
')/ !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
012341'536'01789
B* )*+34#%# %.# 4#&&*$& 0$ %.0& ).'3%#-M =*1 +1&% .'"#I
■ E )*+31%#- %.'% +##%& *- #N)##(& %.# +0$0+1+ .'-(6'-# -#O10-#+#$%& 40&%#( 0$ %.#
PE/*1% B.0& Q**CR &#)%0*$ '% %.# /#D0$$0$D *, %.# /**C;
■ @0)-*&*,% S0&1'4 T%1(0* KUHU 7-*,#&&0*$'4 !(0%0*$ 0$&%'44#( *$ =*1- )*+31%#-;
■ E$ 1$(#-&%'$(0$D *, @0)-*&*,% S0&1'4 Q'&0) *- ?V &=$%'N '$( ,'+040'-0%= 60%. %.# ;A!B
8-'+#6*-C;
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#-&; !"#$%&$'$(#) #$'/4# =*1 %* '(( +14%034#
4#"#4& *, )*+34#N0%= '$( &*3.0&%0)'%0*$ %* =*1- 1&#- 0$%#-,')# '$( %.# 6'= 0% -#&3*$(& %* 1&#-
0$31%; F$ %.0& 4#&&*$M =*1 4#'-$ '/*1% -*1%#( #"#$%&M 0$)41(0$D .*6 %* .'$(4# ' -*1%#( #"#$%M
(#>$# '$( -#D0&%#- ' $#6 -*1%#( #"#$%M .'$(4# '$ '3340)'%0*$ 40,#%0+# #"#$%M '$( 1&# %.#
*'$(#+,(,-$. )4'&&;
HD)-"')*$.'C-..!%@'<!='($CC'4-'/4C-')!8
■ !N34'0$ %.# (0,,#-#$)# /#%6##$ ' (0-#)% #"#$%M ' /1//40$D #"#$%M '$( ' %1$$#40$D
#"#$%;
■ W#>$# '$( -#D0&%#- ' $#6 -*1%#( #"#$%;
■ W#>$# &%'%0) )4'&& #"#$% .'$(4#-&;
■ J'$(4# '$ #"#$% 0$ ' 578 '3340)'%0*$;
■ J'$(4# '$ '%%').#( #"#$% 0$ ' 578 '3340)'%0*$;
■ J'$(4# '3340)'%0*$ 40,#%0+# #"#$%&;
■ X&# %.# *'$(#+,(,-$. )4'&&;
+.)$2/)-0'C-..!%')$2-8'IJ'2$%=)-.
!"#$%& .'"# /##$ ' ,'+040'- 3'-% *, @0)-*&*,% 50$(*6& 3-*D-'++0$D ,*- =#'-&; E$ $'$(#
0& ' +#&&'D# &#$% /= '$ */Y#)%M &1). '& ' )*$%-*4 *- '$*%.#- 3'-% *, %.# 1&#- 0$%#-,')#M %.'%
%.# 3-*D-'+ -#&3*$(& %* 9*- .'$(4#&: /= #N#)1%0$D )*(#; E4%.*1D. %.# %-'(0%0*$'4 ;A!B #"#$%
'-).0%#)%1-# 0& &%044 3-#&#$% 0$ 578 3-*D-'++0$DM 578 /104(& 13*$ %.# #"#$% )*$)#3% /=
0$%-*(1)0$D -*1%#( #"#$%&;
E C#= )*$)#3% %* -#+#+/#- 0$ #"#$% -*1%0$D 0& %.# )*$%-*4 )*$%'0$+#$% .0#-'-).=; F$ 578
1&#- 0$%#-,')#&M )*$%-*4& ,-#O1#$%4= )*$%'0$ *%.#- )*$%-*4&; 8*- #N'+34#M ' %=30)'4 1&#- 0$%#-2
,')# +0D.% )*$&0&% *, ' %*324#"#4 /0(%!1 */Y#)%M 6.0). )*$%'0$& ' 2.0% */Y#)%M 6.0). 0%,
+0D.% )*$%'0$ &#"#-'4 )*$%-*4&M *$# *, 6.0). )*14( /# ' 3!!45,. )*$%-*4M 6.0). 0$ %1-$ )*$2
%'0$& &#"#-'4 5"##!( )*$%-*4&; B.# -*1%#( #"#$% '-).0%#)%1-# '44*6& ,*- '$ #"#$% %.'% *-0D0$'%#&
0$ *$# )*$%-*4 %* /# -'0&#( /= '$*%.#- )*$%-*4 0$ %.# )*$%'0$+#$% .0#-'-).=; B.1&M 0, %.# 1&#-
)40)C& *$# *, %.# 5"##!( )*$%-*4& *$ %.# %**4/'-M %.'% #"#$% )'$ /# -'0&#( /= %.# /1%%*$M %.#
%**4/'-M %.# D-0(M *- %.# 60$(*6;
5.= 0& 0% 1&#,14 %* -*1%# #"#$%&Z T133*&#M ,*- #N'+34#M %.'% =*1 '-# (#&0D$0$D ' 1&#-
0$%#-,')# ,*- ' )'4)14'%*- 3-*D-'+; E& 3'-% *, %.0& '3340)'%0*$M =*1 +0D.% .'"# &#"#-'4 5"##!(
)*$%-*4& #$)4*&#( 60%.0$ ' 2.0% )*$%-*4; T133*&# =*1 6'$%#( '44 /1%%*$ )40)C& 0$ %.0& D-0( %* /#
.'$(4#( /= ' &0$D4# #"#$% .'$(4#-; 578 -'0&#& %.# )40)C #"#$% ,-*+ 5"##!(6 2.0%6 '$( '$= *%.#-
)*$%-*4 0$ %.# )*$%-*4 )*$%'0$+#$% .0#-'-).=; E& %.# (#"#4*3#-M =*1 )'$ (#)0(# 6.#-# '$(
.*6 %.# #"#$% 0& .'$(4#(; B.1&M =*1 )'$ 3-*"0(# ' &0$D4# #"#$% .'$(4#- ,*- '44 5"##!(&74089
HD)-"')*$.'C-..!%@'<!='($CC'4-'/4C-')!8
■ !N34'0$ %.# (0,,#-#$)# /#%6##$ ' (0-#)% #"#$%M ' /1//40$D #"#$%M '$( ' %1$$#40$D
#"#$%;
■ W#>$# '$( -#D0&%#- ' $#6 -*1%#( #"#$%;
■ W#>$# &%'%0) )4'&& #"#$% .'$(4#-&;
■ J'$(4# '$ #"#$% 0$ ' 578 '3340)'%0*$;
■ J'$(4# '$ '%%').#( #"#$% 0$ ' 578 '3340)'%0*$;
■ J'$(4# '3340)'%0*$ 40,#%0+# #"#$%&;
■ X&# %.# *'$(#+,(,-$. )4'&&;*'$(#+,(,-$.
+.)$2/)-0'C-..!%')$2-8'IJ'2$%=)-.
www.it-ebooks.info
')+ !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
#"#$%& *-0D0$'%0$D ,-*+ 5"##!( )*$%-*4& 0$ %.# D-0(M %.#-#/= &0+340,=0$D )*(#26-0%0$D %'&C&
'$( #$&1-0$D )*$&0&%#$)= 0$ #"#$% .'$(40$D;
F<7-.'!D'K!=)-0'+,-%).B.#-# '-# %.-## %=3#& *, -*1%#( #"#$%&I (0-#)%M /1//40$DM '$( %1$$#40$D;
L$"-6)'+,-%).
:0.$8#&$'$(#) '-# +*&% &0+04'- %* &%'$('-( ;A!B #"#$%&; G0C# ' &%'$('-( ;A!B #"#$%M ' (0-#)%
#"#$% 0& -'0&#( *$4= /= %.# )*$%-*4 0$ 6.0). 0% *-0D0$'%#&; Q#)'1&# *%.#- )*$%-*4& 0$ %.# )*$%-*4
)*$%'0$+#$% .0#-'-).= (* $*% -'0&# %.#&# #"#$%&M %.#-# 0& $* *33*-%1$0%= ,*- '$= *%.#- )*$%-*4
%* 3-*"0(# .'$(4#-& ,*- %.#&# #"#$%&; E$ #N'+34# *, ' (0-#)% #"#$% 0& %.# +!")$;$,'$ #"#$%;
M=44C$%&'+,-%).
5"<<40(-&$'$(#) '-# -'0&#( >-&% 0$ %.# )*$%-*4 6.#-# %.#= *-0D0$'%# '$( %.#$ /= #'). )*$%-*4
0$ %.'% )*$%-*4[& )*$%-*4 )*$%'0$+#$% .0#-'-).=M '4&* C$*6$ '& ' "0&1'4 %-##; B.# +!")$:!1(
#"#$% 0& '$ #N'+34# *, ' /1//40$D #"#$%; T133*&# =*1 .'"# ' ;,<$4 )*$%-*4 )*$%'0$#( 0$&0(#
' =4!1>,($4 )*$%-*4 )*$%'0$#( 0$&0(# ' 60$(*6; 5.#$ %.# +*1&# /1%%*$ 0& 3-#&&#( *"#- %.#
4'/#4M %.# >-&% )*$%-*4 %* -'0&# %.# +!")$:!1( #"#$% 6*14( /# ;,<$4? B.#$ =4!1>,($4 6*14(
-'0&# %.# +!")$:!1( #"#$% '$( %.#$M >$'44=M %.# 60$(*6 0%,; \*1 )*14( 3-*"0(# '$ #"#$%
.'$(4#- '% '$= *- '44 &%'D#& *, %.# #"#$% 3-*)#&&;
F=%%-C$%&'+,-%).
3"(($40(-&$'$(#) '-# %.# *33*&0%# *, /1//40$D #"#$%&; E #"(($40(-&$'$(# 0& -'0&#( >-&% /= %.#
%*3+*&% )*$%'0$#- 0$ %.# "0&1'4 %-## '$( %.#$ (*6$ %.-*1D. #'). &1))#&&0"# )*$%'0$#- 1$%04
0% 0& >$'44= -'0&#( /= %.# #4#+#$% 0$ 6.0). 0% *-0D0$'%#&; E$ #N'+34# *, ' %1$$#40$D #"#$% 0&
%.# >.$'0$1+!")$:!1( #"#$%; F$ %.# 3-#"0*1& #N'+34#M '4%.*1D. %.# #"#$% *-0D0$'%#& 60%.
%.# ;,<$4 )*$%-*4M %.# >-&% )*$%-*4 %* -'0&# %.# >.$'0$1+!")$:!1( #"#$% 0& /0(%!16 %.#$
=4!1>,($46 '$( %.#$M >$'44=M ;,<$4? B1$$#40$D #"#$%& #$'/4# =*1 %* 0$%#-)#3% '$( .'$(4#
#"#$%& 0$ %.# 60$(*6 *- )*$%'0$#- /#,*-# %.# #"#$% 0& -'0&#( /= %.# &3#)0>) )*$%-*4 &* =*1
)'$ >4%#- 0$31%M &1). '& C#=&%-*C#&M '% "'-=0$D 4#"#4&;
F$ %.# ;A!B 8-'+#6*-CM '44 %1$$#40$D #"#$%& /#D0$ 60%. %.# 6*-( >.$'0$1M &1). '&
>.$'0$1@$A:!1(M >.$'0$1+!")$:!1(M '$( &* *$M '$( '-# %=30)'44= (#>$#( 0$ 3'0-& 60%. '
)*+34#+#$%'-= /1//40$D #"#$%; 8*- #N'+34#M %.# %1$$#40$D #"#$% >.$'0$1@$A:!1( 0& 3'0-#(
60%. %.# @$A:!1( /1//40$D #"#$%; B.# %1$$#40$D #"#$% '46'=& 0& -'0&#( /#,*-# 0%& )*--#&3*$(2
0$D /1//40$D #"#$%M %.1& '44*60$D .0D.#-24#"#4 )*$%-*4& 0$ %.# "0&1'4 %-## %* .'$(4# %.# #"#$%;
!'). %1$$#40$D #"#$% &.'-#& 0%& 0$&%'$)# *, #"#$% '-D1+#$%& 60%. 0%& 3'0-#( /1//40$D #"#$%;
B.0& ,')% 0& 0+3*-%'$% %* -#+#+/#- 6.#$ .'$(40$D #"#$%&M '$( 0% 6044 /# (0&)1&&#( 0$ D-#'%#-
(#%'04 4'%#- 0$ %.0& ).'3%#-;
www.it-ebooks.info
G#&&*$ HI ?*$>D1-0$D !"#$%& '$( !"#$% J'$(40$D !"#$%&'(' ),
K!=)-0+,-%)H"&.E44 -*1%#( #"#$%& 0$)41(# '$ 0$&%'$)# *, !"#$%*'$(#B.-) 9*- ' )4'&& %.'% 0$.#-0%&
!"#$%*'$(#B.-): 0$ %.#0- &0D$'%1-#&; B.# !"#$%*'$(#B.-) )4'&& )*$%'0$& ' 6#'4%. *, 0$2
,*-+'%0*$ '/*1% %.# #"#$% '$( 0%& &*1-)# )*$%-*4; B'/4# K2H (#&)-0/#& %.# 3-*3#-%0#& *, %.#
!"#$%*'$(#B.-) )4'&&;
$"0:%'(C-' !"#$%*'$(#B.-) 7-*3#-%0#&
#&D#%&$5 E%F &G#$GDH
C,(%4$% F$(0)'%#& 6.#%.#- %.0& #"#$% .'& /##$ .'$(4#(; Q= &#%%0$D %.0&
3-*3#-%= %* 3."$M =*1 )'$ .'4% ,1-%.#- #"#$% /1//40$D *- %1$$#40$D;
D.0-0(,4E!".8$ ]#%& %.# */Y#)% %.'% *-0D0$'44= -'0&#( %.# #"#$%; 8*- +*&% 578
)*$%-*4&M %.0& 6044 /# %.# &'+# '& %.# */Y#)% -#%1-$#( /= %.# E!".8$
3-*3#-%=; J*6#"#-M ,*- &*+# )*$%-*4&M &1). '& )*+3*&0%# )*$%-*4&M
%.0& 3-*3#-%= 6044 -#%1-$ ' (0,,#-#$% */Y#)%;
!"#$%*'$(# <#%1-$& %.# !"#$%*'$(# */Y#)% ,*- %.# #"#$% %.'% 6'& -'0&#(; 5.#$
.'$(40$D +*-# %.'$ *$# #"#$% 60%. %.# &'+# #"#$% .'$(4#-M =*1
+0D.% $##( %* -#,#- %* %.0& 3-*3#-%= %* 0(#$%0,= 6.0). #"#$% .'&
/##$ -'0&#(;
E!".8$ <#%1-$& %.# */Y#)% %.'% -'0&#( %.# #"#$%;
E44 *'$(#B.-) ,*- -*1%#( #"#$%& 0$.#-0% %.# !"#$%*'$(#B.-) )4'&&M /1% +'$= *, %.#+
3-*"0(# '((0%0*$'4 0$,*-+'%0*$; 8*- #N'+34#M @$A<!,.%*'$(#B.-) 0& 1&#( 0$ C#=/*'-( #"#$%&
'$( 3-*"0(#& 0$,*-+'%0*$ '/*1% C#=&%-*C#&; G0C#60&#M +!")$*'$(#B.-)6 1&#( 0$ +*1&# #"#$%&M
3-*"0(#& 0$,*-+'%0*$ '/*1% %.# &%'%# *, %.# +*1&# 6.#$ %.# #"#$% %**C 34')#;
I68JK' L1JK
■ */)'/"-')*-')*"--'#$%0.'!D'"!=)-0'-,-%).'$%' >?'/%0'*!('0!')*-<'0$DD-"N
I68JK' L1JK'"9;M14
■ K!=)-0'-,-%).'$%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$.'B%/CC<'"/$.-0'4<')*-'-C-2-%)'$%'(*$6*'$)'!"$&$%/)-0E'
F=%%-C$%&'/%0'4=44C$%&'-,-%).'-%/4C-'-C-2-%).'!D')*-'=.-"'$%)-"D/6-')!'
"-.7!%0')!'-,-%).'"/$.-0'4<')*-$"'6!%)/$%-0'-C-2-%).E
www.it-ebooks.info
'+. !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
H))/6*$%&'/%'+,-%)'O/%0C-"B.# 3-#,#--#( 6'= %* '%%'). '$ #"#$% .'$(4#- 0& (0-#)%4= 0$ %.# !N%#$&0/4# E3340)'%0*$ @'-C13
G'$D1'D# 9^E@G: )*(#; \*1 &#% %.# #"#$% %* %.# $'+# *, ' +#%.*( 60%. %.# '33-*3-0'%#
&0D$'%1-# ,*- %.'% #"#$%; B.# ,*44*60$D #N'+34# (#+*$&%-'%#& &#%%0$D %.# #"#$% .'$(4#- ,*- '
5"##!( )*$%-*4[& 74089 #"#$%M '& &.*6$ 0$ /*4(I
<Button Height="23" Margin="132,80,70,0" Name="button1"
VerticalAlignment="Top" Click="button1_Click">Button</Button>
_1&% 40C# &#%%0$D ' 3-*3#-%=M =*1 +1&% &1334= ' &%-0$D "'41# %.'% 0$(0)'%#& %.# $'+# *, %.#
+#%.*(;
H))/6*-0'+,-%).
F% 0& 3*&&0/4# ,*- ' )*$%-*4 %* (#>$# ' .'$(4#- ,*- '$ #"#$% %.'% %.# )*$%-*4 )'$$*% 0%, -'0&#;
B.#&# 0$)0(#$%& '-# )'44#( ,##,8F$%&$'$(#)? 8*- #N'+34#M )*$&0(#- 5"##!( )*$%-*4& 0$ ' D-0(;
B.# 5"##!( )4'&& (#>$#& ' 74089 #"#$%M /1% %.# 2.0% )4'&& (*#& $*%; J*6#"#-M =*1 )'$ &%044
(#>$# ' .'$(4#- ,*- /1%%*$& 0$ %.# D-0( /= '%%').0$D %.# 74089 #"#$% *, %.# 5"##!( )*$%-*4 0$
%.# ^E@G )*(#; B.# ,*44*60$D #N'+34# (#+*$&%-'%#& '%%').0$D '$ #"#$% .'$(4#- ,*- ' /1%%*$
)*$%'0$#( 0$ ' D-0(I
<Grid Button.Click="button_Click">
<Button Height="23" Margin="132,80,70,0" Name="button1"
VerticalAlignment="Top" >Button</Button>
</Grid>
A*6 #"#-= %0+# ' /1%%*$ )*$%'0$#( 0$ %.# D-0( &.*6$ .#-# 0& )40)C#(M %.# <"##!(G74089
#"#$% .'$(4#- 6044 .'$(4# %.'% #"#$%;
O/%0C$%&'/'F=%%-C$%&'!"'M=44C$%&'+,-%)
E% %0+#&M =*1 +0D.% 6'$% %* .'4% %.# ,1-%.#- .'$(40$D *, %1$$#40$D *- /1//40$D #"#$%&; 8*-
#N'+34#M =*1 +0D.% 6'$% %* &133-#&& C#=&%-*C# .'$(40$D '% ' 3'-%0)14'- 4#"#4 0$ %.# )*$%-*4
.0#-'-).=; \*1 )'$ .'$(4# '$ #"#$% '$( .'4% '$= ,1-%.#- %1$$#40$D *- /1//40$D /= &#%%0$D %.#
C,(%4$% 3-*3#-%= *, %.# !"#$%*'$(#B.-) 0$&%'$)# %* 3."$M '& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Input.KeyEventArgs)
e.Handled = True
End Sub
;/27C-'!D'1Q'1!0-
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
}
www.it-ebooks.info
G#&&*$ HI ?*$>D1-0$D !"#$%& '$( !"#$% J'$(40$D !"#$%&'(' +-
A*%# %.'% %1$$#40$D #"#$%& '$( %.#0- 3'0-#( /1//40$D #"#$%& 9&1). '& >.$'0$1@$A:!1( '$(
@$A:!1(: &.'-# %.# &'+# 0$&%'$)# *, !"#$%*'$(#B.-)? B.1&M 0, =*1 &#% %.# C,(%4$% 3-*3#-%=
%* 3."$ *$ ' %1$$#40$D #"#$%M 0%& )*--#&3*$(0$D /1//40$D #"#$% '4&* 0& )*$&0(#-#( .'$(4#(
'$( 0& &133-#&&#(;
F*-' !"#$%&#&'"('1C/..*'$(#+,(,-$. 0& ' &%'%0) )4'&& %.'% +'$'D#& %.# -#D0&%-'%0*$ *, '44 578 -*1%#( #"#$%&; B'/4#
K2K (#&)-0/#& %.# +#%.*(& *, %.# *'$(#+,(,-$. )4'&&;
$"0:%'(C(' *'$(#+,(,-$. @#%.*(&
N%$!DE E%F &G#$GDH
2$# !"#$%*'$(#) <#%1-$& '$ '--'= %.'% )*$%'0$& '44 %.# -*1%#( #"#$%& %.'%
.'"# /##$ -#D0&%#-#( 0$ %.0& '3340)'%0*$
2$# !"#$%*'$(#)=!.D1($. <#%1-$& '$ '--'= *, '44 %.# -*1%#( #"#$%& %.'% .'"# /##$
-#D0&%#-#( ,*- ' &3#)0>#( #4#+#$% 0$ %.0& '3340)'%0*$
$-0)#$.74,))C,(%4$. <#D0&%#-& ' )4'&&24#"#4 #"#$% .'$(4#-M '& (0&)1&&#( 0$ %.#
P?-#'%0$D ' ?4'&&2G#"#4 !"#$% J'$(4#-R &#)%0*$ 4'%#- 0$ %.0&
).'3%#-
$-0)#$. !"#$%*'$(# <#D0&%#-& '$ 0$&%'$)#24#"#4 #"#$% .'$(4#-M '& (0&)1&&#( 0$
%.# $#N% &#)%0*$
L-B%$%&'/'R-('K!=)-0'+,-%)\*1 )'$ 1&# %.# *'$(#+,(,-$. )4'&& %* (#>$# ' $#6 -*1%#( #"#$% ,*- =*1- 578 )*$%-*4&; B.#
,*44*60$D 3-*)#(1-# (#&)-0/#& .*6 %* (#>$# ' $#6 -*1%#( #"#$%;
B* (#>$# ' $#6 -*1%#( #"#$%I
!" ?-#'%# ' &%'%0)M -#'(2*$4= (#>$0%0*$ ,*- %.# #"#$%M '& &.*6$ 0$ %.0& #N'+34#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Public Shared ReadOnly SuperClickEvent As RoutedEvent
;/27C-'!D'1Q'1!0-
public static readonly RoutedEvent SuperClickEvent;
#" ?-#'%# ' 6-'33#- ,*- %.# -*1%#( #"#$% %.'% #N3*&#& 0% '& ' %-'(0%0*$'4 ;A!B 8-'+#6*-C
#"#$%M '& &.*6$ 0$ %.0& #N'+34#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Public Custom Event SuperClick As RoutedEventHandler
AddHandler(ByVal value As RoutedEventHandler)
Me.AddHandler(SuperClickEvent, value)
End AddHandler
www.it-ebooks.info
'+( !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
RemoveHandler(ByVal value As RoutedEventHandler)
Me.RemoveHandler(SuperClickEvent, value)
End RemoveHandler
RaiseEvent(ByVal sender As Object, _
ByVal e As System.Windows.RoutedEventArgs)
Me.RaiseEvent(e)
End RaiseEvent
End Event
;/27C-'!D'1Q'1!0-
public event RoutedEventHandler SuperClick
{
add
{
this.AddHandler(SuperClickEvent, value);
}
remove
{
this.RemoveHandler(SuperClickEvent, value);
}
}
X&# ' (0,,#-#$% *'$(#B.-) )4'&& ,-*+ !"#$%*'$(#B.-)? \*1 +1&% (#-0"# ' $#6 )4'&&
,-*+ !"#$%*'$(#B.-) '$( )-#'%# ' $#6 (#4#D'%# %.'% 1&#& %.*&# #"#$% '-D1+#$%&;
$" X&# *'$(#+,(,-$. %* -#D0&%#- %.# $#6 #"#$% 0$ %.# )*$&%-1)%*- *, %.# )4'&& %.'% *6$&
%.0& #"#$%; \*1 +1&% 3-*"0(# %.# $'+# *, %.# #"#$%M %.# -*1%0$D &%-'%#D= 9(0-#)%M %1$2
$#40$DM *- /1//40$D:M %.# %=3# *, (#4#D'%# %.'% .'$(4#& %.# #"#$%M '$( %.# %=3# *, %.#
)4'&& %.'% *6$& 0%; E$ #N'+34# 0& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
EventManager.RegisterRoutedEvent("SuperClick", _
RoutingStrategy.Bubble, GetType(RoutedEventArgs), GetType(Window1))
;/27C-'!D'1Q'1!0-
EventManager.RegisterRoutedEvent("SuperClick",
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Window1));
K/$.$%&'/%'+,-%)
E,%#- '$ #"#$% 0& (#>$#(M =*1 )'$ -'0&# 0% 0$ )*(# /= )-#'%0$D ' $#6 0$&%'$)# *,
!"#$%*'$(#B.-) '$( 1&0$D %.# ,0)$*'$(# +#%.*(M '& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Dim myEventArgs As New RoutedEventArgs(myControl.myNewEvent)
MyBase.RaiseEvent(myEventArgs)
;/27C-'!D'1Q'1!0-
RoutedEventArgs myEventArgs = new RoutedEventArgs(myControl.myNewEvent);
RaiseEvent(myEventArgs);
www.it-ebooks.info
G#&&*$ HI ?*$>D1-0$D !"#$%& '$( !"#$% J'$(40$D !"#$%&'(' +O
1"-/)$%&'/'1C/..G9-,-C'+,-%)'O/%0C-"\*1 )'$ 1&# %.# *'$(#+,(,-$. )4'&& %* -#D0&%#- ' )4'&&24#"#4 #"#$% .'$(4#-; E )4'&&24#"#4 #"#$%
.'$(4#- .'$(4#& ' 3'-%0)14'- #"#$% ,*- '44 0$&%'$)#& *, ' )4'&& '$( 0& '46'=& 0$"*C#( /#,*-#
0$&%'$)# .'$(4#-&; B.1&M =*1 )'$ &)-##$ '$( &133-#&& #"#$%& /#,*-# %.#= -#'). 0$&%'$)# .'$2
(4#-&; B.# ,*44*60$D 3-*)#(1-# (#&)-0/#& .*6 %* 0+34#+#$% ' )4'&&24#"#4 #"#$% .'$(4#-;
B* )-#'%# ' )4'&&24#"#4 #"#$% .'$(4#-I
!" ?-#'%# ' &%'%0) +#%.*( %* .'$(4# %.# #"#$%; B.0& +#%.*( +1&% .'"# %.# &'+# &0D$'%1-#
'& %.# #"#$%; E$ #N'+34# 0& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Private Shared Sub SuperClickHandlerMethod(ByVal sender As Object, _
ByVal e As RoutedEventArgs)
' Handle the event here
End Sub
;/27C-'!D'1Q'1!0-
private static void SuperClickHandlerMethod(object sender, RoutedEventArgs e)
{
// Handle the event here
}
#" F$ %.# &%'%0) )*$&%-1)%*- ,*- %.# )4'&& ,*- 6.0). =*1 '-# )-#'%0$D %.# )4'&&24#"#4 #"#$%
.'$(4#-M )-#'%# ' (#4#D'%# %* %.0& +#%.*(M '& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Dim SuperClickHandler As New RoutedEventHandler( _
AddressOf SuperClickHandlerMethod)
;/27C-'!D'1Q'1!0-
RoutedEventHandler SuperClickHandler = new
RoutedEventHandler(SuperClickHandlerMethod);
$" E4&* 0$ %.# &%'%0) )*$&%-1)%*-M )'44 *'$(#+,(,-$.? $-0)#$.74,))C,(%4$. %* -#D0&%#- %.#
)4'&&24#"#4 #"#$% .'$(4#-M '& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
EventManager.RegisterClassHandler(GetType(Window1), _
SuperClickEvent, SuperClickHandler)
;/27C-'!D'1Q'1!0-
EventManager.RegisterClassHandler(typeof(Window1),
SuperClickEvent,SuperClickHandler);
H77C$6/)$!%G9-,-C'+,-%).!"#-= 578 '3340)'%0*$ 0& 6-'33#( /= '$ BHH408,#0!( */Y#)%M 6.0). 3-*"0(#& ' &#% *, #"#$%&
%.'% -#4'%# %* %.# '3340)'%0*$[& 40,#%0+#; \*1 )'$ .'$(4# %.#&# #"#$%& %* #N#)1%# )*(# 0$ -#2
&3*$&# %* '3340)'%0*$ &%'-%13 *- )4*&1-#; B.# BHH408,#0!( */Y#)% '4&* 3-*"0(#& ' &#% *, #"#$%&
www.it-ebooks.info
'+P !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
-#4'%#( %* $'"0D'%0*$ 0$ 3'D#2/'&#( '3340)'%0*$&; B.#&# #"#$%& 6#-# (0&)1&&#( 0$ ?.'3%#- HM
PQ104(0$D ' X&#- F$%#-,')#;R B'/4# K2L (#&)-0/#& %.# '"'04'/4# '3340)'%0*$24#"#4 #"#$%&M #N)41(2
0$D %.# $'"0D'%0*$ #"#$%&;
$"0:%'(CO' T#4#)%#( E3340)'%0*$2G#"#4 !"#$%&
%Q%H$ E%F &G#$GDH
B8#0',#$% `))1-& 6.#$ =*1 &60%). ,-*+ '$*%.#- '3340)'%0*$
%* =*1- 3-*D-'+; F% '4&* 0& -'0&#( %.# >-&% %0+# =*1
&.*6 ' 60$(*6;
:$,8#0',#$% `))1-& 6.#$ =*1 &60%). %* '$*%.#- 3-*D-'+
:0)H,#8F$.I(F,(%4$%*J8$H#0!( <'0&#( 6.#$ '$ 1$.'$(4#( #N)#3%0*$ *))1-& 0$ =*1-
'3340)'%0*$; \*1 )'$ .'$(4# '$ 1$.'$(4#( #N)#3%0*$
0$ %.# #"#$% .'$(4#- ,*- %.0& #"#$% /= &#%%0$D %.#
:0)H,#8F$.I(F,(%4$%*J8$H#0!(*'$(#B.-)?C,(%4$%&
3-*3#-%= %* 3."$;
*J0# `))1-& 6.#$ %.# '3340)'%0*$ 0& &.1% (*6$ ,*- '$=
-#'&*$
E$))0!(*(%0(- `))1-& 6.#$ %.# 50$(*6& &#&&0*$ 0& #$(0$DM &1). '&
6.#$ %.# 1&#- &.1%& (*6$ %.# )*+31%#- *- 4*D& *,,
E#,.#"H `))1-& '& %.# '3340)'%0*$ 0& &%'-%#(;
E3340)'%0*$ #"#$%& '-# &%'$('-( ;A!B #"#$%& 9-'%.#- %.'$ -*1%#( #"#$%&:M '$( =*1 )'$ )-#2
'%# .'$(4#-& ,*- %.#&# #"#$%& 0$ %.# &%'$('-( ;A!B 6'=; B.# ,*44*60$D 3-*)#(1-# #N34'0$& .*6
%* )-#'%# '$ #"#$% .'$(4#- ,*- '$ '3340)'%0*$24#"#4 #"#$%;
B* )-#'%# '$ '3340)'%0*$24#"#4 #"#$% .'$(4#-I
!" F$ S0&1'4 T%1(0*M 0$ T*41%0*$ !N34*-#-M -0D.%2)40)C E3340)'%0*$;N'+4 90$ S0&1'4 Q'&0): *-
E33;N'+4 90$ ?V: '$( ).**&# S0#6 ?*(# %* *3#$ %.# )*(# >4# ,*- %.# BHH408,#0!(
*/Y#)%;
#" ?-#'%# ' +#%.*( %* .'$(4# %.# #"#$%M '& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Private Sub App_Startup(ByVal sender As Object, _
ByVal e As StartupEventArgs)
' Handle event here
End Sub
;/27C-'!D'1Q'1!0-
void App_Startup(object sender, StartupEventArgs e)
{
// Handle the event here
}
www.it-ebooks.info
G#&&*$ HI ?*$>D1-0$D !"#$%& '$( !"#$% J'$(40$D !"#$%&'(' +*
$" F$ ^E@G "0#6 ,*- %.# BHH408,#0!( */Y#)%M '(( %.# #"#$% .'$(4#- %* %.# E3340)'%0*$
(#)4'-'%0*$M '& &.*6$ 0$ /*4( .#-#I
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml" Startup="App_Startup">
%&'()*(+ R34K897'M8?L'&36?1A'%>19?;
F$ %.0& 3-')%0)#M =*1 1&# -*1%#( #"#$%&; \*1 )-#'%# #"#$% .'$(4#-& ,*- %.# 3$J#5!J?3$J#7F,(-$%
#"#$% 0$ %.-## )*$%-*4& 0$ %.# "0&1'4 %-## '$( */&#-"# .*6 %.# #"#$% 0& -'0&#( '$( .'$(4#( /=
#'). *$#;
+,+&(*-+ 1"-/)$%&'/%'+,-%)'O/%0C-"
!" F$ S0&1'4 T%1(0*M )-#'%# ' $#6 578 '3340)'%0*$;
#" 8-*+ %.# %**4/*NM (-'D ' 3$J#5!J&'$( %.-## ,%0!5"##!(&)*$%-*4& *$%* %.# (#&0D$
&1-,')#; A*%# %.'% '% %.0& 3*0$%M %.#&# )*$%-*4& '-# )*$%'0$#( /= ' 2.0%&)*$%-*4 %.'% 0&
0$ 0%, )*$%'0$#( 0$ %.# %*324#"#4 /0(%!1&)*$%-*4; B.1&M '$= /1//40$D #"#$%& -'0&#(
/= %.# 3$J#5!J&)*$%-*4 6044 /1//4# 13 >-&% %* %.# 2.0%&)*$%-*4 '$( %.#$ %* %.# /0(%!1
)*$%-*4;
$" F$ ^E@G "0#6M &#% %.# (0&34'= )*$%#$%& *, %.# ,%0!5"##!( )*$%-*4& '& ,*44*6&I
&"EGD0S$$DH DH$%H$
,%0!5"##!(K J'$(4# B#N%/*N;B#N%?.'$D#( 0$ B#N%Q*N
,%0!5"##!(L J'$(4# B#N%/*N;B#N%?.'$D#( 0$ ]-0(
,%0!5"##!(M J'$(4# B#N%/*N;B#N%?.'$D#( 0$ 50$(*6
." F$ %.# ^E@G ,*- %.# 3$J#5!J )*$%-*4M Y1&% /#,*-# %.# abM %=3# $1T? L@971A '$( %.#$
3-#&& %.# B'/ C#= %60)#; E$ #$%-= ,*- '$ #"#$% .'$(4#- 0& )-#'%#( '$( ' )*--#&3*$(0$D
+#%.*( 0& )-#'%#( 0$ %.# )*(#; B.# #"#$%2.'$(4#- #$%-= &.*14( 4**C 40C# %.# ,*44*60$DI
TextChanged="TextBox1_TextChanged"
/" F$ %.# ^E@G ,*- %.# 2.0% )*$%-*4M %=3# $1T?03T0@;1U$1T? L@971A '$( %.#$ 3-#&& %.#
B'/ C#= %60)# %* D#$#-'%# '$ #"#$% .'$(4#-; B.# '((#( ^E@G &.*14( 4**C 40C# %.0&I
TextBoxBase.TextChanged="Grid_TextChanged"
0" F$ %.# ^E@G ,*- %.# /0(%!1 )*$%-*4M %=3# $1T?03T0@;1U$1T? L@971A '$( %.#$ 3-#&&
%.# B'/ C#= %60)# %* D#$#-'%# '$ #"#$% .'$(4#-; B.# '((#( ^E@G &.*14( 4**C 40C# %.0&I
TextBoxBase.TextChanged="Window_TextChanged"
www.it-ebooks.info
'+/ !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
1" F$ ?*(# "0#6M '(( %.# ,*44*60$D )*(# %* %.# 3$J#<!JKG3$J#7F,(-$% +#%.*(I
;/27C-'!D'P$.=/C'M/.$6'1!0-
MessageBox.Show("Event raised by Textbox")
e.Handled = RadioButton1.IsChecked
;/27C-'!D'1Q'1!0-
MessageBox.Show("Event raised by Textbox");
e.Handled = (bool)radioButton1.IsChecked;
2" E(( %.# ,*44*60$D )*(# %* %.# 2.0%G3$J#7F,(-$% +#%.*(I
;/27C-'!D'P$.=/C'M/.$6'1!0-
MessageBox.Show("Event raised by Grid")
e.Handled = RadioButton2.IsChecked
;/27C-'!D'1Q'1!0-
MessageBox.Show("Event raised by Grid");
e.Handled = (bool)radioButton2.IsChecked;
3" E(( %.# ,*44*60$D )*(# %* %.# /0(%!1G3$J#7F,(-$% +#%.*(I
;/27C-'!D'P$.=/C'M/.$6'1!0-
MessageBox.Show("Event raised by Window")
e.Handled = RadioButton3.IsChecked
;/27C-'!D'1Q'1!0-
MessageBox.Show("Event raised by Window");
e.Handled = (bool)radioButton3.IsChecked;
!4" 7-#&& 8c %* /104( '$( -1$ =*1- '3340)'%0*$; 50%.*1% >-&% #)%0$D '$= *, %.# *3%0*$&M
%=3# ' 4#%%#- 0$ %.# %#N% /*N? B.-## +#&&'D# /*N#& '-# (0&34'=#(M #'). *$# 0$(0)'%0$D
%.# )*$%-*4 %.'% -'0&#( %.# #"#$%; \*1 )'$ .'$(4# %.# #"#$% /= ).**&0$D *$# *, %.#
/1%%*$ *3%0*$& %* .'4% #"#$% /1//40$D 0$ %.# #"#$% .'$(4#-&;
9-..!%';=22/"<■ 578 '3340)'%0*$& 0$%-*(1)# ' $#6 C0$( *, #"#$% )'44#( -*1%#( #"#$%&M 6.0). '-# -'0&#(
/= 578 )*$%-*4&;
■ B.#-# '-# %.-## C0$(& *, -*1%#( #"#$%&I (0-#)%M /1//40$DM '$( %1$$#40$D; W0-#)% #"#$%&
'-# -'0&#( *$4= /= %.# )*$%-*4 0$ 6.0). %.#= *-0D0$'%#; Q1//40$D '$( %1$$#40$D #"#$%&
'-# -'0&#( /= %.# )*$%-*4 0$ 6.0). %.#= *-0D0$'%# '$( '44 )*$%-*4& %.'% '-# .0D.#- 0$ %.#
"0&1'4 %-##;
■ E %1$$#40$D #"#$% 0& -'0&#( >-&% /= %.# %*324#"#4 )*$%-*4 0$ %.# "0&1'4 %-## '$( %1$$#4&
(*6$ %.-*1D. %.# %-## 1$%04 0% 0& >$'44= -'0&#( /= %.# )*$%-*4 0$ 6.0). 0% *-0D0$'%#&; E
/1//40$D #"#$% 0& -'0&#( >-&% /= %.# )*$%-*4 0$ 6.0). %.# #"#$% *-0D0$'%#& '$( %.#$
/1//4#& 13 %.-*1D. %.# "0&1'4 %-## 1$%04 0% 0& >$'44= -'0&#( /= %.# %*324#"#4 )*$%-*4 0$
%.# "0&1'4 %-##;
www.it-ebooks.info
G#&&*$ HI ?*$>D1-0$D !"#$%& '$( !"#$% J'$(40$D !"#$%&'(' +)
■ \*1 )'$ '%%'). #"#$%& %.'% #N0&% 0$ )*$%'0$#( )*$%-*4& %* )*$%-*4& %.'% '-# .0D.#- 0$ %.#
"0&1'4 %-##;
■ B.# *'$(#+,(,-$. )4'&& #N3*&#& +#%.*(& &* =*1 )'$ +'$'D# #"#$%&
0$ =*1- '3340)'%0*$; \*1 )'$ -#D0&%#- ' $#6 -*1%#( #"#$% /= 1&0$D %.#
*'$(#+,(,-$.?& $-0)#$. !"#$%*'$(# )4'&&; \*1 )'$ )-#'%# ' )4'&&24#"#4 #"#$% .'$(4#- /=
1&0$D *'$(#+,(,-$.? $-0)#$.74,))C,(%4$.?
■ B.# BHH408,#0!( */Y#)% -'0&#& &#"#-'4 #"#$%& %.'% )'$ /# .'$(4#( %* #N#)1%# )*(# '%
"'-0*1& 3*0$%& 0$ %.# '3340)'%0*$[& 40,#%0+#; \*1 )'$ .'$(4# '3340)'%0*$24#"#4 #"#$%& 0$
%.# )*(# ,*- %.# BHH408,#0!( */Y#)%;
9-..!%'K-,$-(\*1 )'$ 1&# %.# ,*44*60$D O1#&%0*$& %* %#&% =*1- C$*64#(D# *, %.# 0$,*-+'%0*$ 0$ G#&&*$ HM
P?*$>D1-0$D !"#$%& '$( !"#$% J'$(40$D;R B.# O1#&%0*$& '-# '4&* '"'04'/4# *$ %.# )*+3'$0*$
?W *, %.0& /**C 0, =*1 3-#,#- %* -#"0#6 %.#+ 0$ #4#)%-*$0) ,*-+;
(&)!' "HFR%&F
H%.(-".')!')*-.-'S=-.)$!%.'/%0'-37C/%/)$!%.'!D'(*<'-/6*'/%.(-"'6*!$6-'$.'6!""-6)'!"'$%6!"G
"-6)'/"-'C!6/)-0'$%')*-'TH%.(-".U'.-6)$!%'/)')*-'-%0'!D')*-'4!!#E'
!" T133*&# =*1 .'"# %.# ,*44*60$D ^E@G )*(#I
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
ButtonBase.Click="Window_Click">
<Grid ButtonBase.Click="Grid_Click">
<StackPanel Margin="47,54,31,108" Name="stackPanel1"
ButtonBase.Click="stackPanel1_Click">
<Button Height="23" Name="button1" Width="75">Button</Button>
</StackPanel>
</Grid>
</Window>
5.0). +#%.*( 0& #N#)1%#( >-&% 6.#$ <"##!(K 0& )40)C#(Z
'"& 5"##!(KG74089
5"& E#,89>,($4KG74089
("& 2.0%G74089
6"& /0(%!1G74089
#" T133*&# =*1 .'"# %.# ,*44*60$D ^E@G )*(#I
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" MouseDown="Window_MouseDown">
(&)! "HFR%&F
H%.(-".')!')*-.-'S=-.)$!%.'/%0'-37C/%/)$!%.'!D'(*<'-/6*'/%.(-"'6*!$6-'$.'6!""-6)'!"'$%6!"G
"-6)'/"-'C!6/)-0'$%')*-'TH%.(-".U'.-6)$!%'/)')*-'-%0'!D')*-'4!!#E'
www.it-ebooks.info
'++ !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
<Grid PreviewMouseDown="Grid_PreviewMouseDown">
<StackPanel Margin="47,54,31,108" Name="stackPanel1"
PreviewMouseDown="stackPanel1_PreviewMouseDown">
<Button Click="button1_Click" Height="23" Name="button1"
Width="75">Button</Button>
</StackPanel>
</Grid>
</Window>
5.0). +#%.*( 6044 /# #N#)1%#( >-&% 6.#$ <"##!(K 0& )40)C#(Z
& '"& /0(%!1G+!")$:!1(
& 5"& 2.0%G>.$'0$1+!")$:!1(
& ("& )#,89>,($4KG>.$'0$1+!")$:!1(
& 6"& <"##!(KG74089
$" \*1 '-# 6-0%0$D '$ '3340)'%0*$ %.'% )*$&0&%& *, ' &0$D4# 578 60$(*6; \*1 .'"# )*(#
=*1 6'$% %* #N#)1%# 6.#$ %.# 60$(*6 >-&% '33#'-& '$( #"#-= %0+# %.# 60$(*6 0& ')%02
"'%#(; 5.0). '3340)'%0*$ #"#$% *- #"#$%& &.*14( =*1 .'$(4# %* '))*+340&. %.0& D*'4Z
& '"& B8#0',#$%
& 5"& E#,.#"H
& ("& B8#0',#$% '$( E#,.#"H
& 6"& :$,8#0',#$% '$( E#,.#"H
www.it-ebooks.info
G#&&*$ KI ?*$>D1-0$D ?*++'$(& !"#$%&'(' +,
:1;;39'(<' 39=764897' 3VV@9A;
578 0$%-*(1)#& $#6 */Y#)%& )'44#( 8!NN,(%)? ?*++'$(& -#3-#&#$% .0D.24#"#4 %'&C& %.'%
'-# 3#-,*-+#( 0$ %.# '3340)'%0*$; >,)#$ 0& '$ #N'+34# *, ' )*++'$(d 0% -#3-#&#$%& %.# %'&C *,
)*3=0$D '$ */Y#)% ,-*+ %.# )403/*'-( 0$%* ' )*$%'0$#-; 578 3-*"0(#& ' )*.#&0"# '-).0%#)%1-#
,*- )-#'%0$D )*++'$(&M '&&*)0'%0$D %.#+ 60%. '3340)'%0*$ %'&C&M '$( .**C0$D %.*&# )*+2
+'$(& 13 %* 1&#- 0$%#-,')# 9XF: #4#+#$%&; F$ %.0& 4#&&*$M =*1 6044 4#'-$ %* 1&# %.# /104%20$ )*+2
+'$( 40/-'-=M '&&*)0'%# %.#&# )*++'$(& 60%. XF #4#+#$%&M (#>$# )*++'$( .'$(4#-&M '(( '
D#&%1-# %* ' )*++'$(M '$( (#>$# )1&%*+ )*++'$(&;
HD)-"')*$.'C-..!%@'<!='($CC'4-'/4C-')!8
■ !N34'0$ %.# (0,,#-#$% 3'-%& *, ' )*++'$(;
■ E&&*)0'%# ' )*++'$( 60%. ' XF #4#+#$%;
■ E(( ' D#&%1-# %* ' )*++'$(;
■ !N#)1%# ' )*++'$(;
■ E&&*)0'%# ' )*++'$( 60%. ' )*++'$( .'$(4#-;
■ W0&'/4# ' )*++'$(;
■ ?-#'%# ' )1&%*+ )*++'$(;
+.)$2/)-0'C-..!%')$2-8'IJ'2$%=)-.
?*++'$(&M &1). '& 7"#M 7!HAM '$( >,)#$M -#3-#&#$% %'&C&; F$ 3'&% "#-&0*$& *, %.# ;A!B
8-'+#6*-CM %.#-# 6'& $* )*+34#%# '-).0%#)%1-# ,*- '&&*)0'%0$D )*(# 60%. %'&C&; 8*- #N2
'+34#M &133*&# =*1 6'$%#( %* 0+34#+#$% ' >,)#$ %'&C 0$ =*1- '3340)'%0*$; \*1 6*14( )-#'%#
%.# )*(# %* #N#)1%# %.# %'&C '$( %.#$ '&&*)0'%# =*1- XF #4#+#$% 60%. %.'% )*(# "0' #"#$%&;
\*1 +0D.% .'"# ' +$("O#$N #4#+#$% %.'% %-0DD#-& %.# )*(# 6.#$ #)%#(; \*1 '4&* +0D.%
.'"# )*$%#N% +#$1 0%#+& '$( 3#-.'3& #"#$ ' 5"##!( )*$%-*4; F$ 3'&% "#-&0*$& *, %.# ;A!B
8-'+#6*-CM =*1 6*14( .'"# .'( %* )-#'%# #"#$% .'$(4#-& ,*- #'). )*$%-*4 60%. 6.0). =*1
6'$%#( %* '&&*)0'%# %.# %'&C; F$ '((0%0*$M =*1 6*14( .'"# .'( %* 0+34#+#$% )*(# %* 0$')%02
"'%# #'). *, %.#&# )*$%-*4& 0, %.# %'&C 6'& 1$'"'04'/4#; E4%.*1D. $*% '$ 0+3*&&0/4# %'&CM (*0$D
%.0& -#O10-#& %#(0*1& )*(0$D %.'% )'$ /# ,-'1D.% 60%. #--*-&;
?*++'$(& #$'/4# =*1 %* 1&# ' )#$%-'40e#( '-).0%#)%1-# ,*- %'&C&; \*1 )'$ '&&*)0'%# '$=
$1+/#- *, XF )*$%-*4& *- 0$31% D#&%1-#& 60%. ' )*++'$( '$( /0$( %.'% )*++'$( %* ' .'$2
(4#- %.'% 0& #N#)1%#( 6.#$ )*$%-*4& '-# ')%0"'%#( *- D#&%1-#& '-# 3#-,*-+#(; ?*++'$(& '4&*
C##3 %-')C *, 6.#%.#- %.#= '-# '"'04'/4#; F, ' )*++'$( 0& (0&'/4#(M XF #4#+#$%& '&&*)0'%#(
60%. %.'% )*++'$( '-# (0&'/4#(M %**;
?*++'$( '-).0%#)%1-# )*$&0&%& *, ,*1- 3-0$)03'4 3'-%&; B.# 7!NN,(% */Y#)% -#3-#&#$%&
%.# %'&C; B.#-# '-# '4&* )*++'$( &*1-)#&; E 8!NN,(%&)!".8$ 0& ' )*$%-*4 *- D#&%1-# %.'%
%-0DD#-& %.# )*++'$( 6.#$ 0$"*C#(; B.# 8!NN,(%&F,(%4$. 0& ' +#%.*( #N#)1%#( 6.#$ %.#
)*++'$( 0& 0$"*C#(M '$( 7!NN,(%50(%0(- 0& '$ */Y#)% %.# ;A!B 8-'+#6*-C 1&#& %* %-')C
6.0). )*++'$(& '-# '&&*)0'%#( 60%. 6.0). &*1-)#& '$( .'$(4#-&;
HD)-"')*$.'C-..!%@'<!='($CC'4-'/4C-')!8
■ !N34'0$ %.# (0,,#-#$% 3'-%& *, ' )*++'$(;
■ E&&*)0'%# ' )*++'$( 60%. ' XF #4#+#$%;
■ E(( ' D#&%1-# %* ' )*++'$(;
■ !N#)1%# ' )*++'$(;
■ E&&*)0'%# ' )*++'$( 60%. ' )*++'$( .'$(4#-;
■ W0&'/4# ' )*++'$(;
■ ?-#'%# ' )1&%*+ )*++'$(;
+.)$2/)-0'C-..!%')$2-8'IJ'2$%=)-.
www.it-ebooks.info
',. !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
B.# ;A!B 8-'+#6*-C 3-*"0(#& &#"#-'4 3-#(#>$#( )*++'$(& (#"#4*3#-& )'$ 1&#; B.#&#
/104%20$ )*++'$(& '-# &%'%0) */Y#)%& %.'% '-# 3-*3#-%0#& *, >"# &%'%0) )4'&&#&M 6.0). '-# %.#
,*44*60$DI
■ BHH408,#0!(7!NN,(%)&
■ 7!NH!($(#7!NN,(%)&
■ *%0#0(-7!NN,(%)&
■ +$%0,7!NN,(%)&
■ P,'0-,#0!(7!NN,(%)&
!'). *, %.#&# )4'&&#& #N3*&#& ' "'-0#%= *, &%'%0) )*++'$( */Y#)%& %.'% =*1 )'$ 1&# 0$ =*1-
'3340)'%0*$&; E4%.*1D. &*+# *, %.#&# )*++'$(& .'"# (#,'14% 0$31% /0$(0$D& 9,*- #N'+34#M
%.# BHH408,#0!(7!NN,(%)?DH$( )*++'$( .'& ' (#,'14% /0$(0$D %* %.# ?%-4f` C#= )*+/0$'2
%0*$:M $*$# *, %.#&# )*++'$(& .'& '$= 0$.#-#$% ,1$)%0*$'40%=d =*1 +1&% )-#'%# /0$(0$D& '$(
.'$(4#-& ,*- %.#&# )*++'$(& %* 1&# %.#+ 0$ =*1- '3340)'%0*$;
H'O$&*G9-,-C'>"!6-0="-'D!"'A27C-2-%)$%&'/'1!22/%0B.# ,*44*60$D &#)%0*$ (#&)-0/#& ' .0D.24#"#4 3-*)#(1-# ,*- 0+34#+#$%0$D )*++'$( ,1$)%0*$2
'40%=; B.# &%#3& *, %.0& 3-*)#(1-# '-# (0&)1&&#( 0$ D-#'%#- (#%'04 0$ %.# &1/&#O1#$% &#)%0*$&;
B* 0+34#+#$% ' )*++'$(I
!" W#)0(# *$ %.# )*++'$( %* 1&#M 6.#%.#- 0% 0& *$# *, %.# &%'%0) )*++'$(& #N3*&#( /=
%.# ;A!B 8-'+#6*-C *- ' )1&%*+ )*++'$(;
#" E&&*)0'%# %.# )*++'$( 60%. '$= )*$%-*4& 0$ %.# 1&#- 0$%#-,')# '$( '(( '$= (#&0-#(
0$31% D#&%1-#& %* %.# )*++'$(;
$" ?-#'%# ' +#%.*( %* .'$(4# %.# )*++'$(;
." ?-#'%# ' 7!NN,(%50(%0(- )*$%-*4 %.'% /0$(& %.# 7!NN,(% */Y#)% %* %.# )*++'$(
.'$(4#- '$(M *3%0*$'44=M %* ' +#%.*( %.'% .'$(4#& 7!NN,(%?7,(*J$8"#$?
/" E(( %.# )*++'$( /0$(0$D %* %.# 7!NN,(%) )*44#)%0*$ *, %.# )*$%-*4 *- /0(%!1
)*$%-*4 6.#-# %.# )*++'$( 0& 0$"*C#(;
A%,!#$%&'1!22/%0.E,%#- ' )*++'$( .'& /##$ 0+34#+#$%#(M =*1 )'$ 0$"*C# 0% /= '&&*)0'%0$D 0% 60%. ' )*$%-*4M
1&0$D ' D#&%1-#M *- 0$"*C0$D 0% (0-#)%4= ,-*+ )*(#;
H..!6$/)$%&'1!22/%0.'($)*'1!%)"!C.
@'$= 578 )*$%-*4& 0+34#+#$% %.# O7!NN,(%E!".8$ 0$%#-,')#M 6.0). #$'/4#& %.#+ %* /#
'&&*)0'%#( 60%. ' )*++'$( %.'% 0& >-#( '1%*+'%0)'44= 6.#$ %.'% )*$%-*4 0& 0$"*C#(; 8*- #N'+2
34#M 5"##!( '$( +$("O#$N )*$%-*4& 0+34#+#$% O7!NN,(%E!".8$ '$( %.1& #N3*&# ' 7!NN,(%
www.it-ebooks.info
G#&&*$ KI ?*$>D1-0$D ?*++'$(& !"#$%&'(' ,-
3-*3#-%=; 5.#$ %.0& 3-*3#-%= 0& &#% %* ' )*++'$(M %.'% )*++'$( 0& #N#)1%#( '1%*+'%0)'44=
6.#$ %.# )*$%-*4 0& )40)C#(; \*1 )'$ &#% ' )*++'$( ,*- ' )*$%-*4 0$ ^E@GM '& &.*6$ .#-#I
<Button Command="ApplicationCommands.Find" Height="23"
HorizontalAlignment="Right" Margin="0,0,38,80" Name="Button3"
VerticalAlignment="Bottom" Width="75">Button</Button>
A%,!#$%&'1!22/%0.'($)*'V-.)="-.
\*1 '4&* )'$ -#D0&%#- +*1&# '$( C#=/*'-( D#&%1-#& 60%. 7!NN,(% */Y#)%& %.'% 0$"*C# %.#
)*++'$( 6.#$ %.*&# D#&%1-#& *))1-; B.# ,*44*60$D #N'+34# )*(# &.*6& .*6 %* '(( '
+*1&# D#&%1-# '$( ' C#=/*'-( D#&%1-# %* %.# O(H"#2$)#".$) )*44#)%0*$ *, %.# BHH408,#0!(?=0(%
)*++'$(I
;/27C-'!D'P$.=/C'M/.$6'1!0-
ApplicationCommands.Find.InputGestures.Add(New _
MouseGesture(MouseAction.LeftClick, ModifierKeys.Control))
ApplicationCommands.Find.InputGestures.Add(New _
KeyGesture(Key.Q, ModifierKeys.Control))
;/27C-'!D'1Q'1!0-
ApplicationCommands.Find.InputGestures.Add(new
MouseGesture(MouseAction.LeftClick, ModifierKeys.Control));
ApplicationCommands.Find.InputGestures.Add(new
KeyGesture(Key.Q, ModifierKeys.Control));
E,%#- %.# )*(# 0$ %.# 3-#"0*1& #N'+34# 0& #N#)1%#(M %.# =0(% )*++'$( #N#)1%#& #0%.#-
6.#$ %.# ?%-4 C#= 0& .#4( (*6$ '$( %.# 4#,% +*1&# /1%%*$ 0& )40)C#( *- 6.#$ %.# ?%-4 C#= '$(
%.# g C#= '-# .#4( (*6$ '% %.# &'+# %0+# 9?%-4fg:;
A%,!#$%&'1!22/%0.'D"!2'1!0-
\*1 +0D.% 6'$% %* 0$"*C# ' )*++'$( (0-#)%4= ,-*+ )*(#M &1). '& 0$ -#&3*$&# %* '$ #"#$% 0$ '
)*$%-*4 %.'% (*#& $*% #N3*&# ' 7!NN,(% 3-*3#-%=; B* 0$"*C# ' )*++'$( (0-#)%4=M &0+34= )'44
%.# 7!NN,(%?*J$8"#$ +#%.*(M '& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
ApplicationCommands.Find.Execute(aParameter, TargetControl)
;/27C-'!D'1Q'1!0-'
ApplicationCommands.Find.Execute(aParameter, TargetControl);
F$ %.0& #N'+34#M ,>,.,N$#$. -#3-#&#$%& '$ */Y#)% %.'% )*$%'0$& '$= -#O10-#( 3'-'+#%#-
('%' ,*- %.# )*++'$(; F, $* 3'-'+#%#- 0& $##(#(M =*1 )'$ 1&# ("44 9P!#F0(- 0$ S0&1'4 Q'&0):;
3,.-$#7!(#.!4 0& ' )*$%-*4 6.#-# %.# )*++'$( *-0D0$'%#&; B.# -1$ %0+# 6044 &%'-% 4**C0$D ,*-
7!NN,(%50(%0(-) 0$ %.0& )*$%-*4 '$( %.#$ /1//4# 13 %.-*1D. %.# "0&1'4 %-## 1$%04 0% >$(& '$
'33-*3-0'%# 7!NN,(%50(%0(-;
www.it-ebooks.info
',( !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
1!22/%0'O/%0C-".'/%0'1!22/%0'M$%0$%&.E& &%'%#( 3-#"0*1&4=M Y1&% 0$"*C0$D ' )*++'$( (*#&$[% ')%1'44= (* '$=%.0$D; ?*++'$(& -#32
-#&#$% %'&C&M /1% %.#= (* $*% )*$%'0$ '$= *, %.# )*(# ,*- %.# %'&C& %.#= -#3-#&#$%; B* #N#)1%#
)*(# 6.#$ ' )*++'$( 0& 0$"*C#(M =*1 +1&% )-#'%# ' 7!NN,(%50(%0(- %.'% /0$(& %.# )*+2
+'$( %* ' )*++'$( .'$(4#-;
1!22/%0'O/%0C-".
E$= +#%.*( 60%. %.# )*--#)% &0D$'%1-# )'$ /# ' )*++'$( .'$(4#-; ?*++'$( .'$(4#-& .'"#
%.# ,*44*60$D &0D$'%1-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Private Sub myCommandHandler(ByVal sender As Object, _
ByVal e As ExecutedRoutedEventArgs)
' Handle the command here
End Sub
;/27C-'!D'1Q'1!0-
private void myCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
// Handle the command here
}
*J$8"#$% !"#$%*'$(#B.-) 0& (#-0"#( ,-*+ !"#$%*'$(#B.-) '$( %.1& #N3*&#& '44 %.#
+#+/#-& !"#$%*'$(#B.-) (*#&; F$ '((0%0*$M 0% #N3*&#& ' 7!NN,(% 3-*3#-%= %.'% -#%1-$& %.#
7!NN,(% */Y#)% /#0$D .'$(4#(;
1!22/%0'M$%0$%&.
B.# 7!NN,(%50(%0(- */Y#)% 3-*"0(#& %.# D41# %.'% .*4(& %.# 6.*4# )*++'$( '-).0%#)%1-#
%*D#%.#-; E 7!NN,(%50(%0(- */Y#)% '&&*)0'%#& ' )*++'$( 60%. ' )*++'$( .'$(4#-; E((0$D
' 7!NN,(%50(%0(- */Y#)% %* %.# 7!NN,(%50(%0(-) )*44#)%0*$ *, %.# 60$(*6 *- ' )*$%-*4
-#D0&%#-& %.# 7!NN,(%50(%0(- */Y#)% '$( #$'/4#& %.# )*++'$( .'$(4#- %* /# )'44#( 6.#$
%.# )*++'$( 0& 0$"*C#(; B.# ,*44*60$D )*(# (#+*$&%-'%#& .*6 %* )-#'%# '$( -#D0&%#- '
7!NN,(%50(%0(- */Y#)%I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Dim abinding As New CommandBinding()
abinding.Command = ApplicationCommands.Find
AddHandler abinding.Executed, AddressOf myCommandHandler
Me.CommandBindings.Add(abinding)
;/27C-'!D'1Q'1!0-
CommandBinding abinding = new CommandBinding();
abinding.Command = ApplicationCommands.Find;
abinding.Executed += new ExecutedRoutedEventHandler(myCommandHandler);
this.CommandBindings.Add(abinding);
www.it-ebooks.info
G#&&*$ KI ?*$>D1-0$D ?*++'$(& !"#$%&'(' ,O
F$ %.# 3-#)#(0$D #N'+34#M =*1 >-&% )-#'%# ' $#6 7!NN,(%50(%0(- */Y#)%; \*1 %.#$
'&&*)0'%# %.'% 7!NN,(%50(%0(- */Y#)% 60%. ' 7!NN,(% */Y#)%; A#N%M =*1 &3#)0,= %.#
)*++'$( .'$(4#- %* /# #N#)1%#( 6.#$ %.# )*++'$( 0& 0$"*C#(M '$( >$'44=M =*1 '(( %.#
7!NN,(%50(%0(- */Y#)% %* %.# 7!NN,(%50(%0(-) )*44#)%0*$ *, %.# 60$(*6? B.1&M 0, '$ */Y#)%
0$ %.# 60$(*6 0$"*C#& %.# )*++'$(M %.# )*--#&3*$(0$D )*++'$( .'$(4#- 6044 /# #N#)1%#(;
\*1 '4&* )'$ (#>$# )*++'$( /0$(0$D& (0-#)%4= 0$ %.# ^E@G; \*1 )'$ )-#'%# ' $#6 /0$(2
0$D '$( (#)4'-'%0"#4= &#% %.# )*++'$( 60%. 6.0). 0% 0& '&&*)0'%#( '4*$D 60%. %.# '&&*)02
'%#( .'$(4#-&; B.# ,*44*60$D #N'+34# (#+*$&%-'%#& ' $#6 7!NN,(%50(%0(- */Y#)% 0$ %.#
7!NN,(%50(%0(-) )*44#)%0*$ *, %.# 60$(*6 %.'% '&&*)0'%#& %.# BHH408,#0!(?=0(% )*++'$(
60%. ' .'$(4#-I
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.Find"
Executed="myCommandHandler" />
</Window.CommandBindings>
1!22/%0'M=44C$%&
E44 )*$%-*4& .'"# %.#0- *6$ 7!NN,(%50(%0(-) )*44#)%0*$ 0$ '((0%0*$ %* %.# 60$(*6[&
7!NN,(%50(%0(-) )*44#)%0*$; B.0& 0& /#)'1&# )*++'$(&M 40C# -*1%#( #"#$%&M /1//4# 13
%.-*1D. %.# "0&1'4 %-## 6.#$ %.#= '-# 0$"*C#(; ?*++'$(& 4**C ,*- ' /0$(0$D >-&% 0$
%.# 7!NN,(%50(%0(-) )*44#)%0*$ *, %.# )*$%-*4 0$ 6.0). %.#= *-0D0$'%# '$( %.#$ 0$ %.#
7!NN,(%50(%0(-) )*44#)%0*$& *, )*$%-*4& .0D.#- *$ %.# "0&1'4 %-##; G0C# !"#$%*'$(#M
=*1 )'$ &%*3 ,1-%.#- 3-*)#&&0$D *, %.# )*++'$( /= &#%%0$D %.# C,(%4$% 3-*3#-%= *, %.#
*J$8"#$% !"#$%*'$(#B.-) 3'-'+#%#- %* 3."$M '& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Private Sub myCommandHandler(ByVal sender As Object, _
ByVal e As ExecutedRoutedEventArgs)
' Stops further Command bubbling
e.Handled = True
End Sub
;/27C-'!D'1Q'1!0-
private void myCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
// Handle the command here
e.Handled = true;
}
!*"+$),-
M=44C$%&'/%0')=%%-C$%&'/"-'%-('6!%6-7).')!' >?'/%0'7C/<'$27!")/%)'"!C-.'4!)*'$%'6!2G
2/%0.'/%0'*!(' >?'*/%0C-.'"!=)-0'-,-%).E'M-'6-")/$%')*/)'<!='=%0-".)/%0')*-'6!%6-7).'
!D'4=44C$%&'/%0')=%%-C$%&'-,-%).'/%0'4=44C$%&'6!22/%0.'D!"')*-'-3/2E'K-2-24-"')*/)'/'
6!22/%0'!"'-,-%)'0!-.%W)'%--0')!'4-'*/%0C-0'4<')*-'./2-'-C-2-%)'$%'(*$6*'$)'!"$&$%/)-.E
www.it-ebooks.info
',P !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
L$./4C$%&'1!22/%0.
E$= )*++'$( %.'% 0& $*% '&&*)0'%#( 60%. ' )*++'$( /0$(0$D 0& '1%*+'%0)'44= (0&'/4#(; A*
')%0*$ 0& %'C#$ 6.#$ %.'% )*++'$( 0& 0$"*C#(M '$( '$= )*$%-*4 6.*&# 7!NN,(% 3-*3#-%= 0&
&#% %* %.'% )*++'$( '33#'-& '& (0&'/4#(; J*6#"#-M %.#-# +0D.% /# %0+#& 6.#$ =*1 6'$% %*
(0&'/4# ' )*++'$( %.'% 0& 0$ 34')# '$( '&&*)0'%#( 60%. )*$%-*4& '$( )*++'$( /0$(0$D&? 8*-
#N'+34#M =*1 +0D.% 6'$% %.# >.0(# )*++'$( %* /# (0&'/4#( 1$%04 %.# ,*)1& 0& *$ ' (*)1+#$%;
B.# )*++'$( '-).0%#)%1-# #$'/4#& =*1 %* (#&0D$'%# ' +#%.*( %* .'$(4# %.# 7!NN,(%?
7,(*J$8"#$ #"#$%; B.# 7,(*J$8"#$ #"#$% 0& -'0&#( '% "'-0*1& 3*0$%& 0$ %.# )*1-&# *, '3340)'2
%0*$ #N#)1%0*$ %* (#%#-+0$# 6.#%.#- ' )*++'$( 0& 0$ ' &%'%# %.'% 6044 '44*6 #N#)1%0*$;
@#%.*(& %.'% .'$(4# %.# 7,(*J$8"#$ #"#$% 0$)41(# '$ 0$&%'$)# *,
7,(*J$8"#$ !"#$%*'$(#B.-) '& ' 3'-'+#%#-; B.0& )4'&& #N3*&#& ' 3-*3#-%= )'44#( 7,(*J$8"#$
%.'% 0& ' Q**4#'$ "'41#; F, 7,(*J$8"#$ 0& %-1#M %.# )*++'$( )'$ /# 0$"*C#(; F, 0% 0& ,'4&#M %.#
)*++'$( 0& (0&'/4#(; \*1 )'$ )-#'%# ' +#%.*( %.'% .'$(4#& %.# 7,(*J$8"#$ #"#$%M (#%#-2
+0$#& 6.#%.#- %.# '3340)'%0*$ 0& 0$ '$ '33-*3-0'%# &%'%# %* '44*6 )*++'$( #N#)1%0*$M '$(
&#%& $?7,(*J$8"#$ %* %.# '33-*3-0'%# "'41#;
B* .'$(4# %.# 7,(*J$8"#$ #"#$%I
!" ?-#'%# ' +#%.*( %* .'$(4# %.# 7,(*J$8"#$ #"#$%; B.0& +#%.*( &.*14( O1#-= %.# '32
340)'%0*$ %* (#%#-+0$# 6.#%.#- %.# '3340)'%0*$[& &%'%# 0& '33-*3-0'%# %* #$'/4# %.#
)*++'$(; E$ #N'+34# 0& &.*6$ .#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
Private canExecute As Boolean
Private Sub abinding_CanExecute(ByVal sender As Object, _
ByVal e As CanExecuteRoutedEventArgs)
e.CanExecute = canExecute
End Sub
;/27C-'!D'1Q'1!0-
bool canExecute;
void abinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = canExecute;
}
F$ %.0& #N'+34#M %.# +#%.*( -#%1-$& %.# "'41# -#3-#&#$%#( /= ' 3-0"'%# "'-0'/4# )'44#(
8,(*J$8"#$? 7-#&1+'/4=M %.# '3340)'%0*$ &#%& %.0& %* =,4)$ 6.#$#"#- 0% -#O10-#& %.# )*+2
+'$( %* /# (0&'/4#(;
#" T#% %.# 7,(*J$8"#$ .'$(4#- *$ 7!NN,(%50(%0(- %* 3*0$% %* %.0& +#%.*(M '& &.*6$
.#-#I
;/27C-'!D'P$.=/C'M/.$6'1!0-
' Assumes that you have already created a CommandBinding called abinding
AddHandler abinding.CanExecute, AddressOf abinding_CanExecute
;/27C-'!D'1Q'1!0-
// Assumes that you have already created a CommandBinding called abinding
abinding.CanExecute += new CanExecuteRoutedEventHandler(abinding_CanExecute);
www.it-ebooks.info
G#&&*$ KI ?*$>D1-0$D ?*++'$(& !"#$%&'(' ,*
E4%#-$'%0"#4=M )-#'%# ' $#6 /0$(0$D 0$ ^E@G '$( &3#)0,= %.# .'$(4#- %.#-#M '& &.*6$
.#-# 0$ /*4(I
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.Find"
Executed="CommandBinding_Executed"
CanExecute="abinding_CanExecute" />
</Window.CommandBindings>
1"-/)$%&'1=.)!2'1!22/%0.E4%.*1D. ' 60(# "'-0#%= *, 3-##N0&%0$D )*++'$(& 0& '% =*1- (0&3*&'4M =*1 +0D.% 6'$% %* )-#2
'%# =*1- *6$ )1&%*+ )*++'$(&; B.# /#&% 3-')%0)# ,*- )1&%*+ )*++'$(& 0& %* ,*44*6 %.# #N2
'+34# &#% 0$ %.# ;A!B 8-'+#6*-C '$( )-#'%# &%'%0) )4'&&#& 90$ ?V: *- +*(14#& 90$ S0&1'4 Q'&0):
%.'% #N3*&# &%'%0) 0$&%'$)#& *, %.# )1&%*+ )*++'$(; B.0& 3-#"#$%& %.# )-#'%0*$& *, +14%034#
0$&%'$)#& *, %.# )*++'$(; \*1 '4&* )'$ 3-*"0(# '$= )1&%*+ )*$>D1-'%0*$ ,*- %.# )*++'$(
0$ %.# &%'%0) )*$&%-1)%*- *, %.# )4'&&h,*- #N'+34#M 0, =*1 6'$% %* +'3 '$= 0$31% D#&%1-#&
%* %.# )*++'$(; B.# ,*44*60$D #N'+34# &.*6& .*6 %* )-#'%# ' &%'%0) )4'&& %.'% #N3*&#& ' )1&2
%*+ )*++'$( )'44#( ;,"(8FQ
;/27C-'!D'P$.=/C'M/.$6'1!0-
Public Module MyCommands
Private launch_command As RoutedUICommand
Sub New()
Dim myInputGestures As New InputGestureCollection
myInputGestures.Add(New KeyGesture(Key.L, ModifierKeys.Control))
launch_command = New RoutedUICommand("Launch", "Launch", _
GetType(MyCommands), myInputGestures)
End Sub
Public ReadOnly Property Launch() As RoutedUICommand
Get
Return launch_command
End Get
End Property
End Module
;/27C-'!D'1Q'1!0-
public class MyCommands
{
private static RoutedUICommand launch_command;
static MyCommands()
{
InputGestureCollection myInputGestures = new
InputGestureCollection();
myInputGestures.Add(new KeyGesture(Key.L, ModifierKeys.Control));
launch_command = new RoutedUICommand("Launch", "Launch",
typeof(MyCommands), myInputGestures);
}
public RoutedUICommand Launch
{
get
{
www.it-ebooks.info
',/ !"#$%&'( 5*-C0$D 60%. !"#$%& '$( ?*++'$(&
return launch_command;
}
}
}
F$ %.0& #N'+34#M ' &%'%0) )4'&& *- +*(14# 0& )-#'%#( %* )*$%'0$ %.# )1&%*+ )*+2
+'$(M 6.0). 0& #N3*&#( %.-*1D. ' -#'(2*$4= 3-*3#-%=; F$ %.# &%'%0) )*$&%-1)%*-M ' $#6
O(H"#2$)#".$7!44$8#0!( )*44#)%0*$ 0& )-#'%#( '$( ' C#= D#&%1-# 0& '((#( %* %.# )*44#)%0*$;
B.0& )*44#)%0*$ 0& %.#$ 1&#( %* 0$0%0'40e# %.# 0$&%'$)# *, !"#$%IO7!NN,(% %.'% 0& -#%1-$#(
%.-*1D. %.# -#'(2*$4= 3-*3#-%=;
X.$%&'1=.)!2'1!22/%0.'$%'YH:9
!"#$%&'(%)*+#%,$#*"#-%*%,(."'/%,'//*0-1%&'(%*$#%$#*-&%"'%(.#%2"%20%,'-#3%4!%&'(%5*0"%"'%(.#%
2"%20%6 781%)'5#+#$1%&'(%*9.'%/(."%/*:%")#%0*/#.:*,#%")*"%,'0"*20.%")#%,(."'/%,'//*0-%
"'%*0%6 78%0*/#.:*,#3%;)#%!'99'520<%:$',#-($#%-#.,$2=#.%)'5%"'%(.#%*%,(."'/%,'//*0-%
20%6 783
;'%(.#%*%,(."'/%,'//*0-%20%6 78>
!"% ?$#*"#%&'($%,(."'/%,'//*0-%*.%-#.,$2=#-%:$#+2'(.9&3
#"% --%*%0*/#.:*,#%/*::20<%"'%&'($% !"#$%%6 783%;)#%!'99'520<%#@*/:9#%-#/'0A
."$*"#.%)'5%"'%/*:%*%0*/#.:*,#%,*99#-% &'(&&)!*+,!$"-./012,$30$33+"#2/%B'"#%
")*"1%20%")2.%#@*/:9#1%")*"%5'(9-%/#*0%&'($%,(."'/%,'//*0-.%*$#%C#:"%20%*%.#:*$*"#%
0*/#.:*,#>
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:CustomCommands="clr-namespace:WpfApplication13.CustomCommands"
Title="Window1" Height="300" Width="300">
<!—The rest of the XAML is omitted-->
</Window>
$"% D.#%")#%0#59&%/*::#-%6 78%0*/#.:*,#%20%&'($%6 78%,'-#1%*.%.)'50%)#$#>
<Button Command="CustomCommands:MyCommands.Launch" Height="23"
HorizontalAlignment="Left" Margin="60,91,0,0" Name="Button1"
VerticalAlignment="Top" Width="75">Button</Button>
%&'()*(+ !"#$%&'(#( )*$+,( +,,#&-
40%")2.%:$*,"2,#1%&'(%,$#*"#%*%,(."'/%,'//*0-%*0-%")#0%,'00#,"%&'($%,'//*0-%"'%D4%#9#A
/#0".%=&%(.20<%*%,'//*0-%=20-20</%
+,+&(*-+ ! !"#$%&'(#( )*$+,( +,,#&-
!"% E$'/%")#%?F1%':#0%")#%:*$"2*9%.'9("2'0%!'$%")2.%#@#$,2.#3%
www.it-ebooks.info
% 8#..'0%G>%?'0H<($20<%?'//*0-.% ./0123(4( 56
#"% E$'/%")#%I$'J#,"%/#0(1%,)''.#% --%?9*..%K20%?LM%'$% --%7'-(9#%K20%N2.(*9%O*.2,M3%
B*/#%")#%0#5%2"#/% )*$+, +,,#&-*%*0-%,92,C%PQ3%R#"%")#%*,,#..%/'-2H#$%'!%")2.%
,9*..%'$%/'-(9#%"'%:(=92,3
$"% 4!%&'(%*$#%5'$C20<%20%?L1%*--%")#%!'99'520<%12!"4%."*"#/#0"%"'%&'($%,9*..>
using System.Windows.Input;
P")#$52.#1%<'%'0%"'%R"#:%S3
."% --%*%$#*-A'09&%:$':#$"&%0*/#-%7#)&89%*0-%*%,'$$#.:'0-20<%/#/=#$%+*$2*=9#%")*"%
$#"($0.%*0%20."*0,#%'!%*%5$1,6#780$33+"#9%*.%.)'50%)#$#3%KB'"#%")*"%")#.#%.)'(9-%=#%
."*"2,%/#/=#$.%20%?L3M
.#,/0"(+1(2%*)#0(3#*%4( +-"
Private launch_command As RoutedUICommand
Public ReadOnly Property Launch() As RoutedUICommand
Get
Return launch_command
End Get
End Property
.#,/0"(+1( 5( +-"
private static RoutedUICommand launch_command;
public static RoutedUICommand Launch
{
get
{
return launch_command;
}
}
/"% --%*%,'0."$(,"'$%"'%&'($%/'-(9#%K20%N2.(*9%O*.2,M%'$%*%."*"2,%,'0."$(,"'$%"'%&'($%,9*..%
K20%?LM%")*"%,$#*"#.%*%0#5%8"&1,:62,1;60$))6*,!$"%,'99#,"2'01%*--.%*0%*::$':$2*"#%20:("%
<#."($#%"'%=#%*..',2*"#-%52")%")2.%0#5%,'//*0-1%*0-%")#0%202"2*92T#.%")#%/#/=#$%+*$2A
*=9#%")*"%$#"($0.%")#%,(."'/%,'//*0-1%*.%.)'50%)#$#>
.#,/0"(+1(2%*)#0(3#*%4( +-"
Sub New()
Dim myInputGestures As New InputGestureCollection
myInputGestures.Add(New KeyGesture(Key.L, ModifierKeys.Control))
launch_command = New RoutedUICommand("Launch", "Launch", _
GetType(CustomCommands), myInputGestures)
End Sub
.#,/0"(+1( 5( +-"
static CustomCommands()
{
InputGestureCollection myInputGestures = new
InputGestureCollection();
myInputGestures.Add(new KeyGesture(Key.L, ModifierKeys.Control));
launch_command = new RoutedUICommand("Launch", "Launch",
typeof(CustomCommands), myInputGestures);
}
www.it-ebooks.info
(5: ./0123(4 U'$C20<%52")%V+#0".%*0-%?'//*0-.
0"% E$'/%")#%O(29-%/#0(1%,)''.#%O(29-%R'9("2'0%"'%=(29-%&'($%.'9("2'03
+,+&(*-+ # 6*%&'(7+)!( )*$+,( +,,#&-
!"% 40%6 78%+2#51%*--%")#%!'99'520<%,'-#%"'%&'($%U20-'5%/*$C(:%"'%,$#*"#%*%$#!#$#0,#%"'%
")#%,9*..%")*"%,'0"*20.%&'($%,(."'/%,'//*0->
xmlns:Local="clr-namespace:YourProjectNamespaceGoesHere"
;)#%:$#+2'(.%,'-#%20%='9-%.)'(9-%=#%$#:9*,#-%52")%")#%0*/#.:*,#%0*/#%'!%&'($%
%:$'J#,"3
#"% 40%6 78%+2#51%*--%")#%!'99'520<%*""$2=("#%"'%='")%&'($%<1,,$"%,'0"$'9%*0-%&'($%=+1"*>%
7#0(4"#/>
Command="Local:CustomCommands.Launch"
$"% 40%")#% !"#$%-%,'-#%+2#51%*--%")#%!'99'520<%/#")'->
.#,/0"(+1(2%*)#0(3#*%4( +-"
Private Sub Launch_Handler(ByVal sender As Object, _
ByVal e As ExecutedRoutedEventArgs)
MessageBox.Show("Launch invoked")
End Sub
.#,/0"(+1( 5( +-"
private void Launch_Handler(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Launch invoked");
}
."% E$'/%")#%"''9='@1%-$*<%*%0>6*?<$@%,'0"$'9%'0"'%")#%!'$/3%R#"%")#%,'0"#0"%'!%")#%,'0A
"$'9%"'%2&#;<"(7#)&89( +,,#&-3
/"% 40%")#%,'-#%+2#5%!'$% !"#$%-1%*--%")#%!'99'520<%/#")'->
.#,/0"(+1(2%*)#0(3#*%4( +-"
Private Sub LaunchEnabled_Handler(ByVal sender As Object, _
ByVal e As CanExecuteRoutedEventArgs)
e.CanExecute = CheckBox1.IsChecked
End Sub
.#,/0"(+1( 5( +-"
private void LaunchEnabled_Handler(object sender,
CanExecuteRoutedEventArgs e)
{
e.CanExecute = (bool)checkBox1.IsChecked;
}
0"% ?$#*"#%'$%$#:9*,#%")#%,'0."$(,"'$%!'$% !"#$%-%")*"%,$#*"#.%*0-%$#<2."#$.%*%,'//*0-%
=20-20<%!'$%")#%=+1"*>%,'//*0-3%;)2.%,'//*0-%=20-20<%.)'(9-%=20-%")#%=+1"*>/
A@6*1,6#%#+#0"%"'%")#%=+1"*>BC+"#)6;%/#")'-%*0-%=20-%")#%=+1"*>/0+"A@6*1,6%#+#0"%
"'%")#%=+1"*>A"+D)6#BC+"#)6;%/#")'-3% 0%#@*/:9#%2.%.)'50%)#$#>
www.it-ebooks.info
% 8#..'0%G>%?'0H<($20<%?'//*0-.% ./0123(4( 55
.#,/0"(+1(2%*)#0(3#*%4( +-"
Public Sub New()
InitializeComponent()
Dim abinding As New CommandBinding()
abinding.Command = CustomCommands.Launch
AddHandler abinding.Executed, AddressOf Launch_Handler
AddHandler abinding.CanExecute, AddressOf LaunchEnabled_Handler
Me.CommandBindings.Add(abinding)
End Sub
.#,/0"(+1( 5( +-"
public Window1()
{
InitializeComponent();
CommandBinding abinding = new CommandBinding();
abinding.Command = CustomCommands.Launch;
abinding.Executed += new ExecutedRoutedEventHandler(Launch_Handler);
abinding.CanExecute += new
CanExecuteRoutedEventHandler(LaunchEnabled_Handler);
this.CommandBindings.Add(abinding);
}
1"% I$#..%EW%"'%=(29-%*0-%$(0%&'($%*::92,*"2'03%U)#0%")#%*::92,*"2'0%."*$".1%")#%O(""'0%*0-%
8*(0,)%/#0(%2"#/.%*$#%-2.*=9#-3%R#9#,"%")#%,)#,C%='@%"'%#0*=9#%")#%,'//*0-3%B'5%
&'(%,*0%20+'C#%")#%,'//*0-%!$'/%")#%=(""'01%!$'/%")#%/#0(1%'$%=&%(.20<%")#%?"$9X8%
20:("%<#."($#3%
8"**+&(.),,#!9■% ?'//*0-.%:$'+2-#%*%,#0"$*9%*$,)2"#,"($#%!'$%/*0*<20<%)2<)A9#+#9%"*.C.3%;)#%3BV;%
E$*/#5'$C%:$'+2-#.%*%92=$*$&%'!%=(29"A20%,'//*0-.%")*"%/*:%"'%,'//'0%"*.C.%")*"%
,*0%=#%(.#-%20%&'($%*::92,*"2'0.3
■% ?'//*0-.%,*0%=#%20+'C#-%-2$#,"9&1%=&%*0%20:("%<#."($#%.(,)%*.%E$126:62,1;6%'$%
%F6G:62,1;61%'$%=&%*,"2+*"20<%*%,(."'/%,'0"$'93% %.20<9#%,'//*0-%,*0%=#%*..',2*"#-%
52")%*0&%0(/=#$%'!%<#."($#.%'$%,'0"$'9.3
■% ?'//*0-%=20-20<.%*..',2*"#%,'//*0-.%52")%,'//*0-%)*0-9#$.3%Y'(%,*0%.:#,2!&%*%
/#")'-%"'%)*0-9#%")#%A@6*1,6#%#+#0"%'!%*%,'//*0-%*0-%*0'")#$%/#")'-%"'%)*0-9#%
")#%0+"A@6*1,6%#+#0"%'!%*%,'//*0-3%
■% 7#")'-.%)*0-920<%")#%0+"A@6*1,6%#+#0"%'!%*%,'//*0-%.)'(9-%.#"%")#%0+"A@6*1,6%
:$':#$"&%'!%0+"A@6*1,65$1,6#AH6",(;42%"'%I+)26%5)#0%")#%,'//*0-%.)'(9-%=#%
%-2.*=9#-3
■% ?'//*0-.%,*0%=#%='(0-%=&%*0&%0(/=#$%'!%,'//*0-%=20-20<./%?'//*0-.%#@)2=2"%
=(==920<%=#)*+2'$3%U)#0%20+'C#-1%,'//*0-.%H$."%9''C%!'$%*%=20-20<%20%")#%,'99#,"2'0%
'!%")#%#9#/#0"%20%5)2,)%")#%,'//*0-%5*.%20+'C#-%*0-%")#0%9''C%20%#*,)%)2<)#$%#9#A
/#0"%20%")#%+2.(*9%"$##3
www.it-ebooks.info
!"#$%&'(' )*+
!" # $ % & ' (
!"#$%&'($)*'+,-"./-0%-1'2!%)"!3,
! "#$%&' ()*'*#+,+"%# -%.#$,+"%# /!(-0 ,#$ !"#$%&' -%)1' 2%+3 4)%5"$* '.44%)+ 6%)
7)*,+"#8 9%.) %&# 7%#+)%:' &3*# +3* 4)*;2.":+ 7%#+)%:' $% #%+ 4)%5"$* +3* )*<.")*$
6.#7+"%#,:"+9 6%) 9%.) ,44:"7,+"%#= ># +3"' 73,4+*)? 9%. :*,)# 3%& +% 7)*,+* 7.'+%1 7%#+)%:' "#
2%+3 !"#$%&' -%)1' ,#$ !(- ,#$ .'*) 7%#+)%:' "# !"#$%&' -%)1' ,#$ 3%& +% *@+*#$ 4)*;
*@"'+"#8 7%#+)%:' +3)%.83 "#3*)"+,#7*= A%. ,:'% :*,)# +% *@+*#$ +3* ,44*,),#7* %6 '+,#$,)$
!(- *:*1*#+' 29 4)%5"$"#8 #*& 7%#+)%: +*14:,+*' +3,+ ,:+*) +3*") ,44*,),#7* ,#$ 2*3,5"%)
&3":* )*+,"#"#8 +3*") "#3*)*#+ 6.#7+"%#,:"+9= -"#,::9? 9%. :*,)# 3%& +% 7)*,+* 7.'+%1 !(-
7%#+)%:' 7%14:*+*:9 6)%1 +3* 2*8"##"#8=
4567'!89-:)$;-,'$%')*$,':*6<)-"='■ >14:*1*#+ .'*);$*B#*$ 7%#+)%:'=
■ C)*,+* ,#$ ,44:9 7%#+)%: +*14:,+*' "# !(-=
■ C)*,+* ,#$ ,44:9 '+9:*' ,#$ +3*1"#8 /+3*1*' %#:9 "# +3"' 73,4+*)0=
■ >14:*1*#+ $*4*#$*#79 4)%4*)+"*'=
>-,,!%,'$%')*$,':*6<)-"=
■ D*''%# EF C)*,+"#8 C%#+)%:' "# !"#$%&' -%)1' )*(
■ D*''%# GF H'"#8 C%#+)%: I*14:,+*' ),,
■ D*''%# JF C)*,+"#8 C.'+%1 C%#+)%:' "# !(- +--
www.it-ebooks.info
')*. !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
/01230'425'/0678
I% 7%14:*+* +3* :*''%#' "# +3"' 73,4+*)? 9%. 1.'+ 3,5*F
■ M 7%14.+*) +3,+ 1**+' %) *@7**$' +3* 1"#"1.1 3,)$&,)* )*<.")*1*#+' :"'+*$ "# +3*
NM2%.+ I3"' O%%KP '*7+"%# ,+ +3* 2*8"##"#8 %6 +3* 2%%K=
■ Q"7)%'%6+ R"'.,: S+.$"% GTET ()%6*''"%#,: "#'+,::*$ %# 9%.) 7%14.+*)=
■ M# .#$*)'+,#$"#8 %6 Q"7)%'%6+ R"'.,: O,'"7 %) CU '9#+,@ ,#$ 6,1":",)"+9 &"+3
Q"7)%'%6+ =VWI -),1*&%)K X=T=
■ M# .#$*)'+,#$"#8 %6 W@+*#'"2:* M44:"7,+"%# Q,)K.4 D,#8.,8* /YMQD0=
!"#$%& #'
?6))*-('@)!-:#-"
> 0%1')*6)' AB'<"!;$1-,'7!,)'!C')*-':!%)"!3,'D'%--1')!':"-6)-'7E'6<<3$:6)$!%,F'8G)')*-"-'6"-'6'C-('%!)683-'-5:-<)$!%,F'<6")$:G36"3E':!%:-"%$%&')*-'03-'1$63!&'8!5-,'
6%1',!7-'!C')*-'7!"-',<-:$63$H-1' $%1!(,'B!"7,':!%)"!3,I'B!")G%6)-3EF'$)'$,'-6,E'
)!'$%)-&"6)-')*6)'CG%:)$!%63$)E'$%)!'7E'6<<3$:6)$!%,F',!'D'1!%J)'*6;-')!',<-%1'*!G",'
"-$%;-%)$%&' $%1!(,'B!"7,':!%)"!3,'!"':"-6)$%&':!7<3-5'(!"#6"!G%1,I
!"#$%& #'
?6))*-('@)!-:#-"
> 0%1')*6)' AB'<"!;$1-,'7!,)'!C')*-':!%)"!3,'D'%--1')!':"-6)-'7E'6<<3$:6)$!%,F'8G)')*-"-'6"-'6'C-('%!)683-'-5:-<)$!%,F'<6")$:G36"3E':!%:-"%$%&')*-'03-'1$63!&'8!5-,'
6%1',!7-'!C')*-'7!"-',<-:$63$H-1' $%1!(,'B!"7,':!%)"!3,I'B!")G%6)-3EF'$)'$,'-6,E'
)!'$%)-&"6)-')*6)'CG%:)$!%63$)E'$%)!'7E'6<<3$:6)$!%,F',!'D'1!%J)'*6;-')!',<-%1'*!G",'
"-$%;-%)$%&' $%1!(,'B!"7,':!%)"!3,'!"':"-6)$%&':!7<3-5'(!"#6"!G%1,I
www.it-ebooks.info
D*''%# EF C)*,+"#8 C%#+)%:' "# !"#$%&' -%)1' !"#$%&'(' )*(
90::28';<' 30=>786' 28>32?:'78'@78A2B:'C23D:
!"#!$%&'()!*&+!,$ ,)* +3* '"14:*'+ 6%)1 %6 .'*);7)*,+*$ 7%#+)%:'= I3* 7%14%'"+* 7%#+)%:
$*'"8#*) "#7:.$*' , 8),43"7,: "#+*)6,7* '"1":,) +% , !"#$%&' 6%)1 +3,+ 9%. 7,# .'* +% ,$$
4)**@"'+"#8 7%#+)%:' ,#$ 7%14%#*#+'? &3"73 9%. +3*# 2"#$ +%8*+3*) "# , '"#8:* 6.#7+"%#,:
.#"+= ># +3"' :*''%#? 9%. :*,)# '%1* 8*#*),: 1*+3%$' 6%) 7%#+)%: $*5*:%41*#+ ,' &*:: ,' 3%&
+% 7)*,+* , 7%14%'"+* 7%#+)%:=
KC)-"')*$,'3-,,!%F'E!G'($33'8-'683-')!=
■ L*5*:%4 , .'*) /7%14%'"+*0 !"#$%&' -%)1' 7%#+)%:=
■ C)*,+* 4)%4*)+"*'? 1*+3%$'? ,#$ *5*#+' 6%) !"#$%&' -%)1' 7%#+)%:'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%&' -%)1' 7%#+)%:'=
■ W@4%'* 4)%4*)+"*' %6 7%#'+"+.*#+ 7%#+)%:'=
■ C%#B8.)* , 7%#+)%: +% 2* "#5"'"2:* ,+ ).# +"1*=
■ C%#B8.)* , 7%#+)%: +% 3,5* , +),#'4,)*#+ 2,7K8)%.#$=
■ ()%5"$* , I%%:2%@ 2"+1,4 6%) , 7%#+)%:=
■ L*5*:%4 ,# *@+*#$*$ 7%#+)%: /"#3*)"+*$ 6)%1 ,# *@"'+"#8 !"#$%&' -%)1'
7%#+)%:0=
4,)$76)-1'3-,,!%')$7-='LM'7$%G)-,
www.it-ebooks.info
')*I !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
I% ,$$ , 7%14%'"+* 7%#+)%: +% , '%:.+"%# ,+ $*'"8# +"1*F
!" -)%1 +3* ()%Z*7+ 1*#.? 73%%'* M$$ H'*) C%#+)%:= I3* M$$ V*& >+*1 $",:%8 2%@ %4*#'=
#" V,1* 9%.) 7%#+)%: ,#$ 7:"7K M$$= I3* #*& 7%#+)%: "' ,$$*$ +% +3* 4)%Z*7+ ,#$ %4*#*$
6%) *$"+"#8 "# +3* $*'"8#*)=
A%. 7,# 7)*,+* , 7%14%'"+* 7%#+)%: "# 7%$* 29 "#3*)"+"#8 6)%1 +3* .$'+ !*&+!, 7:,''? ,'
'3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Public Class myControl
Inherits UserControl
' Add implementation here
End Class
@67<3-'!C'2P'2!1-
public class myControl : UserControl
{
// Add implementation here
}
I3* '.2%)$"#,+* 7%#+)%:' +3,+ 1,K* .4 +3* 7%14%'"+* 7%#+)%: ,)* 7,::*$ 7%#'+"+.*#+
7%#+)%:'= A%. 7,# ,$$ 7%#'+"+.*#+ 7%#+)%:' +% 9%.) 7%14%'"+* 7%#+)%: "# +3* ',1* &,9 9%.
&%.:$ ,$$ , 7%#+)%: +% , 6%)1F 29 $),88"#8 "+ %#+% +3* $*'"8# '.)6,7* 6)%1 +3* I%%:2%@= I3*#
9%. 7,# 7%#B8.)* +3*'* 7%#'+"+.*#+ 7%#+)%:' "# +3* ',1* &,9 9%. &%.:$ 7%#B8.)* +3*1 "#
, 6%)1F 29 '*++"#8 4)%4*)+"*'? ,:+*)"#8 +3* ,44*,),#7*? ,#$ 7)*,+"#8 1*+3%$' +3,+ 3,#$:*
7%#+)%: *5*#+'= !3*# +3* 7%14%'"+* 7%#+)%: "' 2.":+? +3* 6.#7+"%#,:"+9 9%. 3,5* 7%$*$ &":: 2*
2.":+ "#+% "+=
K11$%&'?-)*!1,F'A"!<-")$-,F'6%1'4;-%),')!'2!%)"!3,
># ,$$"+"%# +% ,$$"#8 7%#'+"+.*#+ 7%#+)%:'? 9%. 7,# ,:'% ,$$ 6.#7+"%#,:"+9 +% 9%.) 7%#+)%: "#
+3* 6%)1 %6 1*+3%$'? 4)%4*)+"*'? ,#$ *5*#+'=
(&)!' 9"JJ%JK' LM$&L9JK'"MN' LO#LJE$%' LM$&L9J
Q*-'$%C!"76)$!%'$%')*$,',-:)$!%':6%'8-'6<<3$-1')!':36,,-,'6%1':!%)"!3,'!C'633')E<-,F'%!)'9G,)'
)!':!7<!,$)-':!%)"!3,I
K//DRS'?4QTU/@'QU'K'2URQVU>
A%. 7,# ,$$ , 1*+3%$ +% , 7%#+)%: "# +3* ',1* &,9 +3,+ 9%. &%.:$ ,$$ , 1*+3%$ +% , 6%)1
%) +% ,#9 %+3*) 7:,''= !"+3"# +3* 2%.#$' %6 +3* 7:,'' $*7:,),+"%# "# +3* C%$* &"#$%&? ,$$ +3*
1*+3%$ $*7:,),+"%# ,#$ +3* 1*+3%$ 2%$9= -%) , 1*+3%$ +3,+ $%*' #%+ )*+.)# , 5,:.*? 7)*,+*
, /-0 /R"'.,: O,'"70 %) , 1!%2(/CU0 1*+3%$? ,' '3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Public Sub DisplayString(ByVal aString As String)
Msgbox(aString)
End Sub
(&)! 9"JJ%JK' LM$&L9JK'"MN' LO#LJE$%' LM$&L9J
Q*-'$%C!"76)$!%'$%')*$,',-:)$!%':6%'8-'6<<3$-1')!':36,,-,'6%1':!%)"!3,'!C'633')E<-,F'%!)'9G,)'
)!':!7<!,$)-':!%)"!3,I
www.it-ebooks.info
D*''%# EF C)*,+"#8 C%#+)%:' "# !"#$%&' -%)1' !"#$%&'(' )**
@67<3-'!C'2P'2!1-
public void DisplayString(string aString)
{
MessageBox.Show(aString);
}
-%) 1*+3%$' +3,+ )*+.)# , 5,:.*? 7)*,+* , 3-*)&%!* /R"'.,: O,'"70 %) '4*7"69 , )*+.)# +94*
/CU0? ,' '3%&# "# +3"' *@,14:*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Public Function DisplayString(ByVal aString As String, ByVal bString As String) As
String
Return aString & bString
End Function
@67<3-'!C'2P'2!1-
public string DisplayString(string aString, string bString)
{
return aString + bString;
}
K//DRS'AVUA4VQD4@'QU'K'2URQVU>
M$$"#8 , 4)%4*)+9 "' '"1":,) +% ,$$"#8 , 1*+3%$= A%. 7)*,+* , 4)%4*)+9 $*B#"+"%# ,#$ +3*#
"14:*1*#+ +3* 6.#7+"%#,:"+9 )*<.")*$ +% )*+.)# ,#$ '*+ +3* 5,:.* )*4)*'*#+*$ 29 +3* 4)%4*)+9=
H'.,::9? +3* .#$*):9"#8 5,:.* 6%) +3* 4)%4*)+9 "' '+%)*$ "# , 4)"5,+* 1*12*) 5,)",2:*= ># R"'.,:
O,'"7? 9%. .'* +3* 4+!#'+&5 K*9&%)$ +% 7)*,+* , 4)%4*)+9= ># CU? 9%. '"14:9 "14:*1*#+ +3*
8*++*) ,#$ '*++*) 6%) +3* 4)%4*)+9= I3* 6%::%&"#8 *@,14:* $*1%#'+),+*' 3%& +% "14:*1*#+ ,
4)%4*)+9? "#7:.$"#8 , 1*12*) 5,)",2:* +% 7%#+,"# +3* 5,:.*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Private mUnitsOnHand
Public Property UnitsOnHand() As Integer
Get
Return mUnitsOnHand
End Get
Set(ByVal value As Integer)
mUnitsOnHand = value
End Set
End Property
@67<3-'!C'2P'2!1-
private int mUnitsOnHand;
public int UnitsOnHand
{
get { return mUnitsOnHand; }
set { mUnitsOnHand = value; }
}
www.it-ebooks.info
')*, !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
A%. 7,# 7)*,+* , )*,$;%#:9 4)%4*)+9 29 .'"#8 +3* 6'728*,5 K*9&%)$ "# R"'.,: O,'"7 %) 29
%1"++"#8 +3* '*++*) "# CU= M# *@,14:* "' '3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Private mUnitsOnHand
Public ReadOnly Property UnitsOnHand() As Integer
Get
Return mUnitsOnHand
End Get
End Property
@67<3-'!C'2P'2!1-
private int mUnitsOnHand;
public int UnitsOnHand
{
get { return mUnitsOnHand; }
}
>6 9%. ,)* 7)*,+"#8 , )*,$;%#:9 4)%4*)+9? 9%. 1.'+ '*+ +3* 1*12*) 5,)",2:* +3,+ )*4)*'*#+'
+3* 4)%4*)+9\' 5,:.* "# 7%$*=
K//DRS'4N4RQ@'QU'K'2URQVU>
A%. 7,# ,$$ +% , 7%#+)%: *5*#+' +3,+ 7,# 2* ),"'*$ +% #%+"69 +3* )*'+ %6 +3* ,44:"7,+"%# +3,+
'%1*+3"#8 "#+*)*'+"#8 3,' 3,44*#*$= ]#7* ,# *5*#+ 3,' 2**# ,$$*$ +% , 7:,'' %) 7%#+)%:? "+
7,# 2* ),"'*$ "# 7%$* +% '*#$ , #%+"B7,+"%# +% +3* )*'+ %6 +3* ,44:"7,+"%#=
># R"'.,: O,'"7? 9%. 7,# 7)*,+* ,# *5*#+ 29 .'"#8 +3* 91'*& K*9&%)$ ,#$ '4*7"69"#8 +3*
#,1* ,#$ '"8#,+.)* %6 +3* *5*#+? ,' '3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Public Event Bang(ByVal decibels As Integer)
CU? 3%&*5*)? )*<.")*' ,# *@4:"7"+ $*:*8,+* +% 2* 4)*'*#+ +% '4*7"69 +3* '"8#,+.)* 2*6%)* +3*
91'*& K*9&%)$ 7,# 2* .'*$ +% 7)*,+* , #*& *5*#+= I3* 6%::%&"#8 *@,14:* $*1%#'+),+*' 3%&
+% 7)*,+* ,# *5*#+ "# CUF
@67<3-'!C'2P'2!1-
public delegate void Sound(int decibels);
public event Sound Bang;
V%+* +3,+ 9%. '4*7"69 +3* $*:*8,+* "+'*:6? #%+ ,# "#'+,#7* %6 +3* $*:*8,+*=
A%. 7,# ),"'* ,# *5*#+ "# 7%$* 29 .'"#8 +3* 67%$'91'*& K*9&%)$ "# R"'.,: O,'"7 %) 29 7,::"#8
+3* *5*#+ :"K* 9%. &%.:$ , 1*+3%$ "# CU= M# *@,14:* "' '3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
RaiseEvent Bang(100)
@67<3-'!C'2P'2!1-
this.Bang(100);
www.it-ebooks.info
D*''%# EF C)*,+"#8 C%#+)%:' "# !"#$%&' -%)1' !"#$%&'(' )*P
45<!,$%&')*-'A"!<-")$-,'!C'2!%,)$)G-%)'2!%)"!3,
!3*# 7%#'+"+.*#+ 7%#+)%:' ,)* ,$$*$ +% , 7%14%'"+* 7%#+)%:? +3*9 ,)* 8"5*# ,# ,77*'' :*5*:
%6 3+%'*2 29 $*6,.:+ "# R"'.,: O,'"7 ,#$ #+%17&' 29 $*6,.:+ "# CU= ># 2%+3 7,'*'? +3* 7%#'+"+.*#+
7%#+)%:' &":: 2* "#,77*''"2:* +% 7:,''*' "# %+3*) ,''*12:"*'= >6 9%. &,#+ +% *#,2:* %+3*) ,';
'*12:"*' +% 7%#B8.)* 4,)+' %6 +3* 7%#'+"+.*#+ 7%#+)%:'? 9%. 1.'+ *@4%'* +3* 4)%4*)+"*' %6 +3*
7%#'+"+.*#+ 7%#+)%:' 29 &),44"#8 +3*1 "# , 4)%4*)+9 $*7:,),+"%# ,#$ +3*# &)"+"#8 7%$* "# +3*
4)%4*)+9 %6 +3* 7%14%'"+* 7%#+)%: +% 8*+ ,#$ '*+ +3* 5,:.* %6 +3* 4)%4*)+9 %6 +3* 7%#'+"+.*#+
7%#+)%:= -%) *@,14:*? '.44%'* 9%. &,#+*$ +% *@4%'* +3* :7); !,!+ 4)%4*)+9 %6 , 7%#'+"+.;
*#+ 2.++%#= A%. 1"83+ 7)*,+* , 4)%4*)+9 "# +3* 7%14%'"+* 7%#+)%: 7,::*$ :-&&!*:7); !,!+? "#
&3"73 9%. )*+.)# +3* :7); !,!+ 4)%4*)+9 %6 +3* 7%#'+"+.*#+ 2.++%# "# +3* 8*++*) ,#$ '*+ +3*
7%#'+"+.*#+(:7); !,!+ 4)%4*)+9 %6 +3* 2.++%#("# +3* '*++*)= M# *@,14:* %6 3%& 9%. 1"83+
"14:*1*#+ +3"' "' '3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Public Property ButtonBackColor() As System.Drawing.Color
Get
Return Button1.BackColor
End Get
Set(ByVal value As System.Drawing.Color)
Button1.BackColor = value
End Set
End Property
@67<3-'!C'2P'2!1-
public System.Drawing.Color ButtonBackColor
{
get { return Button1.BackColor; }
set { Button1.BackColor = value; }
}
2!%0&G"$%&'6'2!%)"!3')!'O-'D%;$,$83-'6)'VG%'Q$7-
M+ +"1*'? 9%. 1"83+ &,#+ 9%.) 7%#+)%: +% 2* "#5"'"2:* ,+ ).# +"1*= A%. 7,# 7)*,+* ,# "#5"'"2:*
7%#+)%: 29 '*++"#8 +3* <%$%0,' 4)%4*)+9 +% 37,$'= C%#+)%:' +3,+ ,)* "#5"'"2:* 7,##%+ "#+*),7+ &"+3
+3* .'*) +3)%.83 +3* H>? 2.+ +3*9 7,# '+":: "#+*),7+ &"+3 +3* ,44:"7,+"%# ,#$ %+3*) 7%#+)%:'= I3*
6%::%&"#8 *@,14:* $*1%#'+),+*' 3%& +% '*+ +3* <%$%0,' 4)%4*)+9 +% 37,$'F
@67<3-'!C'N$,G63'O6,$:'2!1-
myUserControl.Visible = False
@67<3-'!C'2P'2!1-
myUserControl.Visible = false;
V%+* +3,+ 9%. 7,# '*+ +3* <%$%0,' 4)%4*)+9 %#:9 ,+ ).# +"1*= I% *#'.)* +3,+ , 7%#+)%: "'
"#5"'"2:* ,+ '+,)+.4? '*+ +3* <%$%0,' 4)%4*)+9 +% 37,$' "# +3* 7%#+)%:\' =!72 *5*#+ 3,#$:*)=
www.it-ebooks.info
'),- !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
2!%0&G"$%&'6'2!%)"!3')!'T6;-'6'Q"6%,<6"-%)'O6:#&"!G%1
!3*# 7%#B8.)"#8 9%.) 7%#+)%: +% 3,5* , +),#'4,)*#+ 2,7K8)%.#$? 9%. 3,5* +&% +94*' %6
+),#'4,)*#7"*' +% 7%#'"$*)= M 7%#+)%: 7,# 2* +),#'4,)*#+ '% +3,+ +3* ,44*,),#7* %6 +3* 6%)1
.#$*)#*,+3 +3* 7%#+)%: "' '**# +3)%.83 +3* 2,7K8)%.#$ %6 +3* 7%#+)%:= M 7%#+)%: 7,# ,:'%
,44*,) ,' , +),#'4,)*#+ &"#$%& +3)%.83 +3* 6%)1? $"'4:,9"#8 &3,+*5*) "' %# +3* $*'K+%4
2*#*,+3 +3* 6%)1=
I% 7)*,+* , 7%#+)%: &"+3 , +),#'4,)*#+ 2,7K8)%.#$ 7%:%)? ,:: 9%. #**$ +% $% "' '*+ +3*
:7); !,!+ 4)%4*)+9 +% !,!+>?+7*$#7+'*&= !3,+*5*) "' $"'4:,9*$ %# +3* 6%)1 2*#*,+3
+3* 7%#+)%: &":: '3%& +3)%.83 +3* 2,7K8)%.#$ %6 +3* 7%#+)%:= A%. 7,# '*+ +3* :7); !,!+
+% ?+7*$#7+'*& "# +3* ()%4*)+"*' &"#$%& ,+ $*'"8# +"1*? %) 9%. 7,# '*+ +3* :7); !,!+ +%
?+7*$#7+'*+ "# 7%$*? ,' '3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Me.BackColor = Color.Transparent
@67<3-'!C'2P'2!1-
this.BackColor = Color.Transparent;
C)*,+"#8 , +),#'4,)*#+ 7%#+)%: +3,+ ,7+' ,' , &"#$%& +3)%.83 +3* 6%)1 "' , :"++:* 1%)*
7%14:*@= W,73 6%)1 3,' , 4)%4*)+9 7,::*$ ?+7*$#7+'*)5@'5? &3"73 )*4)*'*#+' , 7%:%) +3,+ ,4;
4*,)' ,' +),#'4,)*#+ &3*# )*4)*'*#+*$ %# +3* 6%)1= O9 '*++"#8 +3* :7); !,!+ 4)%4*)+9 %6 +3*
7%#+)%: +% +3* ',1* 7%:%) ,' +3* 6%)1\' ?+7*$#7+'*)5@'5 4)%4*)+9? 9%. 7,# 7)*,+* , &"#$%&
%6 +),#'4,)*#79 +3)%.83 +3* 6%)1= A%. 7,# '*+ +3* 6%)1\' ?+7*$#7+'*)5@'5 4)%4*)+9 ,#$ +3*
7%#+)%:\' :7); !,!+ 4)%4*)+9 "# +3* $*'"8#*) ,+ $*'"8# +"1* %) "# 7%$*? ,' '3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Form1.TransparencyKey = Color.Red
myUserControl.BackColor = Color.Red
@67<3-'!C'2P'2!1-
Form1.TransparencyKey = Color.Red;
myUserControl.BackColor = Color.Red;
A"!;$1$%&'6'Q!!38!5'O$)76<'C!"'W!G"'2!%)"!3
M6+*) 9%. 3,5* 2.":+ , 7%#+)%:? "+ ,.+%1,+"7,::9 ,44*,)' "# +3* I%%:2%@ "6 9%. ,)* .'"#8 "+ "# +3*
',1* '%:.+"%# +3,+ 7%#+,"#' +3* 7%#+)%:? %)? "6 "+ &,' 7)*,+*$ "# , $"66*)*#+ 4)%Z*7+? 9%. 7,# ,$$
"+ +% +3* I%%:2%@= !3*# 9%. ,$$ +3* 7%#+)%: +% +3* I%%:2%@? "+ ,44*,)' "# +3* I%%:2%@ ,' +3*
#,1* %6 +3* 7%#+)%: #*@+ +% ,# "7%#= >6 #% "7%# "' '4*7"B*$? , 8*#*)"7 "7%# "' '.44:"*$= A%. 7,#
'4*7"69 +3* "7%# $"'4:,9*$ #*@+ +% +3* #,1* %6 9%.) 7%#+)%: 29 .'"#8 ?!!,0!A:%&"7#B&&+%0-&'=
A%. 7,# ,++,73 "#'+,#7*' %6 +3* ?!!,0!A:%&"7#B&&+%0-&' 7:,'' +% 9%.) 7%#+)%: $*7:,),+"%# ,#$
.'* "+ +% '4*7"69 , E^;29;E^ 4"@*: 2"+1,4 +3,+ &":: )*4)*'*#+ 9%.) 7%#+)%: "# +3* I%%:2%@=
www.it-ebooks.info
D*''%# EF C)*,+"#8 C%#+)%:' "# !"#$%&' -%)1' !"#$%&'(' ),;
A%. 7,# '4*7"69 +3* I%%:2%@ 2"+1,4 "# +3)** &,9'= I3* 1%'+ '+),"83+6%)&,)$ &,9 "' +%
'4*7"69 +3* 4,+3 +% +3* 2"+1,4 9%. &,#+ +% .'*= _*)* "' ,# *@,14:* %6 3%& +% $% +3"'F
@67<3-'!C'N$,G63'O6,$:'2!1-
<ToolboxBitmap("C:\myToolboxBitmap.bmp")> Class myControl
Inherits UserControl
' Implementation omitted
End Class
@67<3-'!C'2P'2!1-
[ToolboxBitmap(@"C:\myToolboxBitmap.bmp")]
class myControl : UserControl
{}
A%. 7,# ,:'% .'* ?!!,0!A:%&"7# 6)%1 ,# *@"'+"#8 +94*= -%) *@,14:*? 9%. 7%.:$ '4*7"69 +3*
',1* I%%:2%@ 2"+1,4 +3,+ +3* :-&&!* 7%#+)%: .'*' &"+3 +3* 6%::%&"#8 7%$*F
@67<3-'!C'N$,G63'O6,$:'2!1-
<ToolBoxBitmap(GetType(System.Windows.Forms.Button))> Class myControl
Inherits UserControl
' Implementation omitted
End Class
@67<3-'!C'2P'2!1-
[ToolBoxBitmap(GetType(System.Windows.Forms.Button))]
class myControl : UserControl
{}
-"#,::9? 9%. 7,# '4*7"69 ,# ,''*12:9 29 '4*7"69"#8 , +94* $*B#*$ "# +3,+ ,''*12:9 ,#$
+3*# :%,$ ,# "7%# )*'%.)7* +3,+ "' '4*7"B*$ 29 , '+)"#8 #,1*? ,' '3%&# 3*)*F
@67<3-'!C'N$,G63'O6,$:'2!1-
<ToolBoxBitmap(GetType(myControl), "myControl.bmp")> Class myControl
Inherits UserControl
' Implementation omitted
End Class
@67<3-'!C'2P'2!1-
[ToolBoxBitmap(GetType(myControl), "myControl.bmp")]
class myControl : UserControl
{}
Q57RS' T0RS
!I' O"$-XE'1-0%-'6':!7<!,$)-':!%)"!3I
#I' T!(':6%'E!G'-5<!,-'<"!<-")$-,'!C':!%,)$)G-%)':!%)"!3,')!'1-;-3!<-",Y
Q57RS' T0RS
!I O"$-XE'1-0%-'6':!7<!,$)-':!%)"!3I
#I T!(':6%'E!G'-5<!,-'<"!<-")$-,'!C':!%,)$)G-%)':!%)"!3,')!'1-;-3!<-",Y
!
#
www.it-ebooks.info
'),) !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
Q57RS' T0RS'"8:B03:
!I' K':!7<!,$)-':!%)"!3F'63,!':633-1'6'G,-"':!%)"!3F'$,'761-'G<'!C'<"--5$,)$%&':!%.
)"!3,'Z:633-1':!%,)$)G-%)':!%)"!3,['8!G%1')!&-)*-"'$%'6',$%&3-'$%)-"C6:-I'2!7.
<!,$)-':!%)"!3,':6%'$%:!"<!"6)-':G,)!7'CG%:)$!%63$)E')!'-%683-')*-':!%,)$)G-%)'
:!%)"!3,')!'(!"#')!&-)*-"I
#I' W!G'-5<!,-'<"!<-")$-,'!C':!%,)$)G-%)':!%)"!3,')!'1-;-3!<-",'8E'("6<<$%&')*-7'
$%'G,-"':!%)"!3'<"!<-")$-,I
2"-6)$%&'45)-%1-1'2!%)"!3,9A&'*2'2()!*&+!,$ ,)* .'*);7)*,+*$ 7%#+)%:' +3,+ *@+*#$ , 4)**@"'+"#8 =VWI -),1*&%)K 7%#+)%:=
O9 *@+*#$"#8 *@"'+"#8 7%#+)%:'? 9%. 7,# )*+,"# ,:: +3* 6.#7+"%#,:"+9 %6 +3* 7%#+)%: &3":* ,$$"#8
4)%4*)+"*' ,#$ 1*+3%$' ,#$? "# '%1* 7,'*'? ,:+*)"#8 +3* )*#$*)*$ ,44*,),#7* %6 +3* 7%#+)%:=
45)-%1$%&'6'2!%)"!3
A%. 7,# 7)*,+* ,# *@+*#$*$ 7%#+)%: 29 7)*,+"#8 , 7:,'' +3,+ "#3*)"+' +3* 7%#+)%: "# <.*'+"%#=
I3* 6%::%&"#8 *@,14:* $*1%#'+),+*' 3%& +% 7)*,+* , 7%#+)%: +3,+ "#3*)"+' +3* :-&&!* 7:,''F
@67<3-'!C'N$,G63'O6,$:'2!1-
Public Class ExtendedButton
Inherits System.Windows.Forms.Button
End Class
@67<3-'!C'2P'2!1-
public class ExtendedButton : System.Windows.Forms.Button
{}
I3* 9A&'*2'2:-&&!* 7:,'' 7)*,+*$ "# +3* 4)*5"%.' *@,14:* 3,' +3* ',1* ,44*,),#7*? 2*;
3,5"%)? ,#$ 4)%4*)+"*' ,' +3* :-&&!* 7:,''? 2.+ 9%. 7,# #%& *@+*#$ +3"' 6.#7+"%#,:"+9 29 ,$$;
"#8 7.'+%1 4)%4*)+"*' %) 1*+3%$'= -%) *@,14:*? +3* 6%::%&"#8 *@,14:* $*1%#'+),+*' ,$$"#8
, 4)%4*)+9 7,::*$ :-&&!*<7,-' +3,+ )*+.)#' ,# "#+*8*)F
@67<3-'!C'N$,G63'O6,$:'2!1-
Public Class ExtendedButton
Inherits System.Windows.Forms.Button
Private mValue As Integer
Public Property ButtonValue() As Integer
Get
Return mValue
End Get
Set(ByVal Value As Integer)
mValue = Value
End Set
End Property
End Class
Q57RS' T0RS'"8:B03:
!I K':!7<!,$)-':!%)"!3F'63,!':633-1'6'G,-"':!%)"!3F'$,'761-'G<'!C'<"--5$,)$%&':!%.
)"!3,'Z:633-1':!%,)$)G-%)':!%)"!3,['8!G%1')!&-)*-"'$%'6',$%&3-'$%)-"C6:-I'2!7.
<!,$)-':!%)"!3,':6%'$%:!"<!"6)-':G,)!7'CG%:)$!%63$)E')!'-%683-')*-':!%,)$)G-%)'
:!%)"!3,')!'(!"#')!&-)*-"I
#I W!G'-5<!,-'<"!<-")$-,'!C':!%,)$)G-%)':!%)"!3,')!'1-;-3!<-",'8E'("6<<$%&')*-7'
$%'G,-"':!%)"!3'<"!<-")$-,I
!
#
www.it-ebooks.info
D*''%# EF C)*,+"#8 C%#+)%:' "# !"#$%&' -%)1' !"#$%&'(' ),+
@67<3-'!C'2P'2!1-
public class ExtendedButton : System.Windows.Forms.Button
{
int mValue;
public int ButtonValue
{
get
{
return mValue;
}
set
{
mValue = value;
}
}
}
U;-""$1$%&'?-)*!1,
># ,$$"+"%# +% ,$$"#8 #*& 1*+3%$' ,#$ 4)%4*)+"*' +% 9%.) 7%#+)%:? 9%. 7,# ,:'% 4)%5"$* ,
#*& "14:*1*#+,+"%# 6%) *@"'+"#8 1*+3%$' 29 %5*))"$"#8 +3*1= ]5*))"$"#8 *#,2:*' 9%. +% '.2;
'+"+.+* 9%.) %&# "14:*1*#+,+"%# 6%) +3* 2,'* "14:*1*#+,+"%# %6 , 1*+3%$ %) +% ,$$ +% +3*
6.#7+"%#,:"+9 ,:)*,$9 +3*)*= I3* 6%::%&"#8 $*1%#'+),+*' 3%& +% %5*))"$* +3* 8* ,%); 1*+3%$
"# , 7:,'' +3,+ "#3*)"+' 6)%1 :-&&!*= I3* #*& "14:*1*#+,+"%# "#7)*1*#+' , 5,)",2:* 7,::*$
,%);$ ,#$ +3*# 7,::' +3* 2,'* "14:*1*#+,+"%# %6 8* ,%);=
@67<3-'!C'N$,G63'O6,$:'2!1-
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
Clicks += 1
MyBase.OnClick(e)
End Sub
@67<3-'!C'2P'2!1-
protected override void OnClick(System.EventArgs e)
{
Clicks++;
base.OnClick(e);
}
K3)-"$%&')*-'K<<-6"6%:-'!C'6%'D%*-"$)-1'2!%)"!3
A%. 7,# 73,#8* +3* 5"'.,: ,44*,),#7* %6 '%1* 7%#+)%:' 29 %5*))"$"#8 +3* 8*47%*& 1*+3%$=
I3"' *#,2:*' 9%. +% *"+3*) ,$$ +% %) )*4:,7* +3* )*#$*)"#8 :%8"7 %6 +3* 7%#+)%:= I% ,$$ +% +3*
$*6,.:+ )*#$*)"#8 %6 +3* 7%#+)%:? 7,:: +3* C5:7$'>8*47%*& /R"'.,: O,'"70 %) 07$'>8*47%*& /CU0
1*+3%$ +% 7,:: +3* 2,'* 7:,''\' )*#$*)"#8 7%$* "# ,$$"+"%# +% 9%.) %&#= I% 4)%5"$* , 7%1;
4:*+*:9 7.'+%1 ,44*,),#7* 6%) +3* 7%#+)%:? 9%. 7,# %1"+ +3* 7,:: +% +3* 2,'* 7:,''\' 8*47%*&
1*+3%$= I3* 6%::%&"#8 *@,14:* $*1%#'+),+*' 3%& +% 7)*,+* , '"14:* *::"4+"7,: 2.++%#= V%+*?
3%&*5*)? +3,+ "+ 73,#8*' %#:9 +3* '3,4* %6 +3* 7%#+)%: ,#$ $%*' #%+ ,$$)*'' '.2+:*) )*#$*)"#8
+,'K' '.73 ,' %.+:"#"#8=
www.it-ebooks.info
'),. !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
@67<3-'!C'N$,G63'O6,$:'2!1-
Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
Dim x As New System.Drawing.Drawing2D.GraphicsPath
x.AddEllipse(0, 0, Me.Width, Me.Height)
Me.Region = New Region(x)
MyBase.OnPaint(pevent)
End Sub
@67<3-'!C'2P'2!1-
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pevent)
{
System.Drawing.Drawing2D.GraphicsPath x = new System.Drawing.Drawing2D.
GraphicsPath();
x.AddEllipse(0, 0, this.Width, this.Height);
this.Region = new Region(x);
base.OnPaint(pevent);
}
$%&'()'* 30=>0'=' 2DU2:7>0' 28>32?
># +3"' 4),7+"7*? 9%. 7)*,+* , '"14:* 7%14%'"+* 7%#+)%: +3,+ ,7+' ,' , $"8"+,: 7:%7K= A%. ,$$ ,
=70', 7%#+)%: +% 9%.) 7%14%'"+* 7%#+)%: +3,+ $"'4:,9' +3* 7%))*7+ +"1* ,#$ , ?%"'+ 7%14%#*#+
+3,+ .4$,+*' +3* =70', *5*)9 '*7%#$= -"#,::9? 9%. *@4%'* +3* 9*70,'2 4)%4*)+9 %6 +3* ?%"'+
7%#+)%: +3)%.83 9%.) 7%14%'"+* 7%#+)%: '% .'*)' 7,# *#,2:* ,#$ $"',2:* +3* 7:%7K=
*+*%'),* 2"-6)-'6'/$&$)63'23!:#
!" C)*,+* , #*& !"#$%&' -%)1' ,44:"7,+"%# "# R"'.,: S+.$"%=
#" -)%1 +3* ()%Z*7+ 1*#.? 73%%'* M$$ H'*) C%#+)%: ,#$ 7:"7K M$$ "# +3* M$$ V*& >+*1
$",:%8 2%@= M #*& .'*) 7%#+)%: "' ,$$*$ +% 9%.) 4)%Z*7+ ,#$ %4*#' "# +3* $*'"8#*)=
-" -)%1 +3* I%%:2%@? $),8 , =70', 7%#+)%: %#+% +3* .'*) 7%#+)%:= `*'"a* +3* .'*) 7%#+)%: '%
+3,+ "+ "' ,44)%@"1,+*:9 +3* '"a* %6 +3* =70', 7%#+)%:=
." -)%1 +3* I%%:2%@? $),8 , ?%"'+ 7%14%#*#+ %#+% +3* .'*) 7%#+)%:=
/" ># +3* ()%4*)+"*' &"#$%&? '*+ +3* D*&'+17, 4)%4*)+9 6%) +3* ?%"'+ 7%14%#*#+ +% ;---
,#$ +3* 9*70,'2 4)%4*)+9 +% ?+-'=
0" L%.2:*;7:"7K +3* ?%"'+ 7%14%#*#+ +% %4*# +3* C%$* &"#$%& +% +3* $*6,.:+ *5*#+ 3,#;
$:*) 6%) +3* ?%"'+>?%); *5*#+ ,#$ ,$$ +3* 6%::%&"#8 :"#* %6 7%$*F
@67<3-'!C'N$,G63'O6,$:'2!1-
Label1.Text = Now.ToLongTimeString
@67<3-'!C'2P'2!1-
label1.Text = DateTime.Now.ToLongTimeString();
www.it-ebooks.info
D*''%# EF C)*,+"#8 C%#+)%:' "# !"#$%&' -%)1' !"#$%&'(' ),(
1" ># +3* C%$* &"#$%&? ,$$ +3* 6%::%&"#8 4+!#'+&5 $*7:,),+"%#F
@67<3-'!C'N$,G63'O6,$:'2!1-
Public Property TimeEnabled() As Boolean
Get
Return Timer1.Enabled
End Get
Set(ByVal value As Boolean)
Timer1.Enabled = value
End Set
End Property
@67<3-'!C'2P'2!1-
public bool TimeEnabled
{
get { return timer1.Enabled; }
set { timer1.Enabled = value; }
}
2" -)%1 +3* -":* 1*#.? 73%%'* S,5* M:: +% ',5* 9%.) '%:.+"%#=
3" -)%1 +3* O.":$ 1*#.? 2.":$ 9%.) '%:.+"%#=
!4" ># S%:.+"%# W@4:%)*)? %4*# 3!+"E= -)%1 +3* I%%:2%@ "# +3* $*'"8#*)? $),8 .$'+ !*&+!,E
%#+% +3* 6%)1= M# "#'+,#7* %6 9%.) .'*) 7%#+)%: "' ,$$*$ +% +3* 6%)1 ,#$ 2*8"#' +%
K**4 +"1* *5*)9 '*7%#$= V%+* +3,+ 9%. 7,# 4,.'* "+ 29 '*++"#8 +3* ?%"'9*70,'2 4)%4;
*)+9 +% 37,$' "# +3* ()%4*)+"*' &"#$%&=
!!" ()*'' -[ +% 2.":$ ,#$ ).# 9%.) ,44:"7,+"%#= V%+* +3,+ +3* .'*) 7%#+)%: 6.#7+"%#' +3*
',1* &,9 ,+ ).# +"1* ,' "+ $%*' "# +3* $*'"8#*)=
>-,,!%'@G776"E■ C%14%'"+* 7%#+)%:'? ,:'% 7,::*$ .'*) 7%#+)%:'? 7%#'"'+ %6 4)**@"'+"#8 !"#$%&' -%)1'
7%#+)%:' ,#$ 7%14%#*#+' 2%.#$ +%8*+3*) 29 7%11%# 6.#7+"%#,:"+9 "# , 7%11%# H>=
C%#+)%:' +3,+ ,)* 7%#+,"#*$ "# , 7%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%')*-']K%,(-",^',-:)$!%'6)')*-'-%1'!C')*-'8!!#I
www.it-ebooks.info
D*''%# EF C)*,+"#8 C%#+)%:' "# !"#$%&' -%)1' !"#$%&'(' ),*
V A%. 1.'+ '*+ +3* D"7I' 4)%4*)+9 %6 +3* 7%#+)%: +% +3* ,44)%4)",+* 2"+1,4 6%) +3*
I%%:2%@ 2"+1,4=
NV A%. 1.'+ 7%#B8.)* +3* ?!!,0!A:%&"7# ,++)"2.+* +% '4*7"69 , 4,+3? , +94*? %) , +94*
,#$ , )*'%.)7* #,1*=
-" !3"73 %6 +3* 6%::%&"#8 ,)* )*<.")*$ +% 7)*,+* ,# *@+*#$*$ 7%#+)%:b
"V A%. 1.'+ %5*))"$* +3* 8*47%*& 1*+3%$ +% 4)%5"$* 7.'+%1 )*#$*)"#8=
/V A%. 1.'+ 4)%5"$* , I%%:2%@ 2"+1,4 6%) +3* #*& 7%#+)%:=
V A%. 1.'+ "#3*)"+ 6)%1 , 4)**@"'+"#8 7%#+)%:=
NV A%. 1.'+ *@4%'* ,#9 #*7*'',)9 4)%4*)+"*' %6 +3* "#3*)"+*$ 7%#+)%: 29 &),44"#8
+3*1 "# #*& 4)%4*)+"*'=
www.it-ebooks.info
'),, !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
90::28')<'G:786' 28>32?'$0DU?=>0:
!(- 7%#+)%:' ,)* $*'"8#*$ +% 2* :%%K:*''? &3"73 1*,#' +3,+ ,# *:*1*#+\' 6.#7+"%#,:"+9 "'
7%14:*+*:9 '*4,),+* 6)%1 +3* *:*1*#+\' ,44*,),#7*= C%#'*<.*#+:9? "+ "' *,'9 +% 4)%5"$* , #*&
H> ,44*,),#7* 6%) , !(- *:*1*#+ 29 7)*,+"#8 , #*& 7%#+)%: +*14:,+*= ># +3"' :*''%#? 9%. :*,)#
3%& +% 7)*,+* , #*& 7%#+)%: +*14:,+* 6%) , 4)**@"'+"#8 7%#+)%:=
KC)-"')*$,'3-,,!%F'E!G'($33'8-'683-')!='
■ C)*,+* ,#$ ,44:9 , #*& 7%#+)%: +*14:,+*=
■ >#'*)+ , ?+%II'+ %2Z*7+ "# , 7%#+)%: +*14:,+*=
■ M44:9 4)%4*)+"*' %6 +3* +*14:,+* 4,)*#+ "# +3* +*14:,+*=
■ M44:9 , +*14:,+* &"+3"# , /&5,'>
■ R"*& +3* '%.)7* 7%$* 6%) , 4)**@"'+"#8 +*14:,+*=
■ H'* 4)*$*B#*$ 4,)+ #,1*' "# , #*& 7%#+)%: +*14:,+*=
4,)$76)-1'3-,,!%')$7-='_`'7$%G)-,
2"-6)$%&'2!%)"!3'Q-7<36)-,M )!*&+!,(&'"#,7&' "' ,# YMQD $%7.1*#+ +3,+ $*'7)"2*' 3%& , 7%#+)%: &":: ,44*,) "# +3*
4)*'*#+,+"%# :,9*)= I3* +*14:,+* )*4)*'*#+' +3* 5"'.,: +)** %6 +3* 7%#+)%:c "+ $*B#*' ,#9 %6 +3*
4,)+' +3,+ 1,K* .4 , 7%#+)%: ,' &*:: ,' +3* ,44*,),#7* ,#$ 2*3,5"%) %6 +3%'* 4,)+'=
O*7,.'* !(- *:*1*#+' ,)* $*'"8#*$ +% 2* :%%K:*''? +3* 5"'.,: :,9*) "' $"'+"#7+ 6)%1 +3*
:%8"7,: :,9*)? ,#$ 9%. 7,# 73,#8* +3* ,44*,),#7* %6 ,#9 !(- *:*1*#+ ),$"7,::9 29 7)*,+"#8 ,
#*& +*14:,+* 6%) +3,+ *:*1*#+=
C%#+)%: +*14:,+*' ,)* $*B#*$ &"+3"# , J !*&+!,?'"#,7&'K *:*1*#+ /,' 9%. 1"83+ *@4*7+0=
I3* 6%::%&"#8 *@,14:* '3%&' , 5*)9 '"14:* 7%#+)%: +*14:,+*F
<Button Height="23" Width="100" Name="Button3">
<Button.Template>
<ControlTemplate>
<Rectangle Fill="RoyalBlue" />
</ControlTemplate>
</Button.Template>
</Button>
!3*# +3"' 7%#+)%: +*14:,+* "' ,44:"*$? +3* )*8.:,) ,44*,),#7* %6 +3* :-&&!* "' )*4:,7*$
&"+3 , 6!57,:,-' )*7+,#8:*= M:+3%.83 "+ "' #%+ 4,)+"7.:,):9 *@7"+"#8? "+ 1,"#+,"#' ,:: +3* 6.#7;
+"%#,:"+9 %6 +3* :-&&!* 7%#+)%:= A%. 7,# 7:"7K "+ +% ),"'* +3* :-&&!*> ,%); *5*#+? ,#$ "+ 1,"#+,"#'
,:: +3* 4%'"+"%#"#8 ,#$ :,9%.+ 6.#7+"%#,:"+9 %6 ,#9 %+3*) !(- *:*1*#+=
KC)-"')*$,'3-,,!%F'E!G'($33'8-'683-')!='
■ C)*,+* ,#$ ,44:9 , #*& 7%#+)%: +*14:,+*=
■ >#'*)+ , ?+%II'+ %2Z*7+ "# , 7%#+)%: +*14:,+*=?+%II'+
■ M44:9 4)%4*)+"*' %6 +3* +*14:,+* 4,)*#+ "# +3* +*14:,+*=
■ M44:9 , +*14:,+* &"+3"# , /&5,'>
■ R"*& +3* '%.)7* 7%$* 6%) , 4)**@"'+"#8 +*14:,+*=
■ H'* 4)*$*B#*$ 4,)+ #,1*' "# , #*& 7%#+)%: +*14:,+*=
4,)$76)-1'3-,,!%')$7-='_`'7$%G)-,
www.it-ebooks.info
D*''%# GF H'"#8 C%#+)%: I*14:,+*' !"#$%&'(' ),P
Q%)* 7%14:*@ +*14:,+*' ,)* 1,$* .4 %6 1.:+"4:* 4,)+'= I3* 6%::%&"#8 *@,14:* "#7:.$*'
, :!+2'+ *:*1*#+ +3,+ 7%#+,"#' +3* *::"4'* ,#$ ,44*,)' ,' , F!)!,7&' 2%)$*) ,)%.#$ +3*
6!57,:,-' )*7+,#8:*F
<Button Height="24" Name="Button3" Margin="89,0,89,61"
VerticalAlignment="Bottom">
<Button.Template>
<ControlTemplate>
<Border BorderBrush="Chocolate" BorderThickness="3">
<Rectangle Fill="RoyalBlue" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
:!+2'+ "' , 7%#+*#+ 7%#+)%:c +3.'? "+ 7,# 7%#+,"# %#:9 , '"#8:* 73":$ *:*1*#+= >6 9%. &,#+ +%
2.":$ 1.:+"4:* 5"'.,: *:*1*#+' "#+% 9%.) +*14:,+*? 9%. 1.'+ .'* , :,9%.+ 7%#+)%:? ,' '3%&# "#
+3* 6%::%&"#8 *@,14:*? &3"73 %5*):,9' , )*$ *::"4'* %#+% %.) 6!57,:,-' )*7+,#8:*F
<Button Height="67" Name="Button3" Margin="89,0,35,18"
VerticalAlignment="Bottom">
<Button.Template>
<ControlTemplate>
<Border BorderBrush="Chocolate" BorderThickness="3">
<Grid>
<Rectangle Fill="RoyalBlue" />
<Ellipse Fill="Red" />
</Grid>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
]#* 1,Z%) 7%14%#*#+ "' '+":: 1"''"#8 6)%1 +3"' +*14:,+*= I3*)* "' #% &,9 +% $"'4:,9 +3*
5,:.* %6 +3* !*&'*& 4)%4*)+9= A%. 7,# 4)%5"$* '.44%)+ 6%) +3* !*&'*& 4)%4*)+9 29 .'"#8 +3*
!*&'*&4+'$'*&'+ 7:,''? ,' '3%&# "# 2%:$ 3*)*F
<Button Height="67" Name="Button3" Margin="89,0,35,18"
VerticalAlignment="Bottom">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderBrush="Chocolate" BorderThickness="3">
<Grid>
<Rectangle Fill="RoyalBlue" />
<Ellipse Fill="Red" />
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
www.it-ebooks.info
')P- !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
I3* !*&'*&4+'$'*&'+ "' *''*#+",::9 , 4:,7*3%:$*) 6%) +3* !*&'*& 4)%4*)+9 %6 +3* *:*1*#+=
!3,+*5*) +3* 5,:.* %6 +3* !*&'*& 4)%4*)+9? "+ "' "#'*)+*$ "#+% +3* '4,7* %77.4"*$ 29 +3*
!*&'*&4+'$'*&'+> -%) =%$& 7%#+)%:'? , '"1":,) 7:,''dD&'"$4+'$'*&'+L4)*'*#+' +3* %2Z*7+' "#
+3* D&'"$ 4)%4*)+9=
V%+* ,:'% "# +3* 4)*5"%.' *@,14:* +3* ,$$"+"%# %6 +3*(?7+I'&?5#'MNAO?5#'(:-&&!*P 4)%4;
*)+9 "# +3* !*&+!,?'"#,7&' +,8= I3"' "' )*<.")*$ 6%) !*&'*&4+'$'*&'+ +% &%)K 2*7,.'* +3*
!*&'*&4+'$'*&'+ 7%#+)%: 7%#+,"#' ,# "14:"7"+ ?'"#,7&':%*2%*I 1,)K.4 +3,+ )*<.")*' +3* +,)8*+
+94* +% 2* $*B#*$= I*14:,+* 2"#$"#8' &":: 2* $"'7.''*$ :,+*) "# +3"' :*''%#= V%+* +3,+ .#:"K*
&"+3 '+9:*'Q '*++"#8 +3* ?7+I'&?5#' 4)%4*)+9 $%*' #%+ ,.+%1,+"7,::9 '*+ +3* +*14:,+* %# *:*;
1*#+' %6 +3,+ +94*= A%. 1.'+ '*+ +3* *:*1*#+\' ?'"#,7&' 4)%4*)+9? *"+3*) "# YMQD %) 29 .'"#8
'+9:*'Q ,' 9%. &":: '** :,+*) "# +3"' :*''%#=
I3* 4)*5"%.' +*14:,+* +,K*' , :-&&!* 7%#+)%: ,#$ 7%14:*+*:9 )*$*B#*' "+' 5"'.,: ,44*,);
,#7* &3":* )*+,"#"#8 ,:: "+' "#3*)*#+ 6.#7+"%#,:"+9= I3* B#,: 4)%$.7+ '+":: )*<.")*' '%1* &%)K?
3%&*5*)c +3*)* "' #% 5"'.,: 7.* &3*# +3* .'*) 1%5*' +3* 1%.'* %5*) +3* :-&&!* 7%#+)%: %)
7:"7K' "+? ,' 9%. &%.:$ '** "# , :-&&!* 7%#+)%: &"+3 +3* '+,#$,)$ ,44*,),#7*= D,+*) "# +3"' :*';
'%# 9%. &":: '** 3%& +% "14:*1*#+ +3,+ 6.#7+"%#,:"+9 ,' &*::=
2"-6)$%&'6'Q-7<36)-'6,'6'V-,!G":-
># +3* 4)*5"%.' '*7+"%#? 9%. ',& 3%& +% $*B#* , 7%#+)%: +*14:,+* "#:"#* "# , 7%#+)%:= M:+3%.83
+3"' "' +*73#"7,::9 4%''"2:*? "+ "' )*,::9 .'*6.: %#:9 6%) $*1%#'+),+"%# 4.)4%'*'= I*14:,+*' ,)*
8*#*),::9 7)*,+*$ +% 4)%5"$* , 7%11%# ,44*,),#7* 6%) 1.:+"4:* 7%#+)%:'? ,#$? +3*)*6%)*? +3*9
,)* $*B#*$ ,' )*'%.)7*' +% 6,7":"+,+* +3*") )*.'*= I% $*B#* , +*14:,+* ,' , )*'%.)7*? 9%. 1.'+
$*B#* "+ "# , 6'$!-+)' '*7+"%# ,#$ ,44:9 , @'5 4)%4*)+9? ,' '3%&# "# +3* 6%::%&"#8 *@,14:*F
<Window.Resources >
<ControlTemplate TargetType="{x:Type Button}" x:Key="ButtonTemplate">
<Border BorderBrush="Chocolate" BorderThickness="3">
<Grid>
<Rectangle Fill="RoyalBlue" />
<Ellipse Fill="Red" />
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</Border>
</ControlTemplate>
</Window.Resources>
K<<3E$%&'6'Q-7<36)-')!'6'2!%)"!3
M6+*) 9%. 3,5* $*B#*$ , +*14:,+* ,' , )*'%.)7*? 9%. 7,# ,44:9 "+ +% , 7%#+)%: 29 '*++"#8 +3*
?'"#,7&' 4)%4*)+9 +% +3,+ )*'%.)7*? ,' '3%&# 3*)*F
<Button Template="{StaticResource ButtonTemplate}" Margin="112,123,91,116"
Name="Button1">Button</Button>
www.it-ebooks.info
D*''%# GF H'"#8 C%#+)%: I*14:,+*' !"#$%&'(' )P;
D%,-")$%&'6' !"##$!%U89-:)'$%'6'Q-7<36)-S% 6,) "# +3"' :*''%#? 9%. 3,5* '**# 3%& +% 7)*,+* , +*14:,+* +3,+ 4)%5"$*' , $"66*)*#+ 5"'.,:
)*4)*'*#+,+"%# 6%) , !(- *:*1*#+? 2.+ +3"' "' %#:9 4,)+ %6 7)*,+"#8 #*& ,#$ *@7"+"#8 5"'.,: *:*;
1*#+' 6%) 9%.) ,44:"7,+"%#= M :,)8* 4,)+ %6 +3* "#+*)6,7* %6 ,# *:*1*#+ "' "#+*),7+"5"+9 &"+3 +3*
.'*)= -%) *@,14:*? , 2.++%# &"+3 +3* '+,#$,)$ +*14:,+* "' 3"83:"83+*$ &3*# +3* 1%.'* )%::'
%5*) "+ ,#$ 8"5*' , 5"'.,: 7.* &3*# "+ "' 7:"7K*$= A%. 7,# )*4:"7,+* +3"' 6.#7+"%#,:"+9 29 "#7%)4%;
),+"#8 +)"88*)' "#+% 9%.) +*14:,+*=
I3* !*&+!,?'"#,7&' %2Z*7+ 7%#+,"#' , 7%::*7+"%# %6 ?+%II'+ %2Z*7+' "# +3* !*&+!,?'"#,7&'
>?+%II'+$ 7%::*7+"%#= A%. 7,# ,$$ +)"88*)' 3*)* +% 4)%5"$* 5"'.,: "#+*),7+"5"+9 Z.'+ ,' 9%. &%.:$
"# , '+9:*> I3* 6%::%&"#8 *@,14:* $*1%#'+),+*' , ?+%II'+ %2Z*7+ "# , :-&&!* +*14:,+* +3,+
3"83:"83+' +3* 2.++%# &3*# +3* 1%.'* 1%5*' %5*) "+= I3* )*:*5,#+ 4%)+"%#' ,)* '3%&# "# 2%:$F
<ControlTemplate TargetType="{x:Type Button}" x:Key="ButtonTemplate">
<Border Name="Bord1" BorderBrush="Chocolate" BorderThickness="3">
<Grid>
<Rectangle Name="Rect1" Fill="RoyalBlue" />
<Ellipse Name="Elli1" Fill="Red" />
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Rect1" Property="Fill" Value="AliceBlue" />
<Setter TargetName="Bord1" Property="BorderBrush" Value="Red" />
<Setter TargetName="Elli1" Property="Fill" Value="Yellow" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
I3*)* ,)* , 6*& "14%)+,#+ +3"#8' +% #%+"7* ,2%.+ +3"' *@,14:*= -")'+? *,73 *:*1*#+ ,66*7+*$
29 +3* ?+%II'+ %2Z*7+ 3,' 3,$ +3* R7"' 4)%4*)+9 '*+ '% +3,+ +3* /'&&'+ %2Z*7+' "# +3* ?+%II'+
%2Z*7+ 7,# )*6*) +% +3* 7%))*7+ %2Z*7+= S*7%#$? +3* ?+%II'+ %2Z*7+ "' $*B#*$ "# +3* YMQD 7S&'+
+3* 7%#'+"+.*#+ *:*1*#+' %6 +3* +*14:,+*= I3"' "' )*<.")*$ 29 +3* +*14:,+* *#8"#*= >+ "'? +3*)*;
6%)*? , 8%%$ "$*, +% $*B#* +)"88*)' ,+ +3* *#$ %6 9%.) +*14:,+*=
A%. ,:'% 7,# $*B#* ,#"1,+"%#' "# 9%.) +*14:,+* +)"88*)'= I3"' *@,14:* 4)%5"$*' ,#
B*%"7&%!* %2Z*7+? '3%&# "# 2%:$? +3,+ "' *@*7.+*$ &3*# +3* 2.++%# "' 7:"7K*$F
<ControlTemplate TargetType="{x:Type Button}" x:Key="ButtonTemplate">
<Border Name="Bord1" BorderBrush="Chocolate" BorderThickness="3">
<Grid>
<Rectangle Name="Rect1" Fill="RoyalBlue" />
<Ellipse Name="Elli1" Fill="Red" />
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Rect1" Property="Fill" Value="AliceBlue" />
www.it-ebooks.info
')P) !"#$%&'( !%)K"#8 &"+3 H'*);L*B#*$ C%#+)%:'
<Setter TargetName="Bord1" Property="BorderBrush" Value="Red" />
<Setter TargetName="Elli1" Property="Fill" Value="Yellow" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Name="bst1">
<Storyboard AutoReverse="True">
<ThicknessAnimation
Storyboard.TargetProperty="Margin"
To="0,0,0,0" Duration="0:0:.3" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<StopStoryboard BeginStoryboardName="bst1" />
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
V-,<-:)$%&')*-'Q-7<36)-1'A6"-%)J,'A"!<-")$-,H4 +% +3"' 4%"#+ "# +3"' :*''%#? 9%. 3,5* '**# 3%& +% 7)*,+* , 6.::9 6.#7+"%#,: +*14:,+* &"+3
'.44%)+ 6%) +)"88*)' +3,+ 4)%5"$*' .'*) "#+*),7+"5"+9= _%&*5*)? 9%.) +*14:,+* "' #%+ *,'9 +%
7%#B8.)*= I3* :!+2'+ 7%:%) "' ,:&,9' F!)!,7&'? +3* 6')&7*I,' %2Z*7+ "' ,:&,9' 6!57,:,-'? ,#$
+3* 9,,%#$' %2Z*7+ "' ,:&,9' 6'2? #% 1,++*) 3%& +3* $*5*:%4*) '*+' +3* 4)%4*)+"*'= M:+3%.83
9%. 1"83+ "#+*#$ 6%) , +*14:,+* +% 2* .#,:+*),2:* "# '%1* 7,'*'? +3*)* ,)* %+3*) +"1*' &3*#
9%. &,#+ +% 4)%5"$* .'*) 7%#B8.),2":"+9= A%. 7,# .'* ?'"#,7&':%*2%*I +% )*'4*7+ +3* 4)%4*);
+"*' %6 +3* +*14:,+* 4,)*#+=
+,$%&' $&'()*$+",-",#
I3* ?'"#,7&':%*2%*I 1,)K.4 "' *''*#+",::9 , $,+,;2"#$"#8 *@4)*''"%# +3,+ 2"#$' , 4)%4*)+9
&"+3"# +3* +*14:,+* +% , #,1*$ 4)%4*)+9 %6 +3* +*14:,+*$ 4,)*#+? &3"73 "' , 6,#79 &,9 %6
',9"#8 +3* 7%#+)%: 6%) &3"73 9%. ,)* $*'"8#"#8 +3* +*14:,+*= I3* ?'"#,7&':%*2%*I *@4)*''"%#
+,K*' +3* 6%::%&"#8 6%)1F
{TemplateBinding <PropertyName>}
&3*)* J4+!#'+&5R7"'K "' +3* #,1* %6 +3* 4)%4*)+9 %# +3* +*14:,+*$ 4,)*#+ +% &3"73 9%.
&,#+ +% 2"#$= I3* 6%::%&"#8 *@,14:* '3%&' +3* +*14:,+* 6)%1 +3* 4)*5"%.' *@,14:* &"+3 +3*
:!+2'+>:!+2'+?F%);*'$$ 4)%4*)+9 2%.#$ +% +3* 4,)*#+ :!+2'+?F%);*'$$ 4)%4*)+9F
<ControlTemplate TargetType="{x:Type Button}" x:Key="ButtonTemplate">
<Border Name="Bord1" BorderBrush="Chocolate"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Rectangle Name="Rect1" Fill="RoyalBlue" />
<Ellipse Name="Elli1" Fill="Red" />
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
www.it-ebooks.info
D*''%# GF H'"#8 C%#+)%: I*14:,+*' !"#$%&'(' )P+
</Grid>
</Border>
<!--Triggers omitted-->
</ControlTemplate>
+,$%&'Q-7<36)-'/6)6'O$%1$%&
I3*)* "' %#* '"8#"B7,#+ 4)%2:*1 &"+3 +3* ?'"#,7&':%*2%*I !"#$!%%&'() !"#$%&!'()*()+ *'!%
('+ %,##'$+ ,-!!.%/$! +-#!% ./0&10 &(12,*! '-012 '34!1+%5 /0!( ,%!* &( +$&66!$%) 7'$+,8
(9+!2-: +0!$! &% 9( !9%- /9- +' *!92 /&+0 +0&% &%%,!; <', 19( ,%! 9 $!6,29$ '()*()+ !"#$!%%&'()
= $!6,29$ '()*()+ !"#$!%%&'( 19( $!>!$ +' 9 #$'#!$+- '> +0! +!?#29+! #9$!(+ 3- %!++&(6 +0!
3!$%&(4!560-7! #$'#!$+- +' !"#$%&!*8%-!)& 9(* 3- %!++&(6 +0! 8%&2 #$'#!$+- +' +0! *!%&$!*
#$'#!$+- >'$ 3&(*&(6) @0! >'22'/&(6 !"9?#2! *!?'(%+$9+!% +0! ,%! '> +0&% 3&(*&(6 +!10(&A,!
.('+! +0! 3'2* 1'*!5;
<ControlTemplate TargetType="{x:Type Button}" x:Key="ButtonTemplate">
<!--Grid and buttons omitted for brevity-->
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Rect1" Property="Fill" Value="AliceBlue" />
<Setter TargetName="Bord1" Property="BorderBrush" Value="Red" />
<Setter TargetName="Elli1" Property="Fill" Value="{Binding
RelativeSource={RelativeSource TemplatedParent},
Path=Background}" />
</Trigger>
<!--Trigger omitted for brevity-->
</ControlTemplate.Triggers>
</ControlTemplate>
<', 19( ,%! 9(- '+0!$ +-#! '> *9+983&(*&(6 !"#$!%%&'( &( 9 +!?#29+! 9% /!22) 7'$ !"9?#2!:
-', 1',2* 1$!9+! 9 '()*()+ '34!1+ +09+ %!+% 8%&2 &( +0! B=CD +!?#29+! .%0'/( 0!$! &( 3'2*5
9(* +0!( %!+% 9%&%:6)&!;& >'$ <()*6= &( 1'*!: 9% %0'/( 0!$!;
<ControlTemplate TargetType="{x:Type Button}" x:Key="ButtonTemplate">
<Border Name="Bord1" BorderBrush="Chocolate" BorderThickness="3">
<Grid>
<Rectangle Name="Rect1" Fill="{Binding Path=Background}" />
<Ellipse Name="Elli1" Fill="Red" />
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</Border>
<!--Triggers omitted-->
</ControlTemplate.Triggers>
</ControlTemplate>
!"#$%&'(&)*+,!$&-!+*.&/'0%
Window1.DataContext = Me
!"#$%&'(&/1&/'0%
Window1.DataContext = this;
www.it-ebooks.info
!"# $%&'()* + E'$F&(6 /&+0 G%!$8H!I(!* J'(+$'2%
E0!( +0&% 1'*! &% 9##2&!*: 922 +0! '0&&6) !2!?!(+% %!+ +' +0&% +!?#29+! &( <()*6=> 09K!
+0! !22&#%! #9&(+!* 3- +0! %9?! 3$,%0 9% +0! 391F6$',(* '> +0! /&(*'/)
2##$3*45&6%"#$!7%+&8*79& !"#$<', 19( ,%! 5&?$! +' 9##2- +!?#29+!% 9,+'?9+&1922-) L- %!++&(6 +0! %-+!& ?#! #$'#!$+- '>
5&?$! 9(* ,%&(6 5!&&!- +' %!+ +0! !"#$%&! #$'#!$+-: +0! %#!1&I!* +!?#29+! &% 9##2&!* 9,+'8
?9+&1922- +' 922 !2!?!(+% '> +09+ +-#!) @0! >'22'/&(6 !"9?#2! *!?'(%+$9+!% 9( &(%+9(1! '>
5&?$! +09+ 9,+'?9+&1922- 9##2&!% 9 +!?#29+! +' '0&&6) !2!?!(+%;
<Style TargetType="{x:Type Button}">
<Setter Property="Template" Value="{StaticResource ButtonTemplate}" />
</Style>
M+ &% &?#'$+9(+ +' $!?!?3!$ +09+ /0!( -', %!+ 9 +!?#29+! /&+0 5&?$!: &+ ?,%+ 3! *!I(!* &(
B=CD 9>+!$ +0! +!?#29+! &% *!I(!*)
)*%8*45&79%& ',:.%&/'0%&(':&!4&;<*+7*45&6%"#$!7%J$!9+&(6 9 +!?#29+! >'$ 9 '0&&6) 1'(+$'2 &% >9&$2- !9%-N +0!$! &%(O+ 9 2'+ '> (,9(1! +' +0! 29-',+:
9(* +0!$! 9$!(O+ +'' ?9(- K&%,92 %+9+!% +' ?'(&+'$) P'/!K!$: /0!( *!%&6(&(6 +!?#29+!% >'$
'+0!$ 1'(+$'2%: -', ?&60+ /9(+ +' ,%! +0! *!>9,2+ +!?#29+! 9% 9 $!>!$!(1!) <', 19( K&!/ +0!
*!>9,2+ +!?#29+! >'$ 9 EQ7 !2!?!(+ !9%&2-: 9% *!%1$&3!* &( +0! >'22'/&(6 #$'1!*,$!;
@' K&!/ +0! %',$1! 1'*! >'$ 9( !"&%+&(6 +!?#29+!;
!" M(%+9(+&9+! 9( !"9?#2! '> +0! !2!?!(+ /0'%! +!?#29+! -', /9(+ +' K&!/) @0! !2!?!(+
?,%+ 91+,922- 3! 1$!9+!* &( +0! K&%,92 +$!! %' -', 19( 9** &+ +' <()*6= 9+ *!%&6( +&?!
'$ 9** &+ #$'6$9??9+&1922-: 9% %0'/( 0!$!;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Dim aTextBox As New TextBox
Grid1.Children.Add(aTextBox)
!"#$%&'(&/1&/'0%
TextBox aTextBox = new TextBox();
Grid1.Children.Add(aTextBox);
#" G%! +0! 5?1&!"@<()*6=1@A%-B0#@C%"$<-(&!- 129%% +' %!$&92&R! +0! +!?#29+!) @0!$! 9$!
%!K!$92 /9-% +' *' +0&%) @0! >'22'/&(6 !"9?#2! *!?'(%+$9+!% 0'/ +' %9K! +0! +!?#29+!
+' 9( S"+!(%&32! C9$F,# D9(6,96! .BCD5 I2!;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Dim aStream As New System.IO.FileStream("C:\template.xml", _
System.IO.FileMode.Append)
System.Windows.Markup.XamlWriter.Save(aTextBox.Template, aStream)
!"#$%&'(&/1&/'0%
System.IO.FileStream aStream = new
System.IO.FileStream("C:\\template.xml",
www.it-ebooks.info
D!%%'( T; G%&(6 J'(+$'2 @!?#29+!% $%&'()* + !"+
System.IO.FileMode.Append);
System.Windows.Markup.XamlWriter.Save(aTextBox.Template, aStream);
=+*45&>:%0%?4%0&>!:7&@!"%+&*4&!&6%"#$!7%=2+0',60 EQ7 !2!?!(+% 9$! *!%&6(!* +' 3! 2''F2!%%: +0&% &% ('+ 92/9-% 1'?#2!+!2- +0! 19%!)
E0!( &(%#!1+&(6 +0! +!?#29+! '> +0! !;&'6; 1'(+$'2 &( +0! #$!K&',% %!1+&'(: -', ?&60+ 09K!
('+&1!* +0! >'22'/&(6 2&(!;
<ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding
UIElement.SnapsToDevicePixels}" />
@0! #9$+ '> +0&% 2&(! +09+ *!%!$K!% #9$+&1,29$ ('+&1! &% UV9?!WUQ=X@YJ'(+!(+P'%+Z) H!%#&+!
+0! 6'92 '> 2''F2!%% 1'(+$'2%: %'?! EQ7 !2!?!(+% &(+!$91+ /&+0 +0!&$ 1'*! +0$',60 (9?!*
!2!?!(+% &( +0!&$ +!?#29+!%) L- 1'(K!(+&'(: 922 +0!%! !2!?!(+% +09+ &(+!$91+ /&+0 +0! !2!?!(+
1'*! 9$! (9?!* 8D3 EF)%"!G: /0!$! F)%"!G &% 9 *!%1$&#+&'( '> +0! $'2! '> +09+ #9$+) M( +0!
!;&'6; !"9?#2!: 8%-&E:6)&!)&H61& &(+!$91+% /&+0 +0! !2!?!(+ 1'*! +' #$'K&*! +0! !*&+932!
%,$>91! '> !;&'6;@ M> -', 9$! #$'K&*&(6 9 (!/ +!?#29+! >'$ 9(- 1'(+$'2 /&+0 (9?!* #9$+%:
-', %0',2* 6&K! +0! 1'$$!%#'(*&(6 !2!?!(+% +0! %9?! (9?! +' F!!# +0! >,(1+&'(92&+- '> +0!
1'(+$'2 1'(%&%+!(+)
$%&'()'* $,-./012 . $31/,34 (-564./-
M( +0&% #$91+&1!: -', 1$!9+! 9 (!/ +!?#29+! >'$ +0! '0&&6) 1'(+$'2) <', #$'K&*! 9 1,%+'? 9#8
#!9$9(1! >'$ +0! 3,++'( 9(* &?#2!?!(+ +0! >,(1+&'(92&+- +' 109(6! +09+ 9##!9$9(1! /0!(
+0! 3,++'( &% *&%932!*: /0!( +0! ?',%! ?'K!% 'K!$ +0! 3,++'(: 9(* /0!( +0! 3,++'( &%
12&1F!*)
*+*%'),* /:%!7*45&!&@%8&/'47:'$&6%"#$!7%
!" J$!9+! 9 (!/ EQ7 9##2&19+&'()
#" M( B=CD K&!/: 1$!9+! 9 <()*6=@3!160-7!1 %!1+&'( 4,%+ 3!>'$! +0! I-(* %!1+&'(: 9%
%0'/( 0!$!;
<Window.Resources>
</Window.Resources>
-" =** +0! >'22'/&(6 :6)&-6$ !"#$%&! +!?#29+! +' +0! <()*6=@3!160-7!1 %!1+&'() @0&%
+!?#29+! *!I(!% 9( J$$(#1! '34!1+ 9(* 9 :6)&!)&8-!1!)&!- '34!1+ +09+ ?9F! ,# +0!
K&%,92 9##!9$9(1! '> '0&&6)) J$$(#1! &% I22!* 3- 9 1,%+'? 3%*(%$I-%*(!)&'-012 #$'#!$+-
+09+ 6&K!% &+ 9 1'2'$>,2 9##!9$9(1!;
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Grid>
<Ellipse Name="Ellipse1" Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="{TemplateBinding BorderThickness}">
<Ellipse.Fill>
www.it-ebooks.info
!"7 $%&'()* + E'$F&(6 /&+0 G%!$8H!I(!* J'(+$'2%
<RadialGradientBrush GradientOrigin=".5, .5">
<GradientStop Color="Red" Offset="0" />
<GradientStop Color="Orange" Offset=".25" />
<GradientStop Color="Blue" Offset=".5" />
<GradientStop Color="Yellow" Offset=".75" />
<GradientStop Color="Green" Offset="1" />
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
." =** 9 :6)&-6$ !"#$%&!@ -(++!-1 %!1+&'( 9(* 9** +0! >'22'/&(6 +$&66!$ +' 0&602&60+ +0!
3,++'( /0!( +0! ?',%! &% 'K!$ &+;
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Ellipse1" Property="Fill">
<Setter.Value>
<RadialGradientBrush GradientOrigin=".5, .5">
<GradientStop Color="LightCoral" Offset="0" />
<GradientStop Color="LightSalmon" Offset=".25" />
<GradientStop Color="LightBlue" Offset=".5" />
<GradientStop Color="LightYellow" Offset=".75" />
<GradientStop Color="LightGreen" Offset="1" />
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
/" =** 9('+0!$ +$&66!$ +' *&%932! '0&&6) /0!( +0! K1J)%/$!* #$'#!$+- &% %!+ +' ,%$1!: 9%
%0'/( 0!$!;
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Ellipse1" Property="Fill">
<Setter.Value>
<RadialGradientBrush GradientOrigin=".5,.5">
<GradientStop Color="Gray" Offset="0" />
<GradientStop Color="LightGray" Offset=".25" />
<GradientStop Color="Black" Offset=".5" />
<GradientStop Color="White" Offset=".75" />
<GradientStop Color="DarkGray" Offset="1" />
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
0" =** J4!)& -(++!- +09+ #29-% 9( 9(&?9+&'( /0!( +0! 3,++'( &% 12&1F!* +' +0! -(++!-1
%!1+&'() @0! >'22'/&(6 !"9?#2! 19,%!% +0! 3,++'( +' %0$&(F +' 9 #'&(+ 9(* $!8!"#9(*;
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
www.it-ebooks.info
D!%%'( T; G%&(6 J'(+$'2 @!?#29+!% $%&'()* + !"8
<Storyboard AutoReverse="True">
<DoubleAnimation To="0" Duration="0:0:0.1"
Storyboard.TargetProperty="Width" />
<DoubleAnimation To="0" Duration="0:0:0.1"
Storyboard.TargetProperty="Height" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
1" M( +0! <()*6=@3!160-7!1 %!1+&'(: 9>+!$ +0! !(* '> :6)&-6$ !"#$%&!L 9** +0! >'22'/&(6
5&?$! !2!?!(+ +' %!+ +0! +!?#29+! >'$ '0&&6) !2!?!(+% &( +0&% 9##2&19+&'( 9,+'?9+&1922-;
<Style TargetType="{x:Type Button}">
<Setter Property="Template" Value="{StaticResource ButtonTemplate}" />
</Style>
2" =** +0! >'22'/&(6 '0&&6) +96% 9% 10&2*$!( +' +0! I-(* 1'(+$'2 &( +0! B=CD >'$ +0&% /&(8
*'/;
<Button Height="80" Width="90" Name="Button1">Button</Button>
<Button Height="60" HorizontalAlignment="Left" Name="Button2"
VerticalAlignment="Top" Width="75">Button</Button>
H' ('+ %!+ +0! C9$6&( #$'#!$+- 3!19,%! +0&% &(+!$>!$!% /&+0 +0! D)("%&(6) #$'#!$+-
-', *!I(!* &( [+!# \)
3" [!+ +0! K1J)%/$!* #$'#!$+- '> +0! %!1'(* '0&&6) '34!1+ +' ,%$1!L 9% %0'/( 0!$!)
<Button IsEnabled="False" Height="60" HorizontalAlignment="Left"
Name="Button2" VerticalAlignment="Top" Width="75">Button</Button>
!4" Q$!%% 7] +' $,( -',$ 9##2&19+&'() V'+! +09+ -',$ '0&&6) '34!1+ &% 0&602&60+!* /0!( +0!
?',%! ?'K!% 'K!$ &+ 9(* +09+ +0! 9(&?9+&'( $,(% /0!( +0! 3,++'( &% 12&1F!*)
A%++'4& ,""!:3■ J'(+$'2 +!?#29+!% *!I(! +0! K&%,92 &(+!$>91! >'$ 9 1'(+$'2 3,+ *' ('+ 9>>!1+ +0! &(0!$8
!(+ >,(1+&'(92&+- '> 9 1'(+$'2 *&$!1+2-) L- %!++&(6 +0! !"#$%&! #$'#!$+- '> 9 EQ7
!2!?!(+: -', 19( #$'K&*! 9 (!/ K&%,92 &(+!$>91! >'$ +09+ 1'(+$'2 /0&2! 2!9K&(6 &+% 1'$!
>,(1+&'(92&+- &(+91+)
■ J'(+$'2 +!?#29+!% 9$! +-#&1922- *!I(!* 9% $!%',$1!% 9(* 9$! %!+ '( 9 +9$6!+ !2!?!(+
3- %!++&(6 +0! !2!?!(+O% !"#$%&! #$'#!$+- +' $!>!$!(1! +0! 9##$'#$&9+! $!%',$1!)
=2+!$(9+&K!2-: +!?#29+!% 19( 3! 9##2&!* 9,+'?9+&1922- +' 922 !2!?!(+% '> 9 6&K!( +-#!
3- ,%&(6 9 5&?$! !2!?!(+ +09+ 09% +0! %-+!& ?#! #$'#!$+- %!+ +' +0! 9##$'#$&9+! !2!8
?!(+ +-#!)
■ J'(+$'2 +!?#29+!% 19( 1'(+9&( -(++!- '34!1+% 9% #9$+ '> +0! +!?#29+!) -(++!- '34!1+%
+-#&1922- #$'K&*! K&%,92 1,!% +' +0! ,%!$ /0!( 1'(*&+&'(% 109(6! >'$ +0! !2!?!(+)
■ <', 19( ,%! +0! !"#$%&!'()*()+ ?9$F,# +' 3&(* 9 #$'#!$+- &(%&*! 9 +!?#29+! +'
9 #$'#!$+- '> +0! +!?#29+!* #9$!(+) @0&% ?9$F,# *'!% ('+ >,(1+&'( /&+0 ,-!!.%/$!
www.it-ebooks.info
!"9 $%&'()* + E'$F&(6 /&+0 G%!$8H!I(!* J'(+$'2%
'34!1+% &( -(++!- '34!1+%N &( +09+ 19%!: -', %0',2* ,%! 9 $!6,29$ '()*()+ 1'(+$'2 /&+0
+0! 3!$%&(4!560-7! #$'#!$+- %!+ +' !"#$%&!*8%-!)&@
■ ['?! +!?#29+!% 1'(+9&( !2!?!(+% +09+ 9$! 91+!* '( *&$!1+2- 3- +0! %',$1! 1'*! '>
+0! !2!?!(+) @0!%! !2!?!(+% 9$! (9?!* 8D3 EF#%-&)%"!G) E0!( -', 9$! 1$!9+&(6 9
+!?#29+! >'$ 9( !2!?!(+ /&+0 (9?!* #9$+%: -', %0',2* F!!# +0! %9?! (9?! >'$ 1'$8
$!%#'(*&(6 #9$+% '> +0! +!?#29+! +' 9K'&* 09K&(6 +' $!8&?#2!?!(+ +0! >,(1+&'(92&+-)
A%++'4&B%C*%8<', 19( ,%! +0! >'22'/&(6 A,!%+&'(% +' +!%+ -',$ F('/2!*6! '> +0! &(>'$?9+&'( &( D!%%'( T:
UG%&(6 J'(+$'2 @!?#29+!%)Z @0! A,!%+&'(% 9$! 92%' 9K9&2932! '( +0! 1'?#9(&'( JH &> -', #$!8
>!$ +' $!K&!/ +0!? &( !2!1+$'(&1 >'$?)
!"# &:;<)*;
24+8%:+&7'&79%+%&D,%+7*'4+&!40&%<#$!4!7*'4+&'(&893&%!.9&!4+8%:&.9'*.%&*+&.'::%.7&':&*4.':E
:%.7&!:%&$'.!7%0&*4&79%&F24+8%:+G&+%.7*'4&!7&79%&%40&'(&79%&H''IJ
!" E0&10 '> +0! >'22'/&(6 B=CD %9?#2!% 1'$$!1+2- 3&(*% +0! '%7B+-60)* #$'#!$+- '> +0!
M%/!$ 1'(+$'2 &( +0! +!?#29+! +' +0! '%7B+-60)* #$'#!$+- '> &+% +!?#29+!* #9$!(+^
.J0''%! 922 +09+ 9##2-)5
&"
<ControlTemplate x:Key="TestTemplate">
<Label Background="Background" />
</ControlTemplate>
5"
<ControlTemplate x:Key="TestTemplate">
<Label Background="{Binding Background}" />
</ControlTemplate>
'"
<ControlTemplate x:Key="TestTemplate">
<Label Background="{TemplateBinding Background}" />
</ControlTemplate>
6"
<ControlTemplate x:Key="TestTemplate">
<Label Background="{Binding RelativeSource={RelativeSource
TemplatedParent}, Path=Background}" />
</ControlTemplate>
!"# &:;<)*;
24+8%:+&7'&79%+%&D,%+7*'4+&!40&%<#$!4!7*'4+&'(&893&%!.9&!4+8%:&.9'*.%&*+&.'::%.7&':&*4.':E
:%.7&!:%&$'.!7%0&*4&79%&F24+8%:+G&+%.7*'4&!7&79%&%40&'(&79%&H''IJ
www.it-ebooks.info
D!%%'( T; G%&(6 J'(+$'2 @!?#29+!% $%&'()* + !""
#" E0&10 '> +0! >'22'/&(6 B=CD %9?#2!% 1'$$!1+2- 9##2&!% +0! 1'(+$'2 +!?#29+! +' 922
&(%+9(1!% '> M%/!$ &( <()*6=^
&"
<Window.Resources>
<ControlTemplate x:Key="TestTemplate" TargetType="Label">
<Label Background="{Binding RelativeSource={RelativeSource
TemplatedParent}, Path=Background}" />
</ControlTemplate>
<Style TargetType="Label">
<Setter Property="Template" Value="{StaticResource
TestTemplate}" />
</Style>
</Window.Resources>
5"
<Window.Resources>
<Style TargetType="Label">
<Setter Property="Template" Value="{StaticResource
TestTemplate}" />
</Style>
<ControlTemplate x:Key="TestTemplate" TargetType="Label">
<Label Background="{Binding RelativeSource={RelativeSource
TemplatedParent}, Path=Background}" />
</ControlTemplate>
</Window.Resources>
'"
<Window.Resources>
<Style TargetType="Label">
</Style>
<ControlTemplate x:Key="TestTemplate" TargetType="Label">
<Label Background="{Binding RelativeSource={RelativeSource
TemplatedParent}, Path=Background}" />
</ControlTemplate>
</Window.Resources>
6"
<Window.Resources>
<ControlTemplate x:Key="TestTemplate" TargetType="Label">
<Label Background="{Binding RelativeSource={RelativeSource
TemplatedParent}, Path=Background}" />
</ControlTemplate>
</Window.Resources>
www.it-ebooks.info
=>> $%&'()* + E'$F&(6 /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%) J,%+'? 1'(+$'2% &( EQ7
>922 &(+' +/' 19+!6'$&!%; 01!-N76)&-6$1: /0&10 &(0!$&+ +0! O1!-:6)&-6$ 129%% 9(* 9$! ?9*! ,# '>
1'(%+&+,!(+ 1'(+$'2% 3',(* +'6!+0!$ 3- 9 1'??'( >,(1+&'(92&+- &( 9 %09$!* ,%!$ &(+!$>91!N
9(* 701&6"N76)&-6$1: /0&10 &(0!$&+ +0! :6)&-6$ '$ :6)&!)&:6)&-6$ 129%% 9(* *!I(! +0!&$ '/(
K&%,92 9##!9$9(1! 9(* >,(1+&'(92&+-) L!19,%! '> +0! +!?#29+!839%!* ?!109(&%? '> 1$!9+&(6
,%!$ &(+!$>91!%: +0! 2&(! 3!+/!!( ,%!$ 1'(+$'2% 9(* 1,%+'? 1'(+$'2% &% %'?!/09+ 32,$$!*) @0!
&?#'$+9(+ *&%+&(1+&'( >$'? 9 *!K!2'#!$O% %+9(*#'&(+ &% +09+ ,%!$ 1'(+$'2% #$'K&*! 9 *!%&6(932!
%,$>91! 9+ *!%&6( +&?! 9(* 1,%+'? 1'(+$'2% *' ('+)
E0!+0!$ 1$!9+&(6 9 ,%!$ 1'(+$'2 '$ 9 1,%+'? 1'(+$'2: -', 2&F!2- /9(+ +' #$'K&*! (!/ #$'#8
!$+&!% >'$ -',$ 1'(+$'2) @' +9F! 9*K9(+96! '> 3,&2+8&( *9+9 3&(*&(6 9(* 109(6! ('+&I19+&'(
>!9+,$!% &( EQ7: -', %0',2* &?#2!?!(+ *!#!(*!(1- #$'#!$+&!%)
/9''+*45&!"'45&=+%:&/'47:'$+K&/,+7'"&/'47:'$+K&!40&6%"#$!7%+G%!$ 1'(+$'2%: 1,%+'? 1'(+$'2%: 9(* +!?#29+!% 922 !(932! -', +' 1$!9+! 1,%+'? !2!?!(+% /&+0
1,%+'? 9##!9$9(1!%) L!19,%! !910 '> +0!%! ?!+0'*% &% %' #'/!$>,2: -', ?&60+ 3! 1'(>,%!*
93',+ /0&10 +!10(&A,! +' ,%! /0!( 1$!9+&(6 9 1,%+'? !2!?!(+ >'$ -',$ 9##2&19+&'() @0! F!-
2(7%:&79*+&$%++'4K&3',&8*$$&H%&!H$%&7'L&
■ J0''%! 9?'(6 ,%&(6 9 1'(+$'2 +!?#29+!: 9 ,%!$ 1'(+$'2: '$ 9 1,%+'? 1'(+$'2)
■ M?#2!?!(+ 9 *!#!(*!(1- #$'#!$+-)
■ J$!9+! 9 (!/ ,%!$ 1'(+$'2)
■ J$!9+! 9 (!/ 1,%+'? 1'(+$'2)
■ J'(%,?! 9 1,%+'? '$ ,%!$ 1'(+$'2)
■ X!(*!$ +0!?!839%!* 9##!9$9(1!% >'$ -',$ 1,%+'? 1'(+$'2%)
;+7*"!7%0&$%++'4&7*"%L&MN&"*4,7%+
www.it-ebooks.info
D!%%'( _; J$!9+&(6 J,%+'? J'(+$'2% &( EQ7 $%&'()* + =>D
+' ?9F&(6 +0! $&60+ *!1&%&'( &%(O+ 39%!* '( +0! 9##!9$9(1! -', /9(+ +' 1$!9+! 3,+: $9+0!$: '(
+0! >,(1+&'(92&+- -', /9(+ +' &(1'$#'$9+! &(+' -',$ 9##2&19+&'()
@0! %+9(*9$* EQ7 1'(+$'2% #$'K&*! 9 6$!9+ *!92 '> 3,&2+8&( >,(1+&'(92&+-) M> +0! >,(1+&'(92&+-
'> '(! '> +0! #$!%!+ 1'(+$'2%: %,10 9% 9 #$'6$!%% 39$ '$ 9 %2&*!$: ?9+10!% +0! >,(1+&'(92&+- +09+
-', /9(+ +' &(1'$#'$9+!: +0!( -', %0',2* 1$!9+! 9 (!/ +!?#29+! >'$ +09+ #$!!"&%+&(6 1'(+$'2
+' 910&!K! +0! 9##!9$9(1! -', /9(+) J$!9+&(6 9 (!/ +!?#29+! &% +0! %&?#2!%+ %'2,+&'( +' 1$!8
9+&(6 9 1,%+'? !2!?!(+: %' -', %0',2* 1'(%&*!$ +09+ '#+&'( I$%+)
M> +0! >,(1+&'(92&+- -', /9(+ +' &(1'$#'$9+! &(+' -',$ 9##2&19+&'( 19( 3! 910&!K!* +0$',60
9 1'?3&(9+&'( '> #$!!"&%+&(6 1'(+$'2% 9(* 1'*!: 1'(%&*!$ 1$!9+&(6 9 ,%!$ 1'(+$'2) G%!$ 1'(8
+$'2% !(932! -', +' 3&(* +'6!+0!$ ?,2+! #$!!"&%+&(6 1'(+$'2% &( 9 %&(62! &(+!$>91! 9(* 9**
1'*! +09+ *!+!$?&(!% 0'/ +0!- 3!09K!)
M> (' #$!!"&%+&(6 1'(+$'2 '$ 1'?3&(9+&'( '> 1'(+$'2% 19( 910&!K! +0! >,(1+&'(92&+- -', /9(+:
1$!9+! 9 1,%+'? 1'(+$'2) J,%+'? 1'(+$'2% !(932! -', +' 1$!9+! 9 1'?#2!+!2- (!/ +!?#29+!
+09+ *!I(!% +0! K&%,92 $!#$!%!(+9+&'( '> +0! 1'(+$'2 9(* +' 9** 1,%+'? 1'*! +09+ *!+!$?&(!%
+0! 1'(+$'2O% >,(1+&'(92&+-)
Q"#$%"%47*45&!40&B%5*+7%:*45&R%#%40%4.3&>:'#%:7*%+H!#!(*!(1- #$'#!$+&!% 9$! +0! %+9(*9$* >'$? +09+ #$'#!$+&!% &( EQ7 +9F!) @0!- %,##'$+
109(6! ('+&I19+&'(: 9(&?9+&'(: #$'#!$+- K92,! &(0!$&+9(1!: 9(* *9+9 3&(*&(6: 9(* +0!- %,#8
#'$+ ?,2+! #$'#!$+- K92,! #$'K&*!$%)
H!#!(*!(1- #$'#!$+&!% 19( 3! &?#2!?!(+!* '(2- '( '34!1+% +09+ *!$&K! >$'? +0!
9!#!)*!)7?P/Q!7& 129%%) =22 EQ7 !2!?!(+% *!$&K! >$'? 9!#!)*!)7?P/Q!7&) M> -', /9(+
+' &?#2!?!(+ *!#!(*!(1- #$'#!$+&!% '( 9 1,%+'? 129%%: +0! 129%% ?,%+ &(0!$&+ >$'?
9!#!)*!)7?P/Q!7&)
H!#!(*!(1- #$'#!$+&!% 9$! &?#2!?!(+!* 9% ('$?92 )VS@ #$'#!$+&!% /&+0 %'?! !"+$9 EQ7
&(>$9%+$,1+,$!) @0! *!#!(*!(1- #$'#!$+- ?,%+ 3! $!6&%+!$!* /&+0 +0! $,( +&?! &( 9 %+9+&1 1'(8
%+$,1+'$: 9(* +0!( &+ 19( 3! %!+ ,%&(6 9 %+9(*9$* )VS@ #$'#!$+- /$9##!$)
@' &?#2!?!(+ 9(* $!6&%+!$ 9 *!#!(*!(1- #$'#!$+-;
!" M( 9 129%% +09+ &(0!$&+% >$'? 9!#!)*!)7?P/Q!7&: *!129$! 9 #,32&1: %+9+&1: $!9*8'(2- K9$&8
932! '> +0! +-#! 9!#!)*!)7?8-6#!-&?@ L- 1'(K!(+&'(: +0! (9?! '> +0&% K9$&932! %0',2*
3! -',$ *!%&$!* (9?! >'$ +0! #$'#!$+- /&+0 +0! %,>I" UQ$'#!$+-Z 9**!* +' &+) D''F 9+
+0! >'22'/&(6 !"9?#2!;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Shared ReadOnly FlavorProperty As DependencyProperty
!"#$%&'(&/1&/'0%
public static readonly DependencyProperty FlavorProperty;
www.it-ebooks.info
=>! $%&'()* + E'$F&(6 /&+0 G%!$8H!I(!* J'(+$'2%
#" J$!9+! 9 %+9+&1 1'(%+$,1+'$ >'$ +0! 129%% +09+ $!6&%+!$% +0! *!#!(*!(1- #$'#!$+-) @0!
9!#!)*!)7?8-6#!-&?@3!+(1&!- ?!+0'* $!A,&$!% -', +' #$'K&*! +0! (9?! '> +0! )VS@
#$'#!$+- /$9##!$: +0! +-#! '> +0! #$'#!$+-: +0! +-#! +09+ '/(% +09+ #$'#!$+-: 9(* 9(
&(%+9(1! '> ,-%"!=6-B8-6#!-&?A!&%*%&%: /0&10 19( 3! ,%!* +' 9** '#+&'(92 >!9+,$!%
+' -',$ *!#!(*!(1- #$'#!$+-) @0! >'22'/&(6 !"9?#2! %0'/% 9 %+9+&1 1'(%+$,1+'$ +09+
$!6&%+!$% +0! *!#!(*!(1- #$'#!$+- 9(* 9%%,?!% +09+ -',$ 129%% &% (9?!* 8(!:$%11;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Shared Sub New()
Dim md As New FrameworkPropertyMetadata()
PieClass.FlavorProperty = DependencyProperty.Register("Flavor", _
GetType(String), GetType(PieClass), md)
End Sub
!"#$%&'(&/1&/'0%
static PieClass()
{
FrameworkPropertyMetadata md = new FrameworkPropertyMetadata();
PieClass.FlavorProperty = DependencyProperty.Register("Flavor",
typeof(string), typeof(PieClass), md);
}
-" 7&(922-: 1$!9+! 9 )VS@ #$'#!$+- /$9##!$ +' 922'/ +0! *!#!(*!(1- #$'#!$+- +' 3! 918
1!%%!* &( 1'*!: 9% %0'/( 0!$!;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Property Flavor() As String
Get
Return CType(GetValue(PieClass.FlavorProperty), String)
End Get
Set
SetValue(PieClass.FlavorProperty, value)
End Set
End Property
!"#$%&'(&/1&/'0%
public string Flavor
{
get
{
return (string)GetValue(PieClass.FlavorProperty);
}
set
{
SetValue(PieClass.FlavorProperty, value);
}
}
M+ &% &?#'$+9(+ +' ('+! +09+ /0!( *!#!(*!(1- #$'#!$+&!% 9$! %!+ 3- +0! $,( +&?!: +0!-
9$! %!+ *&$!1+2- +0$',60 +0! I!&R%$0! 9(* 5!&R%$0! ?!+0'*%: ('+ +0$',60 +0! )VS@ #$'#8
!$+- /$9##!$) @0,%: -', %0',2* ('+ #,+ 9(- 9**&+&'(92 1'*! &( +0! /$9##!$ 3!19,%! &+
*'!% ('+ $,( ,(2!%% +0! #$'#!$+- &% %!+ *&$!1+2- &( 1'*!) <', 19( #$'K&*! 9 %+9+&1 1922391F
www.it-ebooks.info
D!%%'( _; J$!9+&(6 J,%+'? J'(+$'2% &( EQ7 $%&'()* + =>=
?!+0'* +09+ !"!1,+!% /0!( +0! #$'#!$+- K92,! &% 109(6!* 3- %#!1&>-&(6 9 *!2!69+! &(
,-%"!=6-B8-6#!-&?A!&%*%&%: 9% %0'/( 0!$!;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Shared Sub New()
Dim md As New FrameworkPropertyMetadata(New _
PropertyChangedCallback(AddressOf FlavorPropertyChanged))
PieClass.FlavorProperty = DependencyProperty.Register("Flavor", _
GetType(String), GetType(PieClass), md)
End Sub
Private Shared Sub FlavorPropertyChanged(ByVal o As DependencyObject, _
ByVal e As DependencyPropertyChangedEventArgs)
' Implementation omitted
End Sub
!"#$%&'(&/1&/'0%
static PieClass()
{
FrameworkPropertyMetadata md = new FrameworkPropertyMetadata(new
PropertyChangedCallback(FlavorPropertyChanged));
PieClass.FlavorProperty = DependencyProperty.Register("Flavor",
typeof(string), typeof(PieClass), md);
}
private static void FlavorPropertyChanged(DependencyObject o,
DependencyPropertyChangedEventArgs e)
{
// Implementation omitted
}
/:%!7*45&=+%:&/'47:'$+<', 19( 1$!9+! 9 ,%!$ 1'(+$'2 +' 1'?3&(! +0! >,(1+&'(92&+- '> ?,2+! #$!!"&%+&(6 1'(+$'2%
/&+0 1'*! +09+ ?9F!% +0!? /'$F +'6!+0!$ &( 9 %#!1&I1 /9-) E0!( 1$!9+&(6 ,%!$ 1'(+$'2%: -',
9$! +-#&1922- ('+ 9++!?#+&(6 +' 1$!9+! 9 2''F2!%% 1'(+$'2 3,+: $9+0!$: 9 $!,%932! 9?9269? '>
#$!1'(I6,$!* 1'(+$'2%)
J$!9+&(6 9 ,%!$ 1'(+$'2 &% !9%-) `&%,92 [+,*&' #$'K&*!% 9 *!%&6(932! %,$>91! >'$ ,%!$ 1'(+$'2
1$!9+&'( +09+ !(932!% *$9689(*8*$'# >,(1+&'(92&+- >$'? +0! @''23'"@ @0,%: -', 19( *!%&6( 9
,%!$ 1'(+$'2 &( !"91+2- +0! %9?! /9- 9% -', /',2* *!%&6( 9( 9##2&19+&'( &(+!$>91!) =>+!$ +0!
&(+!$>91! '> +0! 1'(+$'2 &% 1$!9+!*: -', 19( &?#2!?!(+ +0! >,(1+&'(92&+- -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1'(+$'2 #$'4!1+ &( `&%,92 [+,*&': &+ 1$!9+!% 9 @0!?!% >'2*!$ +09+ 1'(+9&(% 9 I2! (9?!*
a!(!$&1) "9?2) @0&% I2! 1'(+9&(% +0! *!>9,2+ +!?#29+! >'$ -',$ 1,%+'? 1'(+$'2: /0&10 -', 19(
92+!$ +' 1$!9+! +0! +!?#29+! >'$ -',$ 1'(+$'2)
@' 1$!9+! 9 1,%+'? 1'(+$'2;
!" M( `&%,92 [+,*&': 1$!9+! 9 (!/ EQ7 J,%+'? J'(+$'2 D&3$9$- #$'4!1+ ,%&(6 +0! +!?#29+!
&( +0! E&(*'/% #$'4!1+ +-#!) @0! *!%&6(!$ '#!(% +' +0! J'*! /&(*'/)
#" M( ['2,+&'( S"#2'$!$: '#!( +0! @0!?!% >'2*!$ 9(* *',32!812&1F a!(!$&1)"9?2 +' '#!(
+0! *!>9,2+ +!?#29+! >'$ -',$ 1,%+'? 1'(+$'2)
-" M( B=CD K&!/: 1$!9+! +0! +!?#29+! >'$ -',$ 1'(+$'2)
." =** 9(- >,(1+&'(92&+- -',$ 1'(+$'2 $!A,&$!%) M> -', (!!* +' &?#2!?!(+ 9(- #$'#!$+&!%:
&?#2!?!(+ *!#!(*!(1- #$'#!$+&!% 9% *!%1$&3!* !9$2&!$ &( +0&% 2!%%'() 7'$ !K!(+%: &?#2!8
?!(+ $',+!* !K!(+% 9% *!%1$&3!* &( J09#+!$ T: UE'$F&(6 /&+0 SK!(+% 9(* J'??9(*%)Z
/" Q$!%% 7] +' 3,&2* -',$ 1'(+$'2)
M( +0! #$91+&1! >'$ +0&% 2!%%'(: -', 1$!9+! 9 1,%+'? 1'(+$'2 >$'? +0! 3!6&((&(6)
J,%+'? 1'(+$'2% +-#&1922- &(0!$&+ +0! :6)&-6$ 129%%: /0&10 #$'K&*!% 922 +0! &(>$9%+$,1+,$! 9
1'(+$'2 (!!*% 3,+ 1'(+9&(% (' 1'(+$'28%#!1&I1 &?#2!?!(+9+&'() M( %'?! 19%!%: 0'/!K!$: -',
/9(+ +' &(0!$&+ 9('+0!$ 129%%) 7'$ !"9?#2!: &> -', /9(+!* +' 1$!9+! 9 EQ7 &?#2!?!(+9+&'( '>
A%1B!* !;&'6;: -', ?&60+ %+9$+ 3- &(0!$&+&(6 +0! !;&'6; 129%%) M> -', /9(+ +' &(0!$&+ 9 129%%
'+0!$ +09( :6)&-6$L -', ?,%+ ?9(,922- 109(6! +0! 129%% -',$ 1'(+$'2 &(0!$&+% &( +0! 1'*! I2!)
/'4+,"*45&=+%:&/'47:'$+&!40&/,+7'"&/'47:'$+@' +!%+ '$ '+0!$/&%! 1'(%,?! 9 ,%!$ 1'(+$'2 '$ 9 1,%+'? 1'(+$'2: -', ?,%+ 9** &+ +' 9('+0!$
#$'4!1+) @0&% &(K'2K!% 1$!9+&(6 9 $!>!$!(1! +' +0! 9%%!?32- 9(* +0!( &(%+9(+&9+&(6 +0! 1'(+$'2)
@' 1'(%,?! 9 ,%!$ 1'(+$'2 '$ 9 1,%+'? 1'(+$'2;
!" M( ['2,+&'( S"#2'$!$: $&60+812&1F +0! #$'4!1+ 9(* 10''%! =** X!>!$!(1!) @0! =**
X!>!$!(1! *&92'6 3'" '#!(%)
www.it-ebooks.info
D!%%'( _; J$!9+&(6 J,%+'? J'(+$'2% &( EQ7 $%&'()* + =>+
#" J2&1F +0! L$'/%! +93 9(* 3$'/%! +' +0! )*22 I2! +09+ 1'(+9&(% +0! 1'(+$'2 -', /9(+ +'
,%!) [!2!1+ &+ 9(* 12&1F bc)
-" M( B=CD K&!/: 9** 9( B=CD $!>!$!(1! +' +0! (!/2- 9**!* 9%%!?32-: 9% %0'/( &( +0&%
!"9?#2!;
xmlns:cc="clr-namespace:WpfCustomControlLibrary1;
assembly=WpfCustomControlLibrary1"
." M( B=CD: 9** -',$ 1,%+'? 1'(+$'2: 9% %0'/( &( +0&% !"9?#2!;
<cc:CustomControl1 />
/" Q$!%% 7] +' 3,&2* -',$ 9##2&19+&'()
M> -', 9$! +!%+&(6 9 1'(+$'2: 3! %,$! -', $!>!$!(1! +0! *-(9?&182&(F 2&3$9$- .HDD5 &( +0!
H!3,6 >'2*!$) E0!( -', ?9F! 109(6!% +' +0! 1'(+$'2 9(* $!3,&2* &+: -',$ +!%+ 9##2&19+&'(
*!+!1+% 9(- 109(6!% 9(* #$'?#+% -', +' $!3,&2* +0! 9##2&19+&'()
EB0FG $H-FG
■ O9!7&*+&79%&0*((%:%4.%&H%78%%4&!&,+%:&.'47:'$&!40&!&.,+7'"&.'47:'$S
EB0FG $H-FG &1@I-,
■ 2&,+%:&.'47:'$&*+&!&.'"#'+*7%&.'47:'$&.'"#'+%0&'(&#:%%<*+7*45&O>P&.'47:'$+&
H',40&7'5%79%:&H3&!&.'""'4&(,4.7*'4!$*73J&2&.,+7'"&.'47:'$&*+&!&,+%:E
0%?4%0&.'47:'$&.'"#'+%0&'(&!&4%8&.'47:'$&7%"#$!7%&!40&!&4%8&!++'.*!7%0&
(,4.7*'4!$*73J
B%40%:*45&!&69%"%E-!+%0&2##%!:!4.%@0! E&(*'/% `&%+9 '#!$9+&(6 %-%+!? !(932!% +0! ,%!$ +' %!2!1+ +0!?!% >'$ +0! *!%F+'#
!(K&$'(?!(+) E0!( 9 +0!?! &% %!2!1+!*: 9##2&19+&'(% +09+ $!(*!$ 9 +0!?!839%!* 9##!9$9(1!
9,+'?9+&1922- 109(6! +' $!(*!$ 9( 9##!9$9(1! 9(* 3!09K&'$ 1'(%&%+!(+ /&+0 +09+ +0!?!)
=2+0',60 &( %'?! 19%!% -', ?&60+ /9(+ -',$ 1,%+'? 1'(+$'2% +' 09K! 9 *&%+&(1+ 9##!9$9(1!:
$!(*!$&(6 9 +0!?!839%!* 9##!9$9(1! !(932!% -',$ 1'(+$'2% +' &(+!6$9+! %!9?2!%%2- /&+0
'+0!$ ,%!$ &(+!$>91!%)
@0! F!-% +' $!(*!$&(6 9 +0!?!839%!* 9##!9$9(1! 9$! +0! 5?1&!":6$6-1: 5?1&!",6)&1: 9(*
5?1&!"8%-%"!&!-1 129%%!%) @0!%! 129%%!% #$'K&*! ,%!$8911!%%&32! &(%+9(1!% '> +0! 3$,%0!%:
>'(+%: 9(* ?&%1!229(!',% #9$9?!+!$% +09+ +0! 1,$$!(+ +0!?! ,%!%) E0!( +0! ,%!$ 109(6!%
+0! +0!?!: +0! 5?1&!" 1'2'$%: >'(+%: 9(* #9$9?!+!$% 9$! ,#*9+!* 9,+'?9+&1922- +' $!d!1+ +0!
(!/ +0!?!)
<', 19( 911!%% +0!%! %!++&(6% 9% $!%',$1!%) L!19,%! +0!- 9$! %-%+!? '34!1+%: +0!- 9$! 928
$!9*- *!129$!* 9(* *'(O+ (!!* +' 3! *!129$!* 9% $!%',$1!% &( -',$ 3!160-7!1 %!1+&'() <', 19(
3&(* 9 #$'#!$+- +' '(! '> +0!%! %-%+!? '34!1+%: 9% %0'/( &( 3'2* &( +0&% !"9?#2!;
<Label Background ="{DynamicResource {x:Static
SystemColors.ControlBrushKey}}" Content="Hello World" />
EB0FG $H-FG
■ O9!7&*+&79%&0*((%:%4.%&H%78%%4&!&,+%:&.'47:'$&!40&!&.,+7'"&.'47:'$S
EB0FG $H-FG &1@I-,
■ 2&,+%:&.'47:'$&*+&!&.'"#'+*7%&.'47:'$&.'"#'+%0&'(&#:%%<*+7*45&O>P&.'47:'$+&
H',40&7'5%79%:&H3&!&.'""'4&(,4.7*'4!$*73J&2&.,+7'"&.'47:'$&*+&!&,+%:E
0%?4%0&.'47:'$&.'"#'+%0&'(&!&4%8&.'47:'$&7%"#$!7%&!40&!&4%8&!++'.*!7%0&
(,4.7*'4!$*73J
www.it-ebooks.info
=>7 $%&'()* + E'$F&(6 /&+0 G%!$8H!I(!* J'(+$'2%
L!19,%! 5?1&!" $!%',$1!% '>+!( 9$! 109(6!* 3- +0! ,%!$: -', %0',2* ,%! +0!
9?)%"(73!160-7! ?9$F,# &(%+!9* '> +0! ?'$! >9?&2&9$ 5&%&(73!160-7! ?9$F,#) @0! *&>>!$!(1!
3!+/!!( %+9+&1 9(* *-(9?&1 $!%',$1!% &% !"#29&(!* &( D!%%'( T '> J09#+!$ e: UL,&2*&(6 9 G%!$
M(+!$>91!)Z
V'+! +09+ -', $!>!$ +' +0! $!%',$1! F!- &( +0&% !"9?#2!) M> -', /9(+ +' ,%! +0&% '34!1+ &(
1'*!: -', /',2* '?&+ +0! F!- %,>I": 9% %0'/( 0!$!;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Label1.Background = SystemColors.ControlBrush
!"#$%&'(&/1&/'0%
label1.Background = SystemColors.ControlBrush;
>:'C*0*45&69%"%E #%.*?.&6%"#$!7%+&(':&/,+7'"&/'47:'$+
M( %'?! 19%!%: -', ?&60+ /9(+ +' #$'K&*! 9 1'?#2!+!2- *&>>!$!(+ 9##!9$9(1! >'$ 9 1'(+$'2
/0!( &+ &% $!(*!$!* &( '(! +0!?! 9% '##'%!* +' 9('+0!$) <', 19( 1$!9+! +!?#29+!% +09+ 9$!
%#!1&I1 +' &(*&K&*,92 +0!?!% 9(* *!%&6(9+! +0!? >'$ ,%! /&+0 2!"!K)S6D&&-(/0&!@
@0! +!?#29+! *!I(!* &( +0! a!(!$&1)"9?2 I2! &% +0! +!?#29+! ,%!* >'$ !K!$- +0!?! +09+
*'!% ('+ 09K! 9 %#!1&I1 +!?#29+! *!I(!* >'$ &+) <', 1$!9+! +!?#29+!% >'$ %#!1&I1 +0!?!% 3-
1$!9+&(6 9( B=CD I2! (9?!* f 2!"!T%"!g)f 2!"!:6$6-g)"9?2: !"1!#+ >'$ +0! E&(*'/%
J29%%&1 +0!?!: /0&10 &% (9?!* %&?#2- J29%%&1)"9?2) @932! ]8e %0'/% %!K!$92 !"9?#2!% '>
E&(*'/% +0!?!% 9(* +0!&$ 1'$$!%#'(*&(6 B=CD I2!(9?!%)
(&J?) +KD [!2!1+!* E&(*'/% @0!?!% 9(* C9+10&(6 B=CD 7&2!(9?!%
<L:MN<; (%)O) P&O? CL?):&O)
E&(*'/% `&%+9 +0!?! =!$')V'$?92J'2'$)"9?2
H!>9,2+ E&(*'/% BQ +0!?! D,(9)V'$?92J'2'$)"9?2
[&2K!$ E&(*'/% BQ +0!?! D,(9)C!+922&1)"9?2
E&(*'/% J29%%&1 +0!?! J29%%&1)"9?2
V' ?9++!$ /0&10 +0!?!% -', #$'K&*! %#!1&I1 %,##'$+ >'$: -', ?,%+ 1$!9+! 9 >922391F +!?8
#29+! &( +0! a!(!$&1)"9?2 I2!)
M( 9**&+&'( +' 1$!9+&(6 92+!$(9+! +!?#29+!% &( +0!?!8%#!1&I1 I2!%: -', ?,%+ 9##2-
2!"!K)S6D&&-(/0&!@ @0&% &% 9( D11!"/$? 9++$&3,+!: 9(* &+ &% 9##2&!* &( +0! =%%!?32-M(>')K3 '$
=%%!?32-M(>')1% I2!) 2!"!K)S6D&&-(/0&! +9F!% +/' 9$6,?!(+%) @0! I$%+ 9$6,?!(+ *!%&6(9+!%
/0!$! +' 2''F >'$ +0!?!8%#!1&I1 +!?#29+!% 9(* $!%',$1!%: 9(* +0! %!1'(* 9$6,?!(+ &(*&19+!%
/0!$! +' 2''F >'$ 6!(!$&1 +!?#29+!%) Q'%%&32! K92,!% >'$ +0!%! 9$6,?!(+% 9$! 9% >'22'/%;
■ 3!160-7!9(7&(6)%-?M67%&(6)@T6)!; @0&% K92,! &(*&19+!% ('+ +' 2''F >'$ +0!?!8%#!1&I1
+!?#29+!%)
www.it-ebooks.info
D!%%'( _; J$!9+&(6 J,%+'? J'(+$'2% &( EQ7 $%&'()* + =>8
■ 3!160-7!9(7&(6)%-?M67%&(6)@560-7!D11!"/$?; @0&% K92,! &(*&19+!% +' 2''F &( +0! %',$1!
9%%!?32-)
■ 3!160-7!9(7&(6)%-?M67%&(6)@J;&!-)%$D11!"/$?; @0&% K92,! &(*&19+!% +' 2''F &( 9( !"8
+!$(92 9%%!?32-: /0&10 ?,%+ 3! (9?!* fD11!"/$?T%"!g)f 2!"!T%"!g)*22: /0!$!
fD11!"/$?T%"!g &% +0! 1,$$!(+ 9%%!?32- (9?! 9(* f 2!"!T%"!g &% +0! (9?! '>
+0! 9##$'#$&9+! +0!?!)
@0! >'22'/&(6 !"9?#2! *!?'(%+$9+!% 2!"!K)S6D&&-(/0&!;
!"#$%&'(&)*+,!$&-!+*.&/'0%
<Assembly: _
ThemeInfo(ResourceDictionaryLocation.SourceAssembly, _
ResourceDictionaryLocation.SourceAssembly)>
!"#$%&'(&/1&/'0%
[assembly: ThemeInfo(ResourceDictionaryLocation.SourceAssembly,
ResourceDictionaryLocation.SourceAssembly)]
<', 19( ,%! +0&% +!10(&A,! +' #$'K&*! +0!?!8%#!1&I1 $!%',$1! *&1+&'(9$&!% 9% /!22) .X!8
%',$1! *&1+&'(9$&!% 9$! *&%1,%%!* &( J09#+!$ e: UL,&2*&(6 9 G%!$ M(+!$>91!)Z5 @0! '(2- 9*4,%+8
?!(+ -', 09K! +' ?9F! &% +' 1$!9+! 9 @0!?!% >'2*!$ &> &+ *'!% ('+ !"&%+) <', ?,%+ 92%' 1$!9+! 9
a!(!$&1)"9?2 I2! +09+ &(12,*!% 9 $!%',$1! %!+ >'$ 9(- +0!?!% +09+ 9$! ,(%,##'$+!*)
#$%&'"()
2$79',59&*7&*+&*"#':7!47&7'&,40%:+7!40&79%&0*((%:%4.%+&H%78%%4&O*40'8+&P':"+&.,+7'"&
.'47:'$+&!40&O>P&.,+7'"&.'47:'$+&89%4&7!I*45&79%&%<!"K&79%&%<!"&*+&"':%&$*I%$3&7'&('.,+&
'4&O>P&.'47:'$&.:%!7*'4K&+'&H%&+,:%&3',&,40%:+7!40&!$$&!+#%.7+&'(&79*+&#:'.%++K&%+#%.*!$$3&
.'47:'$&7%"#$!7%+&!40&,+*45&79%"%+J
$%&'()'* $,-./012 . $B@/35 $31/,34
M( +0&% #$91+&1!: -', 1$!9+! 9 1,%+'? 1'(+$'2 +09+ +9F!% +0! >'$? '> 9 *&6&+92 12'1F +09+ &%
,#*9+!* !K!$- %!1'(*) <', 1$!9+! 9 *!#!(*!(1- #$'#!$+- +09+ $!#$!%!(+% +0! 1,$$!(+ +&?!
9(* &?#2!?!(+ +0! >,(1+&'(92&+- +' ,#*9+! +0&% #$'#!$+- !K!$- %!1'(*) <', +0!( 1$!9+! +0!
*!>9,2+ +!?#29+! >'$ -',$ 1'(+$'2 9(* 3&(* !;&'$67B &( +09+ +!?#29+! +' +0! ("! #$'#!$+-)
7&(922-: -', 1$!9+! 9 +!%+ #$'4!1+ +' +!%+ -',$ (!/ 1'(+$'2)
*+*%'),* /:%!7*45&!&/,+7'"&/'47:'$
!" J$!9+! 9 (!/ EQ7 J,%+'? J'(+$'2 D&3$9$- #$'4!1+: ,%&(6 +0! +!?#29+! &( +0! E&(*'/%
#$'4!1+ +-#!)
#" M( 1'*! K&!/: 1$!9+! K9$&932!% +09+ $!#$!%!(+ 9 5?1&!"@ ("!-1@ ("!- 129%% 9(* 9
*!#!(*!(1- #$'#!$+- (9?!* ("!8-6#!-&?@ =2%': *!129$! 9 (!/ *!2!69+! 1922!*
5!&&!-9!$!+%&! +09+ +9F!% (' 9$6,?!(+%: 9% %0'/( 0!$!;
www.it-ebooks.info
=>9 $%&'()* + E'$F&(6 /&+0 G%!$8H!I(!* J'(+$'2%
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Shared ReadOnly TimeProperty As DependencyProperty
Private myTimer As New System.Timers.Timer
Delegate Sub SetterDelegate()
!"#$%&'(&/1&/'0%
public static readonly DependencyProperty TimeProperty;
System.Timers.Timer myTimer = new System.Timers.Timer();
delegate void SetterDelegate();
-" M( +0! %09$!* .%+9+&15 1'(%+$,1+'$: 9** +0! >'22'/&(6 1'*! +' $!6&%+!$ 9 (!/ *!#!(*!(1-
#$'#!$+-) V' 9$6,?!(+% 9$! (!1!%%9$- >'$ +0! ?!+9*9+9 >'$ +0&% #$'#!$+-;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Dim metadata As New FrameworkPropertyMetadata()
TimeProperty = DependencyProperty.Register("Time", GetType(String), _
GetType(CustomControl1), metadata)
!"#$%&'(&/1&/'0%
FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata();
TimeProperty = DependencyProperty.Register("Time", typeof(string),
typeof(CustomControl1), metadata);
." J$!9+! 9( &(%+9(1! 1'(%+$,1+'$ +09+ &(&+&92&R!% ("!- 9(* %!+% +0! 9%&%:6)&!;& #$'#!$+-)
M( 9**&+&'(: 9** 9 09(*2!$ >'$ +0! ("!-@J$%#1!* !K!(+) .<', /&22 1$!9+! +0! ?!+0'* +09+
09(*2!% +0&% !K!(+ &( 9 %,3%!A,!(+ %+!#)5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Sub New()
AddHandler myTimer.Elapsed, AddressOf timer_elapsed
myTimer.Interval = 1000
myTimer.Start()
Me.DataContext = Me
End Sub
!"#$%&'(&/1&/'0%
public CustomControl1()
{
myTimer.Elapsed += timer_elapsed;
myTimer.Interval = 1000;
myTimer.Start();
this.DataContext = this;
}
/" J$!9+! 9 ?!+0'* +09+ %!+% +0! ("! #$'#!$+- +' 9 %+$&(6 +09+ $!#$!%!(+% +0! 1,$$!(+
+&?! &( +0! 2'(6 +&?! >'$?9+) @0&% ?!+0'* &% 1922!* 3- 9(1#%&72!- &( +0! ("!-@NJ$%#1!*
!K!(+ 09(*2!$) V'+! +09+ -', 9$! %!++&(6 +0! ("! #$'#!$+- *&$!1+2- +0$',60 +0!
5!&R%$0! ?!+0'* &( EQ7) L!19,%! +0&% #$'#!$+- &% ('+ ?!9(+ +' 3! %!+ 3- '+0!$
1'(+$'2%: -', *' ('+ (!!* +' #$'K&*! 9 )VS@ #$'#!$+- /$9##!$ >'$ +0&% *!#!(*!(1-
#$'#!$+-)
www.it-ebooks.info
D!%%'( _; J$!9+&(6 J,%+'? J'(+$'2% &( EQ7 $%&'()* + =>"
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub TimeSetter()
SetValue(TimeProperty, Now.ToLongTimeString)
End Sub
!"#$%&'(&/1&/'0%
void TimeSetter()
{
SetValue(TimeProperty, DateTime.Now.ToLongTimeString());
}
0" J$!9+! +0! &("!-E!$%#1!* ?!+0'* +' 09(*2! +0! ("!-@J$%#1!* !K!(+) L!19,%! ("!-
1'*! &% !"!1,+!* '( 9 *&>>!$!(+ +0$!9* >$'? +0! ,%!$ &(+!$>91!: +0&% ?!+0'* %0',2* ,%!
9(1#%&72!- +' &(K'F! +0! ("!5!&&!- ?!+0'* %9>!2-) =( !"9?#2! &% %0'/( 0!$!;
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub timer_elapsed(ByVal sender As Object, ByVal e As _
System.Timers.ElapsedEventArgs)
Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Normal, _
New SetterDelegate(AddressOf TimeSetter))
End Sub
!"#$%&'(&/1&/'0%
void timer_elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new SetterDelegate(TimeSetter));
}
1" M( ['2,+&'( S"#2'$!$: !"#9(* +0! @0!?!% >'2*!$ 9(* *',32!812&1F a!(!$&1)"9?2 +' '#!(
+0! a!(!$&1)"9?2 I2! &( B=CD K&!/) E&+0&( +0! '6-*!- *!129$9+&'(: 9** +0! >'22'/&(6
B=CD 1'*! +' 1$!9+! +0! K&%,92 +!?#29+! >'$ -',$ 1'(+$'2;
<TextBlock Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding
Path=Time}" />
2" Q$!%% 7\ +' 3,&2* -',$ 1'(+$'2)
3" V'/ -', /&22 9** 9 #$'4!1+ +' +!%+ -',$ 1'(+$'2) 7$'? +0! 7&2! ?!(,: 10''%! =**
9(* +0!( 10''%! V!/ Q$'4!1+) @0! =** V!/ Q$'4!1+ *&92'6 3'" '#!(%) J0''%! EQ7
=##2&19+&'( 9(* 12&1F bc)
!4" M( ['2,+&'( S"#2'$!$: $&60+812&1F +0! (!/ #$'4!1+ 9(* 10''%! =** X!>!$!(1! +' '#!( +0!
=** X!>!$!(1! *&92'6 3'") J0''%! +0! Q$'4!1+% +93 9(* +0!( %!2!1+ +0! 1,%+'? 1'(+$'2
2&3$9$- -', 1$!9+!* &( +0! #$!K&',% %+!#%) J2&1F bc)
!!" M( +0! (9?!%#91!% %!1+&'( '> -',$ B=CD 1'*! >'$ +0! +!%+ #$'4!1+: 9** +0! >'22'/&(6
2&(! +' &?#'$+ +0! 1,%+'? 1'(+$'2 (9?!%#91! &(+' -',$ #$'4!1+) V'+! +09+ &> -',$ #$'48
!1+ 9(* (9?!%#91! 9$! 1922!* %'?!+0&(6 '+0!$ +09( D!%%'(_: -', 09K! +' ?'*&>- +0&%
2&(! 911'$*&(62-;
xmlns:MyNamespace="clr-namespace:Lesson3;assembly=Lesson3"
www.it-ebooks.info
=D> $%&'()* + E'$F&(6 /&+0 G%!$8H!I(!* J'(+$'2%
!#" =** +0! >'22'/&(6 B=CD /&+0&( +0! I-(* *!129$9+&'( &( +0! B=CD 1'*! >'$ -',$ +!%+
#$'4!1+;
<MyNamespace:CustomControl1/>
=( &(%+9(1! '> -',$ 1'(+$'2 &% 9**!* +' -',$ +!%+ #$'4!1+)
!-" M( ['2,+&'( S"#2'$!$: $&60+812&1F -',$ +!%+ #$'4!1+ 9(* %!2!1+ [!+ =% [+9$+,# Q$'4!1+) Q$!%%
7] +' 3,&2* 9(* $,( -',$ #$'4!1+)
A%++'4& ,""!:3■ @0! 10'&1! 9?'(6 +!?#29+!%: 1,%+'? 1'(+$'2%: 9(* ,%!$ 1'(+$'2% %0',2* 3! 39%!* '(
>,(1+&'(92&+-) M> 9( !"&%+&(6 EQ7 1'(+$'2 1'(+9&(% +0! >,(1+&'(92&+- -', (!!*: 1$!9+! 9
+!?#29+! +' #$'K&*! 9 (!/ 9##!9$9(1! >'$ &+) M> ?,2+! !"&%+&(6 EQ7 1'(+$'2% 19( 3!
3',(* +'6!+0!$ /&+0 1'*! +' 1$!9+! -',$ (!!*!* >,(1+&'(92&+-: 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2% &( EQ7)Z @0! A,!%+&'(% 9$! 92%' 9K9&2932! '( +0! 1'?#9(&'( JH &>
-', #$!>!$ +' $!K&!/ +0!? &( !2!1+$'(&1 >'$?)
!"# &:;<)*;
24+8%:+&7'&79%+%&D,%+7*'4+&!40&%<#$!4!7*'4+&'(&893&%!.9&!4+8%:&.9'*.%&*+&.'::%.7&':&*4.':E
:%.7&!:%&$'.!7%0&*4&79%&F24+8%:+G&+%.7*'4&!7&79%&%40&'(&79%&H''IJ
!"# &:;<)*;
24+8%:+&7'&79%+%&D,%+7*'4+&!40&%<#$!4!7*'4+&'(&893&%!.9&!4+8%:&.9'*.%&*+&.'::%.7&':&*4.':E
:%.7&!:%&$'.!7%0&*4&79%&F24+8%:+G&+%.7*'4&!7&79%&%40&'(&79%&H''IJ
www.it-ebooks.info
2 Module 3: Building Controls
Lesson: Options for Creating Controls
� Extending an Existing Control
� Composite Controls
� Custom Controls
Custom
Control
ComponentStandard IComponent Impl
ControlBasic HWND Wrapper
Scrollable Control
Container Control
UserControl
Textbox ButtonComposite Controls
Form
Extended Controls
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Windows Forms provides several options for authoring controls. You can combine existing controls, extend existing controls, or author your own custom controls. This lesson provides background information on the various options that are available for creating Windows Forms controls.
After completing this lesson, you will be able to:
� Determine the various options for authoring controls.
� Describe extending an existing control.
� Describe composite controls.
� Describe custom controls.
Introduction
Lesson objectives
Module 3: Building Controls 3
What is Extending an Existing Control?
� You can extend any existing control using inheritance
� When you extend a control, you can
� Use the members of the inherited classOR
� Override the members of the inherited classOR
� Create your own custom members
Public Class NumericTextBoxInherits System.Windows.Forms.TextBox
…End Class
Public Class NumericTextBoxInherits System.Windows.Forms.TextBox
…End Class
*****************************ILLEGAL FOR NON-TRAINER USE******************************
One of the options for creating a Windows Forms control is to extend an existing control. You can extend an existing control to customize it or add additional functionality to it. Extend an existing control if the control you want to create is quite similar in functionality to an existing control.
You can customize any Windows Forms control by deriving from it and overriding its properties, methods, and events. This entire procedure of creating a customized control from an existing control is referred to as extending a control. When you inherit from an existing a control, you have the option of using the members of the inherited class, overriding the members of the inherited class, or creating your own custom members.
When inheriting from an existing control, you use the base keyword to implement the constructor of the inherited object. This is required because constructors are not inherited. The following example shows how to implement the functionality provided by the default constructor in an extended class.
public NumericTextBox():base()
Some examples of extended controls include a text box that can only accept numeric values or a button that has some additional properties, such as a property that can record how many times the button has been clicked.
The following code example shows a numeric text box that is inherited from the Windows TextBox control. It also shows how the OnKeyPress event of the base TextBox class is overridden to provide custom functionality.
public class NumericTextBox : System.Windows.Forms.TextBox
protected override void
OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
Since this control inherits from TextBox, all the members associated with the TextBox control are exposed within the extended control. For example, you can
Introduction
Definition
Example of extending a control
4 Module 3: Building Controls
use the functionality of the Clear() method of the of TextBox control from the extended control.
myNumericControl = New NumericTextBox();
myNumericControl.Clear;
Module 3: Building Controls 5
What Is a Composite Control?
ComponentStandard IComponent Impl
ControlBasic HWND Wrapper
Scrollable Control
Container Control
UserControl
Textbox ButtonComposite Controls
Form
Extended Controls
� Composite Controls
� Controls that are composed of other controls
� Designed to act as containers for other controls
� Derive from the UserControl class which inherits from ContainerControl
� ContainerControl Class
� Supports methods for adding, removing, and retrieving components
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Another way of creating your own controls is to combine existing controls to create composite controls. Create composite controls when you need complex functionality that requires the use of more than one control.
You can create new controls by combining existing controls using class composition. A composite control renders a user interface that reuses the functionality of existing controls. A composite control can synthesize properties from the properties of its child controls and handle events raised by its child controls. It can also expose custom properties and events. Composite controls can act as containers for other controls because they extend the ContainerControl class.
All composite controls derive from System.Windows.Forms.UserControl. There is full design-time support for creating composite controls with the Visual Studio.NET Windows Forms Designer.
The ContainerControl class defines a logical boundary for controls that it contains. This class provides focus management, which means that it is aware of active controls and can change focus from one control to another. It also supports methods for adding, removing, and retrieving children controls. The Form class also inherits from the ContainerControl class.
For more information about the ContainerControl class, see “ContainerControl Class” in the Visual Studio .NET Help documentation.
Introduction
Definition
ConatinerControl Class
6 Module 3: Building Controls
What is a Custom Control?
� Custom Controls
� Typically derive from the Control class
� Display UI by making calls to a Graphics object in the Paint event
� To create a custom control
� Inherit from the Control class, which draws a blank square on your form by default
� Override the OnPaint event of the Control class
� Use GDI+ to draw your own UI
public class VerticalLabel : System.Windows.Forms.Control
public class VerticalLabel : System.Windows.Forms.Control
*****************************ILLEGAL FOR NON-TRAINER USE******************************
If you do not want to combine or extend existing controls, you have the option of creating your own custom controls.
Custom controls display user-interface (UI) elements by making calls to a GDI+ Graphics object in the OnPaint event. Custom controls are generally derived from the base class System.Windows.Forms.Control.
public class VerticalLabel : System.Windows.Forms.Control
To create a custom control, you generally inherit from the Control class, which draws a blank square on your form, override the OnPaint event of the Control class and use GDI+ to draw your own UI. For more information about using GDI+ in greater detail, see Module 6, “Reporting and Printing in Windows Forms Applications,” in Course 2555A, Developing .NET Windows Applications (Visual C# ..NET).
You can add as well as override properties, methods, and events of the base class (Control). The base class provides the plumbing required for visual display in client-side Windows applications. The Control class provides a window handle, manages message routing, and provides mouse and keyboard events as well as many other user interface events. It provides advanced layout and has properties specific to visual display, such as ForeColor, BackColor, Height, Width, and many others.
Introduction
Definition
Module 3: Building Controls 7
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
public class CustomControl : System.Windows.Forms.Control
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawString("Written with GDI+ on OnPaint event",
New Font(Arial”,12), New SolidBrush(Color.Red), 0, 0);
}
Example of a Custom control
8 Module 3: Building Controls
Code Walkthrough: Creating Controls
� In this exercise, you will see the code that is involved in creating different controls.
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this walkthrough, you will see examples of extended, composite, and custom controls. The instructor will walk you through the code required to extend a control, create a composite control, and build a custom control.
◮ Open the project file for this code walkthrough
1. Start Visual Studio .NET.
2. On the Start Page window, click Open Project.
3. In the Look in list, navigate to the install_folder\Democode\Mod03_01\Starter\Controls folder, and then open
the Controls.sln file.
◮ Walkthrough the NumericTextBox control
1. Open the code view of NumericTextBox.cs.
2. Point out the following line of code. Explain that in order to create an
extended control, you inherit directly from an existing control.
public class NumericTextBox : System.Windows.Forms.TextBox
3. Scroll to the following line of code. You can override the events of the base
control.
protected override void
OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
4. Scroll to the following line of code to explain that you can also override the
properties of the base control.
public override string Text
◮ Walkthrough the OrderItemControl
1. Open the design view of OrderItemControl.cs.
Introduction
Instructions
Module 3: Building Controls 9
2. Composite controls are composed of a UserControl and one or more
controls. Explain the significance of the controls contained within the
UserControl.
3. Open the code view of OrderItemControl.cs.
4. A composite control inherits from the UserControl class. Point out the
following line of code.
public class OrderItemControl :
System.Windows.Forms.UserControl
5. To access the properties of constituent controls, you must expose them
explicitly. Scroll down to the following lines of code to show how the properties of constituent controls are exposed.
public int OrderQuantity
{
get
{
return Convert.ToInt32(QuantityNumericTextBox.Text);
}
set
{
QuantityNumericTextBox.Text = value.ToString();
}
}
6. The OrderItemControl exposes a method that binds data to constituent controls. Explain the significance of the following procedure.
public void GetProductData(System.Data.DataTable
dsproducts)
◮ Walkthrough the VerticalLabel control
1. Open the code view of VerticalLabel.cs.
2. Custom controls generally inherit from the Control class. Explain the significance of the following line of code.
public class VerticalLabel : System.Windows.Forms.Control
3. To implement a custom control you must override the OnPaint event and use GDI+ to draw the control. Explain the following procedure to show how
to override the OnPaint event of the Control class.
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
4. The Control class exposes many properties, methods, and events that can be
overridden. These properties, methods, and events are shared by all controls. Explain the significance of the following line of procedure.
public override string Text
◮ Display the controls at design-time within the Controls_Host project
1. In Solution Explorer, right-click the Controls project, and then click Build
Solution.
2. In the Controls_Host project, open the design view of Form1.cs.
3. On the Tools menu, click Customize Toolbox.
10 Module 3: Building Controls
4. In the Customize Toolbox dialog box, click the .NET
FrameworksComponents tab, and then click Browse.
5. In the Open dialog box, select Controls.dll from
install_folder\2555A\Democode\Mod03_01\Starter\Controls\obj\Debug\, click Open, and then click OK.
6. Add a NumericTextBox to Form1 under the designated label. Attempt to set the Text property to a non-numeric value.
The control enforces the property logic at design time.
7. Add an OrderItemControl to Form1 under the designated label.
8. In the Properties window, display the OrderQuantity property.
The OrderItemControl property exposes the property of a constituent control.
9. Add a VerticalLabel to Form1 under the designated label.
10. Set the ForeColor property to ActiveCaption and the Font property to Italic.
The OnPaint event fires at design time as it will at run time.
◮ Display the controls at run time within the Controls_Host project
1. On Form1, select the SQLConnection1 connection object, and then set the
ConnectionString property to connect to an instance of Microsoft SQL
Server™ with the Northwind database installed.
2. In Solution Explorer, right-click the Controls_Host project, and then click
Set as Startup Project.
3. Press F5 to run the application
4. Attempt to enter non-numeric characters into the NumericTextBox control.
The control enforces property logic at run time.
5. Navigate through the products within the OrderItemControl.
The constituent controls are data bound.
Module 3: Building Controls 11
Lesson: Adding Functionality to Controls
� How to Expose and Override Properties for Controls
� How to Raise and Override Events for Controls
� How to Test a Composite Control
� Practice: Creating a Composite Control
*****************************ILLEGAL FOR NON-TRAINER USE******************************
When creating controls, you can add additional functionality to the controls by overriding properties, methods, and events and also by creating and raising new properties and events. This lesson describes how to add additional functionality to controls by creating new properties, and raising new events for composite controls. The lesson also describes how to test a composite control in an application.
After completing this lesson, you will be able to:
� Create properties for controls.
� Raise events for controls.
� Test a control.
� Create a control.
Introduction
Lesson objectives
12 Module 3: Building Controls
How to Expose and Override Properties for Controls
� Exposing properties of a control within a container
� Overriding properties
public ContextMenu QuantityTextBox_ContextMenu{get
{return QuantityTextBox.ContextMenu;
}set{
QuantityTextBox.ContextMenu = value;}
}
public ContextMenu QuantityTextBox_ContextMenu{get
{return QuantityTextBox.ContextMenu;
}set{
QuantityTextBox.ContextMenu = value;}
}
public ReadOnly String MyProperty{
get{
…}
}
public ReadOnly String MyProperty{
get{
…}
}
*****************************ILLEGAL FOR NON-TRAINER USE******************************
A Windows Forms control inherits many properties form the base class System.Windows.Forms.Control. These include properties such as Font, ForeColor, BackColor, Bounds, ClientRectangle, DisplayRectangle, Enabled, Focused, Height, Width, Visible, as well as many others. You can override inherited properties in your control as well as define new properties.
A component should define properties instead of public fields because visual designers such as Visual Studio .NET display properties, but not fields, in the property browser.
Property definitions include two parts: a private variable to hold the value of a property for an instance of a control, and a property definition that exposes the private variable.
While a property definition generally includes a private data member, this is not required. The Get accessor can return a value without accessing a private data member. For example, a property whose get method returns the system time. Properties enable data hiding, in which the accessor methods hide the implementation of the property.
The properties for controls contained by composite controls are not directly exposed to developers. For example, to access the Text property of a text box within a composite control, you may have to iterate through the Controls collection of the composite control to access the property. A common practice with composite controls is to expose properties of child controls as properties of the composite control.
Introduction
Property definitions
Procedure: Exposing properties of control within a container
Module 3: Building Controls 13
The following code example shows how to expose the ContextMenu property of a control contained in a composite control.
public ContextMenu QuantityTextBox_ContextMenu
{
get
{
return QuantityTextBox.ContextMenu;
}
set
{
QuantityTextBox.ContextMenu = value;
}
}
The Get and Set methods are generally not different from other methods. They can perform any program logic, throw exceptions, be overridden, and can be declared with any modifiers allowed by the programming language. You can make a property read-only or write-only by using the ReadOnly and WriteOnly key words, and only using a Get or Set accessor respectively. The following code is an example of a ReadOnly Property.
public ReadOnly String MyProperty
{
get
{
…
}
}
When you extend an existing control, you can override the properties of the base class to provide custom functionality. The following code example overrides the Text property of the TextBox control and allows only numeric characters to be set on the property.
Procedure: Overriding properties
14 Module 3: Building Controls
public class NumericTextBox : System.Windows.Forms.TextBox
public override string Text
{
get
{
return base.Text;
}
set
{
try
{
int.Parse(value);
base.Text = value;
return;
}
catch
{}
if (value == null)
{
base.Text = value;
return;
}
}
}
When overriding members of an extended class, use the base keyword to implement the functionality of the base member. The example above uses base.Text to refer to the property in the derived class.
Module 3: Building Controls 15
How to Raise and Override Events for Controls
� To raise events for a composite control
� To override events
public delegate void MyEvent(StringstringPassed);
public event MyEvent InvokeMyEvent///to invoke the eventInvokeMyEvent("Pass this string to host")
public delegate void MyEvent(StringstringPassed);
public event MyEvent InvokeMyEvent///to invoke the eventInvokeMyEvent("Pass this string to host")
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
*****************************ILLEGAL FOR NON-TRAINER USE******************************
When authoring controls, you can raise your own custom events or override the events of the base class.
When creating controls, you use events to notify host applications when something occurs within a control. To create an event, create a delegate and define any parameters to be passed to the host when the event is invoked. Then declare an event using the event keyword and reference the delegate to invoke and name the event. To invoke the event within the control, call the event and pass the required parameters.
The following code example defines an event called MyEvent that passes a string data type when invoked.
public delegate void MyEvent(String stringPassed);
public event MyEvent InvokeMyEvent
///to invoke the event
InvokeMyEvent("Pass this string to host")
You can then make the host application aware of the control event by delegating a procedure to the event. You use the same Handles or AddHandler keywords to handle a custom event that you use with the intrinsic controls.
The Control class provides a base set of events that allow you to monitor activities such as property modifications and user actions. When you create controls, you can access events exposed by the Control class and other base classes by overriding them. Each base event provides event-specific information with the EventArgs parameter. This parameter (and parameters that derive from it such as KeyEventArgs and MouseEvtsArgs) provides event specific information, such as which key was pressed or the X,Y position of the mouse cursor.
Introduction
Procedure: Raising events
Procedure: Overriding an event
16 Module 3: Building Controls
The following code shows how to override an event. The example overrides the OnKeyPress event of a TextBox control. The event contains a KeyPressEventArgs parameter that contains data about the keys that were pressed (e.KeyChar) and a Boolean value (e.Handled) that allows you to indicate if the event was handled (True) or if the event should be passed to Windows for processing (False). If the event is handled in the procedure, then it raises a custom event and passes an instance of the object along with the KeyPressEventArgs passed to the event.
protected override void
OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
int asciiInteger = Convert.ToInt32(e.KeyChar);
if (asciiInteger >= 47 && asciiInteger <= 57)
{
e.Handled = false;
return;
}
if (asciiInteger == 8)
{
e.Handled = false;
return;
}
e.Handled = true;
if (InvalidUserEntry != null)
InvalidUserEntry(this, e);
}
Module 3: Building Controls 17
How to Test a Composite Control
Create a new project within the same window
Add the user control to the Toolbox
Add the user control to the form from the Toolbox
UserControl System.Windows.Forms System.Windows.Forms(1.0.3300.0)
UserControl1
*****************************ILLEGAL FOR NON-TRAINER USE******************************
The Microsoft .Net Framework eliminates many of the original problems with versioning that existed with COM. For example, you can have more than one version of a component supporting different applications without having to be concerned with backwards compatibility.
When you create and compile a Windows application using the Visual Studio .NET integrated development environment (IDE), any external assemblies referenced within the application are built into the /Bin folder of the application. Because the application has its own copy of the component, any modification to the original component will not affect it. However, if you are testing a component within an application, you must remove the previous component and add the newer one every time you modify the component.
If you want to test a component without adding a new reference to the control every time you modify the control, you can add a forms application to the component solution. The Visual Studio .NET IDE is aware of the component project and adds an implicit reference to the component. This reference is automatically updated whenever you rebuild the component.
1. Create a new form in the same project.
2. Add the user control to the Toolbox.
3. Add the user control to the form from the Toolbox.
After you add the user control to the toolbox, it is visible on the toolbox. To add the user control to the project, drag the control to the form, just as you do with other controls.
Introduction
Procedure
18 Module 3: Building Controls
Practice: Creating a Composite Control
� In this practice, you will create a composite control.
� Create a Windows Control Library Project and add a UserControl
� Add controls to the UserControl
� Expose properties
� Raise events
� Test the design-time instance
� Test the run-time instance
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this practice, you will build a composite control that displays the current time. The composite control includes a Label to display the time and a Timer control. The Timer control has a Tick event that fires repeatedly with a period based on the Interval property. The default value of the Interval property is 100 milliseconds, meaning that the Tick event will fire every second.
You will create a composite control that exposes properties of the Label and Timer controls and raises the Tick event to host applications.
◮ Create a Windows Control Library project and add a UserControl
1. Open Visual Studio .NET.
2. On the File menu, point to New, and then click Project.
3. In the New Project dialog box, click Windows Control Library, name it DigitalClock, and then click OK.
4. On the Project menu, click Add UserControl, name it DigitalClock.cs, and then click Open.
◮ Add controls to the UserControl
1. Add the following controls to the UserControl.
Control Name Text Label LocalTimeLabel “”
Timer Timer1
2. Set BackColor of LocalTimeLabel to ControlDark.
Introduction
Module 3: Building Controls 19
3. Center LocalTimeLabel within the UserControl. Your UserControl
should look like the following.
◮ Add code to expose the properties of LocalTimeLabel and Timer1 to
the host application
1. Create a Public property named Timer1_Enabled that exposes the Boolean
Enabled property of Timer1. Your code should look like the following.
public bool Timer1_Enabled
{
get
{
return Timer1.Enabled;
}
set
{
Timer1.Enabled = value;
}
}
2. Create a Public property named LocalTimeLabel_BackColor that exposes
the BackColor property of LocalTimeLabel. Your code should look like
the following.
public Color LocalTimeLabel_BackColor
{
get
{
return LocalTimeLabel.BackColor;
}
set
{
LocalTimeLabel.BackColor = value;
}
}
◮ Add code that raises the Timer1.Tick event to host applications
1. Declare a Public event named RaiseTimer1_Tick that passes uses the EventHandler delegate.
2. Create the Timer1_Tick event procedure and update the Text property of LocalTimeLabel to reflect the current time (use the Now.ToString
function).
3. Within the Timer1_Tick event procedure, raise the RaiseTimer1_Tick
event and pass the sender and e event arguments.
Your code should look like the following.
20 Module 3: Building Controls
public event System.EventHandler RaiseTimer1_Tick;
private void Timer1_Tick(object sender, System.EventArgs e)
{
LocalTimeLabel.Text = System.DateTime.Now.ToString();
if (RaiseTimer1_Tick != null)
RaiseTimer1_Tick(sender, e);
}
◮ Test the design-time instance of your Composite Control in a host
application
1. On the Build menu, click Build Solution to compile the DigitalClock
control.
2. On the File menu, click Add Project, and then click New Project.
3. Create a new Windows Application and name it TestClock.
4. Add the DigitalClock control from the Toolbox to Form1 in TestClock.
5. In the Properties window, set the Timer1_Enabled property to True.
The DigitalClock control is running while the host application is in design mode.
6. In the Properties window set the LocalTimeLabel_Color property to ControlLight.
This property would not be available to developers within the IDE if you did not explicitly expose it using a property procedure.
7. Add a Label to Form1 and name it UniversalTimeLabel.
8. Create the DigitalClock1_RaiseTimer1_Tick event procedure and update the Text property of UniversalTimeLabel to reflect the coordinated
universal time (use the Now.UtcNow function). Your code should look like the following.
private void DigitalClock1_RaiseTimer1_Tick(object sender,
System.EventArgs e)
{
UniversalTimeLabel.Text =
DateTime.Now.ToUniversalTime().ToString();
}
9. Add a Button to Form1 and name it StartStopButton.
10. Create the StartStopButton_Click event procedure and toggle the
Timer1_Enabled property of DigitalClock1 within the procedure. Your code should look like the following:
private void StartStopButton_Click(object sender,
System.EventArgs e)
{
DigitalClock1.Timer1_Enabled =
!(DigitalClock1.Timer1_Enabled);
}
◮ Test the runtime instance of your control in a host application
Module 3: Building Controls 21
1. Place a breakpoint on the Get and Set statements of the Timer1_Enabled
event procedure within the DigitalClock composite control.
2. In Project Explorer, right-click TestClock project, and then click Set as
Startup Project.
3. Press F5 to compile and run the application.
4. Step through each line of the code in the debug mode by pressing F11.
5. Click StartStopButton and step through each line of code in debug mode by pressing F11.
By adding a test host project to the control project, you can easily debug the control. In addition, you will not be required to refresh the reference to the control every time you rebuild it.
◮ Test the DigitalClock in separate instances of Visual Studio .NET
(Optional)
1. Open a new instance of Visual Studio .NET
2. On the File menu, click Add Project, and then click New Project.
3. Create a new Windows application and name it TestClock2.
4. On the Tools menu, click Customize Toolbox.
5. Click the .NET Framework Components tab, and then click Browse.
6. In the Open dialog box, navigate to the DigitalClock.dll located in the \bin directory of the DigitalClock project, click Open, and then click OK.
7. Add a DigitalClock control to Form1.
8. Switch back to the Visual Studio .NET instance that includes the DigitalClock source code and set the BackColor property of
LocalTimeLabel to ControlLightLight
9. On the Build menu, click Rebuild Solution.
10. Switch back to the Visual Studio instance that includes the TestClock2 project and run it by pressing F5.
The control displays the original value (ControlDark) and not the most recent one (ControlLightLight). To update the TestClock2 project to use the most recent DigitalClock control, you need to refresh the reference to the control.
22 Module 3: Building Controls
Lesson: Adding Design-Time Support for Controls
� Property Attributes
� How to Add Attributes that Provide Information to the Visual Designer
� Design Time Support Options Built into the .NET Framework
� Practice: Adding Design-Time Support for Controls
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Design-time attributes are essential in order to display a control and its members correctly at design time because they provide valuable information to a visual design tool. This lesson describes some of the design time options that are built into the .NET Framework. The lesson also describes how to add the attributes that provide information to the visual design tool.
After completing this lesson, you will be able to:
� Describe property attributes.
� Add attributes that provide information to the Visual Designer.
� Describe the built-in design-time options for components in Visual Studio
.NET.
Introduction
Lesson objectives
Module 3: Building Controls 23
Property Attributes
� Property Attributes
� Allow you to specify the behavior of properties at design time
� Property attributes allow you to specify
� Grouping options for custom properties in the Properties window of the Visual Studio .NET environment
� Default values
� Custom editors for custom properties
� Examples of Property Attributes
� Browsable
� Category
� Description
� DefaultProperty
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Attributes associate design-time functionality with a component. Design-time attributes can be applied to properties, events, classes, and even assemblies.
Attributes are the glue that binds design-time functionality to a component. Property attributes allow you to specify the behavior of properties at design time. Attributes can also be applied at the control level and to events as well. In the .NET Framework, design-time functionality is implemented not within a component but outside the component, and it is associated with the component through metadata supplied by custom attributes.
Property attributes allow you to specify:
• Grouping options for custom properties in the Properties window of the
Visual Studio .NET environment.
• Default values.
• Custom editors for custom properties.
The following table lists some of the property attributes and their descriptions.
Property Attributes Description Browsable Specifies whether a property or an event
should be displayed in the property
browser.
Category Specifies the name of the category in
which to group a property or event. When
categories are used, component properties
and events can be displayed in logical
groupings in the property browser.
Description Defines a small block of text to be
displayed at the bottom of the property
browser when the user selects a property
or event.
Introduction
Definition
List of property attributes
24 Module 3: Building Controls
DefaultProperty Specifies the default property for the
component. This property is selected in
the property browser when a user clicks
on the control.
DefaultValue Sets a default value for a property.
TypeConverter Specifies the type converter to use for
converting the type of the property to
another data type.
Editor Specifies the editor to use for editing
(changing) a property in a visual designer.
RefreshProperties Indicates how a designer refreshes when
the associated property value changes.
This class cannot be inherited.
In addition to property attributes, there are some control attributes, such as the ToolBoxBitMap attribute that allow you to specify control behavior. The ToolBoxBitMap allows you to specify a bitmap or icon image to represent a control in the Toolbox of the Visual Studio .Net IDE.
Module 3: Building Controls 25
How to Add Attributes that Provide Information to the Visual
Designer
To add attributes to your codeTo add attributes to your code
Define a new attribute or use an existing attribute by importing its namespace from the .NET framework class library
Initialize the attribute directly preceding the element that needs to be described
[Category(“Appearance”)]PublicColor BackColor
[Category(“Appearance”)]PublicColor BackColor
using System.ComponentModel;using System.ComponentModel;
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Attributes associate design-time functionality with a component. Design-time attributes can be applied to properties, events, classes, and even assemblies.
To add attributes:
1. Define a new attribute or use an existing attribute by importing its
namespace from the .NET Framework class library.
using System.ComponentModel;
When you derive a component or control from a base component that has design-time attributes, your component inherits the design-time functionality of the base class. If the base functionality is adequate for your purposes, you do not have to reapply the attributes. However, you can always override attributes or apply additional attributes to the derived component. Only classes that directly or indirectly implement System.ComponentModel.IComponent have design-time support in a visual designer.
2. Initialize the attribute directly preceding the element that needs to be described.
In the following code fragment, the Category attribute enables the property browser to display the Color property in the Appearance category.
[Category(“Appearance”)]Public Color BackColor
Introduction
Procedure
26 Module 3: Building Controls
Design-Time Support Options Built into the .NET Framework
� Property Browser
� Associates property editors for different data types
� Type Converter
� Converts the value entered into the Properties window to the correct data type within a control
� Custom UI Editors
� Chooses the correct UI editor for the Properties window based on the type of property
� Custom Designers
� Allows you to modify the design-time appearance and behavior of controls and objects
� Extenders
� Provide the ability to add or filter properties for controls
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Design-time functionality refers to the display and behavior of a component or control in a visual designer. The .NET platform includes several features that support the development of design-time behavior for controls.
� Property Browser
When a control exposes properties, the Visual Studio .NET IDE displays them at design time in the Properties window. Most properties are modified by typing string values into the property browser. The property browser then converts the string values to the correct type. So, for example, if you expose a property of type integer and attempt to enter a non-numeric value for it in the property browser, it will raise an error.
The property browser is also capable of associating more advanced property editors for different data types. For example, the property editor exposes a color palette for Color types and a DateTimePicker control for Date types.
� Type Converter
A type converter is used to convert the value entered into the Property window. A simple example is the conversion from a string to an integer and back. Type converters are primarily used for string-to-value conversions and for validation at design time and at run time. Most native data types (Int32, String, enumeration types, and others) have default type converters. You can create a custom type converter (by inheriting from the System.ComponentModel.TypeConverter class), if a custom property does not have an associated type converter.
After you create a type converter, you can apply the TypeConverter
attribute to a property to associate the property with the type converter. For example, you can use a TypeConverter to convert two strings entered in the property browser to a Point type.
Introduction
Design-time support options
Module 3: Building Controls 27
� Custom UI editors
In some situations, a simple value-to-string conversion that allows a property to be displayed as text in the property browser might not be adequate. For instance, in the case of a color property, a visual representation is more desirable. A UI type editor allows such a representation and is intended for use with property browsers and other advanced design-time hosts.
To implement a custom UI type editor for Windows Forms, you define a class that is derived from System.Drawing.Design.UITypeEditor. You then apply the Editor attribute to a property to associate the property with the UI editor.
� Custom Designers
Designers are classes that allow you to modify the design-time appearance and behavior of components and controls. Although the usual goal of any WYSIWYG form designer is to minimize differences between design-time and run-time appearance, some special design-time cues are necessary. For example, a System.Windows.Forms.Panel object might not have a visible border at run time. However, without a border the panel is invisible to the developer designing a form that contains the panel. Therefore, the designer for the System.Windows.Forms.Panel object draws a dotted line border around the panel.
To create a custom designer, create a class that implements the IDesigner interface and apply the Designer attribute to the control.
� Extenders
Extender providers add properties to other controls. In the .NET Framework, extender providers require no special support. At design time, extender properties appear in the property browser as properties on the objects that they extend, rather than on the actual extender object.
An example of an extender is the ToolTip control. The ToolTip property is not available to controls on a form until you add the ToolTip control to the form.
To create an extender control, create a class that implements the System.ComponentModel.IExtenderProvider interface.
28 Module 3: Building Controls
Practice: Adding Design-Time Attributes Support for Controls
� In this practice, you will use attributes and custom designer to modify the behavior and appearance of controls.
� Add a ToolBox bitmap for a control
� Add attributes to the Text property
� Test the design time support for the control
� Explore custom designers and extenders
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this practice, you will learn how to add design-time support for controls. The exercises involve adding a special icon for a vertical label control on the Toolbox. In addition, you will add an attribute to the Text property of the vertical label.
◮ Open the practice project
1. Start Visual Studio .NET.
2. In the Start Page window, click Open Project.
3. In the Look in list, navigate to install_folder\
Practices\Mod03_02\Starter\VerticalLabel, and then open the VerticalLabel.sln solution file.
4. On the Build menu, click Build Solution.
◮ Add a ToolBox bitmap for a control
1. On the Project menu, click Add Existing Item, change the File Type filter to All Files, select the VerticalLabel.ico file located in
install_folder\2555A\Practices\Mod03_02\Starter, and then click Open.
2. In Solution Explorer, click VerticalLabel.ico. In the Properties window, set
the Build Action property to Embedded Resource.
There are various options for associating an image with a control’s Toolbox bitmap. In this exercise, you will embed the image within the compiled project. In this case, the ToolboxBitmap attribute requires two arguments, the Type where the image is located and a String that represents the name of the image.
Introduction
Instructions
Module 3: Building Controls 29
3. Open VerticalLabel.cs in the code view.
4. Add a ToolBoxBitmap attribute to the VerticalLabel class. Use the typeof function to return a VerticalLabel type for the first argument and
VerticalLabel.ico as a string for the second argument. You code should look like the following:
[ToolboxBitmap(typeof(VerticalLabel), "VerticalLabel.ico")]
public class VerticalLabel :
System.Windows.Forms.Control
◮ Add attributes to the Text property
1. Import the System.ComponentModel namespace at the top of the VerticalLabel.cs code window.
2. Add a Category attribute to the Text property and set it to VerticalLabel.
3. Add a Description attribute to the Text property and set it to: Text is
displayed vertically in container. You code should look like this.
using System.ComponentModel;
…
[Category("VerticalLabel"), Description("Text is displayed
in container")]
public override string Text
4. On the Build menu, click Build Solution.
◮ Test the design-time support for the control
1. On the File menu, click Add Project, and then click New Project.
2. Click the Windows Application template, and then click OK.
3. On the Tools menu, click Customize Toolbox.
4. In the Customize Toolbox dialog box, click the .NET
FrameworksComponents tab, and then click Browse.
5. In the Open dialog box, click install_folder\2555A\Practices\Mod03_02\Starter\VerticalLabel\obj\Debug\
VerticalLabel.dll, click Open, and then click OK.
6. Ensure the control is correctly represented by the VerticalLabel.ico in the
Toolbox.
7. Add a VerticalLabel control to Form1 from the Toolbox. View the Text
property in the Properties window to ensure that Category and Description
are displayed.
◮ Explore custom designers and extenders
1. Add a Panel control to Form1.
The Panel control displays an outline of its borders at design time. At run time the outline is not displayed. This is an example of a custom designer.
2. Add a ToolTip control to Form1 and view the ToolTip on ToolTip1 property that is exposed on both the Panel control and the VerticalLabel
control.
The ToolTip control extends the ToolTip property to other controls. This is an example of an extender control.
Module 4: Using Data in Windows Forms Applications 1
Overview
� Adding ADO.NET Objects to a Windows Forms Application
� Accessing and Modifying Data by Using DataSets
� Binding Data to Controls
� Using the DataGrid Control
� Overview of XML Web Services
� Creating a Simple XML Web Services Client
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Data binding provides a simple, convenient, powerful, and transparent way for developers to create a read/write link between the controls on a form and the data in their application.
Microsoft® .NET Framework Windows Forms support binding data to ADO.NET DataSets, arrays, collections, and other controls. A control can be bound to any collection that supports indexed access to the elements in that collection.
XML Web services enable the exchange of data and the remote invocation of application logic by using XML messaging to move data through firewalls and among many heterogeneous systems.
Developers can create applications that weave together XML Web services from a variety of sources in much the same way that developers traditionally use components when creating a distributed application.
After completing this module, you will be able to:
� Describe the objects in the ADO.NET object model.
� Add and configure ADO.NET objects in a Windows Forms application.
� Access and modify data from a database by using DataSets.
� Bind data to controls.
� Use the DataGrid control.
� Describe the XML Web services model and the roles of HTML, SOAP,
XML, and marshaling in the XML Web services model.
� Create and test a simple XML Web service client application.
� Persist data to and read data from files and isolated storage by using methods of the BinaryReader and BinaryWriter methods and the
TextReader and TextWriter methods.
Introduction
Objectives
2 Module 4: Using Data in Windows Forms Applications
Lesson: Adding and Configuring ADO.NET Objects on a Windows Forms Application
Data SourceDataAdapterDataTable
DataTable
DataSet
DataAdapter
FillFill
UpdateUpdate
UpdateUpdate
FillFill
*****************************ILLEGAL FOR NON-TRAINER USE******************************
As application development has evolved, a lot of new applications are based on the Web application model. An increasing number of applications use XML to encode data to be passed over network connections. ADO.NET provides a programming model that incorporates features of both XML and ADO.NET in the .NET Framework.
ADO.NET is a set of classes that allow .NET-based applications to read and update information in databases and other data stores. You can access these classes through the .NET Framework System.Data namespace.
ADO.NET provides consistent access to a wide variety of data sources, including Microsoft SQL Server™ databases, OLE DB–compliant databases, non-relational sources such as Microsoft Exchange Server, and XML documents.
ADO.NET is designed for working with disconnected data in a multi-tier environment. ADO.NET uses XML as the format for transmitting disconnected data, which makes it easier to communicate with client applications that are not based on Windows Forms.
After completing this lesson, you will be able to:
� Describe the objects in the ADO.NET object model.
� Add and configure ADO.NET objects in a Windows Forms application.
Introduction
Lesson objectives
Module 4: Using Data in Windows Forms Applications 3
Multimedia: ADO.NET Object Model
� In this animation, you will get an overview of the ADO.NET object model.
� Connection object
� Command object
� DataSets
� DataAdapters
� DataReaders
*****************************ILLEGAL FOR NON-TRAINER USE******************************
ADO.NET evolved from the ADO data access model. By using ADO.NET, you can develop applications that are robust and scalable, and that can use XML.
ADO.NET has some of the same objects as ADO (like the Connection and Command objects), and introduces new objects, such as Dataset, DataReader, and DataAdapter.
Introduction
4 Module 4: Using Data in Windows Forms Applications
What Is a Connection Object?
� Connections
� Used to talk to databases
� Use ConnectionString property to determine connection strings
� Types of Connections
� SqlConnection
System.Data.SqlClient.SqlConnection cnNorthwind;
cnNorthwind.ConnectionString = "data source=London\\MOC;initial catalog=Northwind;integratedsecurity=SSPI; " +
"persist security info=False;";
System.Data.SqlClient.SqlConnection cnNorthwind;
cnNorthwind.ConnectionString = "data source=London\\MOC;initial catalog=Northwind;integratedsecurity=SSPI; " +
"persist security info=False;";
� OleDbConnection
*****************************ILLEGAL FOR NON-TRAINER USE******************************
To move data between a data store and your application, you must first have a connection to the data store. In ADO.NET you can create and manage a connection by using a connection object.
Applications use Connection objects to communicate with databases. The
ConnectionString property determines connection settings. These connection settings access a particular DataSource. A typical ConnectionString property might look like the following code:
Provider=SQLOLEDB.1;Data Source=MySQLServer;Initial
Catalog=NORTHWIND;Integrated Security=SSPI
There are two kinds of connection objects in ADO.NET: SqlConnection and OleDbConnection.
The SqlConnection object manages a connection to Microsoft SQL Server version 7.0 or later. The SqlConnection object is optimized for use with SQL Server 7.0 or later by bypassing the OLE DB layer.
The following code is an example of connecting to a SQL Server 2000 database by using a SqlConnection object:
System.Data.SqlClient.SqlConnection cnNorthwind;
cnNorthwind.ConnectionString = "data
source=London\\MOC;initial catalog=Northwind;integrated
security=SSPI; " +
"persist security info=False;";
Introduction
Definition
SqlConnection
Example of SQLConnection
Module 4: Using Data in Windows Forms Applications 5
The OleDbConnection object manages a connection to any data store accessible through OLE DB. The OleDbConnection object interacts with OLE DB to expose a consistent API for a variety of data sources — everything from simple text files to spreadsheets and, of course, full-featured databases.
The following code is an example of connecting to a Microsoft Access 2002 database by using an OleDbConnection object:
Dim cnNorthwind as New _
System.Data.OleDb.OleDbConnection()
cnNorthwind.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Program Files\Microsoft
Office\Office10\Samples\Northwind.mdb;"
System.Data.OleDb.OleDbConnection cnNorthwind = new
System.Data.OleDb.OleDbConnection ();
cnNorthwind.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Program Files\\Microsoft
Office\\Office10\\Samples\\Northwind.mdb;";
The Connection object is one component of a .NET Framework data provider. A data provider in the .NET Framework serves as a bridge between an application and a data source, and is used to retrieve data from a data source and to reconcile changes to that data back to the data source.
OleDbConnection
Example of OleDbConnection
Note
6 Module 4: Using Data in Windows Forms Applications
What Is a Command Object?
� Travel over connections
� Resultsets are returned in the form of streams
� Types of Commands
� SqlCommand
SqlClient.SqlConnection conSQL = new SqlClient.SqlConnection();
conSQL.ConnectionString = "Integrated Security=True;DataSource=LocalHost;Initial Catalog=Pubs;";
conSQL.Open( );
SqlClient.SqlCommand commSQL = new SqlClient.SqlCommand();
commSQL.Connection = conSQL;
commSQL.CommandText = "Select Count(*) from Authors";
MessageBox.Show(commSQL.ExecuteScalar( ).ToString());
SqlClient.SqlConnection conSQL = new SqlClient.SqlConnection();
conSQL.ConnectionString = "Integrated Security=True;DataSource=LocalHost;Initial Catalog=Pubs;";
conSQL.Open( );
SqlClient.SqlCommand commSQL = new SqlClient.SqlCommand();
commSQL.Connection = conSQL;
commSQL.CommandText = "Select Count(*) from Authors";
MessageBox.Show(commSQL.ExecuteScalar( ).ToString());
� OleDbCommand
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Command objects allow you to access data directly in the database in a connected environment. Command objects use SQL statements or stored procedures to retrieve data.
Commands travel across connections, and result sets are returned in the form of streams that can be read by DataReaders or pushed into DataSet objects. Command objects contain a Parameters collection that populates the input and output arguments of SQL statements or stored procedures. For example, if you have a SQL statement that returns all of the rows in the Orders table where the EmployeeID is equal to a value determined at run time, you add the value EmployeeID to the Paremeters collection of the Command object.
A Command object contains a reference to a SQL statement or stored procedure that you can execute directly. The two Command classes are described in the following table.
Command class Description System.Data.SqlClient.SqlCommand SQL Server .NET Data Provider
command
System.Data.OleDb.OleDbCommand OLE DB .NET Data Provider command
The properties of a Command object contain all of the information necessary to execute a statement against a database. The following table summarizes the properties of the Command object and their descriptions.
Property Description Name The programmatic name of the command
object. Use this name in your code, to
refer to the command object.
Connection The command object references a
connection object, which it uses to
communicate with the database.
Introduction
Definition
Properties of a command object
Module 4: Using Data in Windows Forms Applications 7
CommandType A value specified by the CommandType
enumeration, indicating what type of
command you want to execute:
• Text. A SQL statement.
• StoredProcedure. A stored
procedure.
• TableDirect. A way of fetching
the entire contents of a table.
(This option is available only for
OleDbCommand objects.)
CommandText The command to execute. The command
text you specify depends on the value of
the CommandType property:
• Text. Enter the SQL statement to
execute.
• StoredProcedure. Enter the
name of the stored procedure.
• TableDirect. Enter the name of
the table to fetch.
Parameters The command object may include zero or
more parameters.
8 Module 4: Using Data in Windows Forms Applications
After configuring the properties for a command object, you call one of the following methods to execute the command. The method you call depends on the statement or procedure being executed, and the results that you expect to be returned.
Method in a Command class Description ExecuteScalar Executes a command that returns a single
value.
ExecuteReader Executes a command that returns a set of
rows.
ExecuteNonQuery Executes a command that updates the
database or changes the database
structure. This method returns the number
of rows affected.
ExecuteXmlReader
(SqlCommand only)
Executes a command that returns an XML
result. Capability is supported by SQL
Server version 7.0 or later.
The following example shows how to use the Command object to query a database and retrieve data:
SqlClient.SqlConnection conSQL = new
SqlClient.SqlConnection();
conSQL.ConnectionString = "Integrated Security=True;Data
Source=LocalHost;Initial Catalog=Pubs;";
conSQL.Open( );
SqlClient.SqlCommand commSQL = new SqlClient.SqlCommand();
commSQL.Connection = conSQL;
commSQL.CommandText = "Select Count(*) from Authors";
MessageBox.Show(commSQL.ExecuteScalar( ).ToString());
Methods of a command object
Example
Module 4: Using Data in Windows Forms Applications 9
What Is a DataReader Object?
� A fast, forward-only cursor that loops through a stream of rows
SqlConnection cnNorthwind = new SqlConnection();
System.Data.SqlClient.SqlCommand cmProducts = new System.Data.SqlClient.SqlCommand("SELECT ProductName, " +
"UnitsInStock FROM Products", cnNorthwind);
SqlDataReader rdrProducts;
cnNorthwind.Open();
rdrProducts = cmProducts.ExecuteReader(CommandBehavior.CloseConnection);
while (rdrProducts.Read())
{
listBox1.Items.Add(rdrProducts.GetString(0) + "\t" + rdrProducts.GetInt16(1));
}
rdrProducts.Close();
SqlConnection cnNorthwind = new SqlConnection();
System.Data.SqlClient.SqlCommand cmProducts = new System.Data.SqlClient.SqlCommand("SELECT ProductName, " +
"UnitsInStock FROM Products", cnNorthwind);
SqlDataReader rdrProducts;
cnNorthwind.Open();
rdrProducts = cmProducts.ExecuteReader(CommandBehavior.CloseConnection);
while (rdrProducts.Read())
{
listBox1.Items.Add(rdrProducts.GetString(0) + "\t" + rdrProducts.GetInt16(1));
}
rdrProducts.Close();
*****************************ILLEGAL FOR NON-TRAINER USE******************************
The DataReader is a fast, forward-only cursor that loops through a stream of rows. When you execute a Command object that returns a set of rows, you use a DataReader to loop through the set of rows.
You can use a Command object and the ExecuteReader method to return a DataReader. You can execute any SELECT statement or a stored procedure that contains a SELECT statement.
The DataReader provides strongly typed methods to get the value of a specific column in the current row. You can also obtain metadata about the rows, such as the column name and the column data type.
When you process a result set with a DataReader, the associated connection is kept busy until you close the DataReader. For this reason, you should close the DataReader as soon as you finish processing the result set.
The following are examples of situations where you might want to use a Command object to return a DataReader:
� You want to obtain a single record from a table, such as the details for a
particular customer. To do this, you specify the customer ID, and get back a
single record containing the details for that customer.
� You want to obtain a set of records that you insert into a control on a form.
This is often useful in applications which display read-only information such as search results or inventory lists.
The following code executes a SELECT statement to get product details from the Northwind database. The example iterates through the rows by using a SqlDataReader, and gets the ProductName and UnitsInStock for each product.
Introduction
The ExecuteReader method
Example
Code example
10 Module 4: Using Data in Windows Forms Applications
SqlConnection cnNorthwind = new SqlConnection();
System.Data.SqlClient.SqlCommand cmProducts = new
System.Data.SqlClient.SqlCommand("SELECT ProductName, " +
"UnitsInStock FROM Products", cnNorthwind);
SqlDataReader rdrProducts;
cnNorthwind.Open();
rdrProducts =
cmProducts.ExecuteReader(CommandBehavior.CloseConnection);
while (rdrProducts.Read())
{
listBox1.Items.Add(rdrProducts.GetString(0) + "\t" +
rdrProducts.GetInt16(1));
}
rdrProducts.Close();
Module 4: Using Data in Windows Forms Applications 11
Demonstration: Using DataReaders
� In this demonstration, you will see how to use DataReader to populate a ListBox with results returned by a Command object.
� Create a new project
� Call the ExecuteReader method
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this demonstration, you will see how to use a DataReader to populate a ListBox with results returned by a Command object.
◮ Create a new project
1. Start Microsoft® Visual Studio® .NET.
2. On the File menu, point to New, and then click Project.
3. In the New Project dialog box, click Windows Application, name it UsingDataReaders, and then click OK.
4. On the Data tab of the Toolbox, drag a SQLDataAdapter control to Form1.
◮ Call the ExecuteReader method
1. Using the DataAdapter Configuration Wizard, create a stored procedure
named AllCustomers that returns all of the data in the Customers table,
sorted by company name.
2. Make the data read-only by disabling the Generate Insert, Update, and
Delete statements checkbox in the Advanced SQL Generation Options dialog box.
3. Add a list box and button to Form1.
4. Define a Click event handler for the button, and add the following code:
12 Module 4: Using Data in Windows Forms Applications
System.Data.SqlClient.SqlDataReader rdrCustomers;
sqlConnection1.Open();
rdrCustomers =
sqlSelectCommand1.ExecuteReader(CommandBehavior.CloseConnec
tion);
while (rdrCustomers.Read())
{
listBox1.Items.Add(rdrCustomers.GetString(1));
}
rdrCustomers.Close();
5. Build and run the application.
Module 4: Using Data in Windows Forms Applications 13
What Is a DataSet?
� Datasets can include multiple DataTables
� Relationships between tables are represented using DataRelations
� Constraints enforce primary and foreign keys
� Use the DataRow and DataColumn to access values in Tables
DataTable
DataColumn
DataRow
DataRelation
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In ADO.NET, by using DataSets you can represent data in a local cache and provide a relational programming model for the data regardless of its source.
The ADO.NET DataSet is an in-memory cache of data that functions as a disconnected relational view of the data. The connection to the data source does not need to be active for an application to view and manipulate data in a DataSet. This disconnected architecture enables greater scalability by using database server resources only when reading from, or writing to, the data source.
DataSets store data similarly to the way data is stored in a relational database, with a hierarchical object model of tables, rows, and columns. Additionally, you can define constraints and relationships for the data in the DataSet.
DataTable objects represent the tables in a DataSet. A DataTable represents one table of in-memory relational data. The data is local to the .NET application in which it resides, but it can be populated from an existing data source. A DataTable is composed of DataColumns.
A DataColumn is the building block for creating the schema of a DataTable. Each DataColumn has a DataType property that determines the kind of data that each DataColumn contains. For example, you can restrict the data type to integers, strings, or decimals. Because data contained in the DataTable is typically merged back into the original data source, you must match the data types to those in the data source.
The DataSet class has a Tables property that gets a collection of DataTable
objects in the DataSet, and a Relations property that gets a collection of the DataRelation objects in the DataSet.
A DataTable object contains several collections that describe the data in the table and cache the data in memory. The following table describes the most important collections.
Introduction
Definition
DataTables in DataSets
DataColumns in DataTables
Tables in a DataSet
14 Module 4: Using Data in Windows Forms Applications
Collection name Type of object
in collection
Description of object in collection
Columns DataColumn Contains metadata about a column in the table,
such as the column name, data type, and whether
rows can contain a NULL value in this column.
Rows DataRow Contains a row of data in the table. A DataRow
object also maintains the original data in the row,
before any changes were made by the application.
Constraints Constraint Represents a constraint on one or more
DataColumn objects. Constraint is an abstract
class. There are two concrete subclasses:
UniqueConstraint and ForeignKeyConstraint.
ChildRelations DataRelation Represents a relationship to a column in another
table in the DataSet. You use DataRelation
objects to create links between primary keys and
foreign keys in your tables.
A typed DataSet is a class that derives from a DataSet. It inherits all the
methods, events, and properties of a DataSet. In addition, a typed DataSet provides strongly typed methods, events, and properties. This means that you
can access tables and columns by name, instead of using collection-based methods. For example, to access the access the Titles table from a DataSet
named DatSet1, you use the following code:
DataSet1.Tables(“Titles”);
However, with a typed DataSet, you can directly access the Titles table by using the following code: DataSet1.Titles;
In addition to the improved readability of the code, a typed DataSet also allows
the Visual Studio .NET Code Editor to use the Intellisense feature to automatically complete lines of code as you type them.
Additionally, the strongly typed DataSets provide access to correct value type
at compile time. With a strongly typed DataSet, type mismatch errors are caught when the code is compiled, rather than at run time.
You can generate a strongly typed DataSet by using the XSD.exe tool provided with the .NET Framework SDK, or you can generate one in the Visual Studio
IDE.
Typed DataSets
Module 4: Using Data in Windows Forms Applications 15
What Is a DataAdapter?
sp_SELECT
XxxDataAdapterXxxDataAdapter
XxxCommandXxxCommand
SelectCommand UpdateCommand InsertCommand DeleteCommand
XxxCommandXxxCommand XxxCommandXxxCommand XxxCommandXxxCommand
XxxConnectionXxxConnection
sp_UPDATE sp_INSERT sp_DELETE
XxxDataReaderXxxDataReader
*****************************ILLEGAL FOR NON-TRAINER USE******************************
The DataSet object represents a local copy of data from a data source and is one of the key innovations of the Microsoft .NET Framework. By itself, the DataSet object is useful for reference. However, to serve as a true data-management tool, a DataSet must be able to interact with a data source. To accomplish this, the .NET Framework provides the DataAdapter class.
A DataAdapter object serves as a bridge between a DataSet and a data source for retrieving and saving data. The DataAdapter class represents a set of database commands and a database connection that you use to fill a DataSet and update the data source. DataAdapter objects are part of the Microsoft ADO.NET data providers, which also include connection objects, data-reader objects, and command objects.
Each DataAdapter exchanges data between a single DataTable object in a DataSet and a single result set from a SQL statement or stored procedure.
Microsoft Visual Studio .NET makes two primary DataAdapters available for use with databases. In addition, other DataAdapters can be integrated with Visual Studio. The primary DataDdapters are:
� OleDbDataAdapter, which is suitable for use with any data source that is exposed by an OLE DB provider.
� SqlDataAdapter, which is specific to SQL Server version 7.0 or later database. The SqlDataAdapter is faster than the OleDbDataAdapter
because it works directly with SQL Server and does not go through an OLE DB layer.
\
Introduction
Definition
Primary DataAdapters for databases
16 Module 4: Using Data in Windows Forms Applications
You use DataAdapters to act on records from a data source. You can specify which actions you want to perform by using one of four DataAdapter properties, which execute a SQL statement or call a stored procedure. The properties are actually objects that are instances of the SqlCommand or OleDbCommand class.
� SelectCommand. Refers to a Command object that retrieves rows from the
data source.
� InsertCommand. Refers to a Command object that writes inserted rows
from the DataSet into the data source.
� UpdateCommand. Refers to a Command object that writes modified rows from the DataSet into the data source.
� DeleteCommand. Refers to a Command object that deletes rows in the data source.
DataAdapter properties
Module 4: Using Data in Windows Forms Applications 17
How to Add ADO.NET Objects to a Form
Drag an OleDbDataAdapter or SqlDataAdapter object from the Toolbox onto a formDrag an OleDbDataAdapter or SqlDataAdapter object from the Toolbox onto a form
Specify connection and SQL command information Specify connection and SQL command information
Select the adapter or adapters that will be used to transfer data between the data source and the datasetSelect the adapter or adapters that will be used to transfer data between the data source and the dataset
On the Data menu, choose Generate DatasetOn the Data menu, choose Generate Dataset
Select New and then specify a name for the new datasetSelect New and then specify a name for the new dataset
*****************************ILLEGAL FOR NON-TRAINER USE******************************
The data design tools in Visual Studio provide a simple way to connect to a database and retrieve data from it.
You can use any of the following data design tools to connect to data source:
� DataAdapter Configuration Wizard
This wizard prompts you for information to create a connection that is in turn linked to a data adapter.
� Data Form Wizard
This wizard creates the connection object as part of the form it is configuring.
In this topic, you will learn how to connect to data source by using the DataAdapter Configuration Wizard.
Although, by using data design tools you need not create explicit
connections to a data source, there are times when you need to create just a connection. For more information how to create a connection, see “Creating ADO.NET Connection Objects” in the Visual Studio .NET documentation.
Introduction
Note
18 Module 4: Using Data in Windows Forms Applications
The Data Adapter Configuration Wizard helps you set the properties of a new or existing data adapter. A data adapter contains SQL commands that your application can use to read data into a dataset from a database and write it back again. The wizard can optionally create a data connection that allows the adapter to communicate with a database.
To use the DataAdapter Configuration Wizard:
1. Drag an OleDbDataAdapter or SqlDataAdapter object from the Toolbox onto a form or component.
2. Specify connection and SQL command information.
The wizard displays several dialog boxes:
a. If you ask to create a connection, the wizard displays the Connection tab of the Data Link Properties dialog box, which allows you to
specify a provider, server name, database name, user name, and password for the connection.
b. To help you create SQL statements, the wizard provides the Query Builder, a utility that allows you to create and test a Select statement by
using visual tools. To launch it, click the Query Builder button when asked for a SQL statement.
3. In the Component Designer, select the adapter or adapters that will transfer data between the data source and the dataset.
Typically, each data adapter accesses data in a single table. Therefore, to create a dataset containing multiple data tables, you should select all the adapters for the tables you want to work with.
4. On the Data menu, choose Generate Dataset.
The Generate DataSet dialog box appears.
5. Click New, and then specify a name for the new dataset. If you want to add
the dataset to your form or component, click Add an instance of this
DataSet to the designer.
Procedure
Module 4: Using Data in Windows Forms Applications 19
Practice: Adding and Configuring ADO.NET Objects on a Form
� In this practice, you will add and configure ADO.NET objects on a form by using the Data Adapter Configuration Wizard
� Create a Windows application project
� Add and Configure a SQLConnectioncontrol to the form
� Add and configure a SQLDataAdaptercontrol to the form
� Generate the DataSet
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this practice, you will learn how to add and configure ADO.NET objects on a form by using the Data Adapter Configuration Wizard.
◮ Create a Windows application project
1. Open Visual Studio .NET.
2. On the File menu, point to New, and then click Project.
3. In the New Project dialog box, select Windows Application, name it
BuildingDataSets, and then click OK.
◮ Add a SQLConnection control to the form and configure it
1. Drag a SQLConnection control from the ToolBox to Form1.
The SQLConnection control is on the Data tab of the Toolbox.
2. In the Properties window, click the ConnectionString property, click the
down arrow, and then click New Connection.
3. In the Data Link Properties dialog box, type <computername>\MOC,
where <computername> is the name of your computer.
4. Select the Use Windows NT Integrated Security option.
5. Select the pubs database from the drop down list, click Test Connection to
ensure that you can access the pubs database, and then click OK.
6. Click OK to close the Data Link Properties dialog box.
7. Review the ConnectionString text that is generated.
◮ Add a SQLDataAdapter control to the form and configure it
1. Drag a SQLDataAdapter control from the ToolBox to Form1.
2. In the Data Adapter Configuration Wizard, click Next.
3. In the data connection drop down list, click
<computername>\moc\pubs.dbo, and then click Next.
20 Module 4: Using Data in Windows Forms Applications
4. In the Choose a Query Type dialog box, click Next.
You can use this wizard create SQL statements and stored procedures or modify existing stored procedures.
5. On the Toolbar, click the Query Builder button.
6. In the Add Table dialog box, select the Titles tables, click Add, and then click Close.
7. In the Query Builder dialog box, in the Titles table, select All Columns,
and then click OK.
8. Review the information in the View Wizard Results dialog box, and then
click Finish.
9. Review the SelectCommand, DeleteCommand, InsertCommand and
UpdateCommand properties of the SQLDataAdapter1 control in the Properties window.
Each of these properties is associated with a SQLCommand object that was generated by the wizard. Each operation (SELECT, INSERT, UPDATE, DELETE) uses a specific SQLCommand to perform its task.
10. Expand the DeleteCommand property and review the CommandText
property.
Each SQLCommand object has a unique CommandText property that is generated by the wizard and enables the object to perform its task.
◮ Generate the DataSet
1. On the Data menu, click Generate DataSet.
If the Generate DataSet option is disabled, then click anywhere outside the Properties window before generating the DataSet.
2. Click OK on the Generate Dataset dialog box.
A dataset control named DataSet11 is added to Form1. DataSet11 is an instance of the typed dataset DataSet1.
3. In Solution Explorer, double click DatSet1.xsd.
This is the visual representation of your dataset. In this view you can add new or existing tables to your dataset and create relationships between them.
4. Click XML in the lower left of the designer.
This is the XML representation of your dataset.
5. In Solution Explorer, click Show All Files.
6. In Solution Explorer, expand DataSet1.xsd, and then double click DataSet1.cs.
7. Review the code.
Note
Module 4: Using Data in Windows Forms Applications 21
Lesson: Accessing and Modifying Data by Using DataSets
� How to Populate a Dataset
� How to Update Data in a Dataset
� How to Update Data to a DataSource
� Practice: Populating and Updating DataSets
� How to Create Relationships in a DataSet
� How to Create Database Schema on the Client
� How to Read XML Data into a DataSet
� How to Write DataSet Information into an XML File
� Practice: Reading and Writing DataSets to XML Files
*****************************ILLEGAL FOR NON-TRAINER USE******************************
ADO.NET provides you with the DataSet object for the caching of data on the client computer. This DataSet is automatically disconnected from the data source but maintains the ability to later update the source based on changes made at the client.
In this lesson, you will learn how to create DataSets and populate tables in them. You will also learn how to edit these tables and propagate those changes to the data source.
After completing this lesson, you will be able to:
� Populate a DataSet with data from a data source.
� Update the data in a DataSet.
� Update the data source by using a DataSet.
� Create relationships between tables in a DataSet.
� Create database schema on the client.
� Read XML data into a DataSet.
� Write data from a DataSet into an XML file.
Introduction
Lesson objectives
22 Module 4: Using Data in Windows Forms Applications
How to Populate a Dataset
� Use the DataAdapter object to fill the dataset
SqlDataAdapter storesSQLDataAdapter;SqlCommand storesSelectSQLCommand;storesSelectSQLCommand.CommandText = "SELECT * FROM
stores";storesSelectSQLCommand.Connection = SqlConnection1;storesSQLDataAdapter.SelectCommand =
storesSelectSQLCommand;storesSQLDataAdapter.Fill(storesDataSet.Tables["Stores"]);
SqlDataAdapter storesSQLDataAdapter;SqlCommand storesSelectSQLCommand;storesSelectSQLCommand.CommandText = "SELECT * FROM
stores";storesSelectSQLCommand.Connection = SqlConnection1;storesSQLDataAdapter.SelectCommand =
storesSelectSQLCommand;storesSQLDataAdapter.Fill(storesDataSet.Tables["Stores"]);
*****************************ILLEGAL FOR NON-TRAINER USE******************************
A DataSet is an in-memory representation of data and does not actually contain any data until you fill it by using a DataAdapter object. After you create the DataAdapter object, you use the Fill method, passing a DataSet and, optionally, the DataTable name as parameters.
The DataAdapter uses the SelectCommand object to execute the query and returns the results to the DataSet or to the DataTable referenced as parameters. The following code programmatically creates and configures a SQLDataAdapter and a SQLCommand and then uses the Fill method to populate a table in a dataset:
SqlDataAdapter storesSQLDataAdapter;
SqlCommand storesSelectSQLCommand;
storesSelectSQLCommand.CommandText = "SELECT * FROM stores";
storesSelectSQLCommand.Connection = SqlConnection1;
storesSQLDataAdapter.SelectCommand = storesSelectSQLCommand;
storesSQLDataAdapter.Fill(storesDataSet.Tables["Stores"]);
It is often necessary to pass parameters to a SQL statement. For example, when accessing rows from a data source, you use the SELECT statement, which uses a unique identifier to identify the rows to be accessed. The unique identifier is commonly the value of a primary key field. The SELECT statement uses parameters that contain the unique identifier, and the columns and values to be updated, as shown in the following SQL statement:
SELECT stor_id, ord_num, qty, ord_date, payterms, title_id
FROM sales WHERE (stor_id = @stor_id)
In the previous example, the stor_id field must be populated with a value from the @stor_id parameter for the SQL statement to return results.
A Parameter object holds the input and output parameters of SQL statement and stored procedures. The Parameters collection of a Command object is
where you add the required arguments of SQL statements or stored procedures.
Introduction
Procedure
Passing parameters to SELECT statements
Module 4: Using Data in Windows Forms Applications 23
There are a variety of ways to add Parameter objects to the Parameters
collection. The following code uses the SelectCommand property to access a
Command object, and then assigns the value of stor_id to the Value property of the Parameter object in the Parameters collection that is identified by
@stor_id:
SalesSqlDataAdapter.SelectCommand.Parameters["@stor_id"].Value
= stor_id;
After all the arguments for a SQL Statement or stored procedure are defined in Parameter objects you can call the Fill method of the DataAdapter to get the results.
SalesSqlDataAdapter.Fill(StoreSalesDataSet1.sales);
24 Module 4: Using Data in Windows Forms Applications
How to Update Data in a DataSet
� Adding Rows
� Editing Rows
� Deleting Data
Dim drNewRow As DataRow = datPubs.Tables("Titles").NewRowdrNewRow("title") = "New Book"drNewRow("type") = "business"datPubs.Tables("Titles").Rows.Add(drNewRow)
Dim drNewRow As DataRow = datPubs.Tables("Titles").NewRowdrNewRow("title") = "New Book"drNewRow("type") = "business"datPubs.Tables("Titles").Rows.Add(drNewRow)
DataRow drChangeRow = datPubs.Tables["Titles"].Rows[0];drChangeRow.BeginEdit( );drChangeRow["Title"] = drChangeRow["Title"].ToString() + "
1";drChangeRow.EndEdit( );
DataRow drChangeRow = datPubs.Tables["Titles"].Rows[0];drChangeRow.BeginEdit( );drChangeRow["Title"] = drChangeRow["Title"].ToString() + "
1";drChangeRow.EndEdit( );
DataRow drDelRow = datPubs.Tables["Titles"].Rows[0];datPubs.Tables["Titles"].Rows.Remove(drDelRow);
DataRow drDelRow = datPubs.Tables["Titles"].Rows[0];datPubs.Tables["Titles"].Rows.Remove(drDelRow);
*****************************ILLEGAL FOR NON-TRAINER USE******************************
After you have created a DataSet of DataTables, you might want to add, update, and delete data. Any changes you make to the data are stored in memory and later used to apply the changes to the data source.
To add new rows to a DataSet table:
1. Instantiate a DataRow object by using the NewRow method of the
DataTable.
2. Populate the columns with data.
3. Call the Add method of the DataRows collection, passing the DataRow object.
The following code shows how to add rows to a DataSet:
Dim drNewRow As DataRow = datPubs.Tables("Titles").NewRow
drNewRow("title") = "New Book"
drNewRow("type") = "business"
datPubs.Tables("Titles").Rows.Add(drNewRow)
Introduction
Procedure: Adding rows to a DataSet
Module 4: Using Data in Windows Forms Applications 25
To edit existing rows in a DataSet table:
1. Call the BeginEdit method of the row.
2. Change the data in the columns.
3. Call EndEdit or CancelEdit to accept or reject the changes.
The following code shows how to edit data in an existing column:
DataRow drChangeRow = datPubs.Tables["Titles"].Rows[0];
drChangeRow.BeginEdit( );
drChangeRow["Title"] = drChangeRow["Title"].ToString() + "
1";
drChangeRow.EndEdit( );
Use either of the following methods to delete a row:
� Remove method
Call the Remove method of the DataRows collection. This permanently removes the row from the DataSet.
� Delete method
Call the Delete method of the DataRow object. This only marks the row for deletion in the DataSet, and calling RejectChanges will undo the deletion.
The following code shows how to delete an existing row from a DataSet:
DataRow drDelRow = datPubs.Tables["Titles"].Rows[0];
datPubs.Tables["Titles"].Rows.Remove(drDelRow);
Procedure: Editing rows in a DataSet
Procedure: Deleting data in a DataSet
26 Module 4: Using Data in Windows Forms Applications
How to Data to a Data Source
SqlCommand comm = new SqlCommand("Insert titles &_(title_id, title, type) values (@title_id,@title,@type)");comm.Parameters.Add("@title_id", SqlDbType.VarChar, 6, &_"title_id");comm.Parameters.Add("@title", SqlDbType.VarChar, 80, "title");comm.Parameters.Add("@type", SqlDbType.Char, 12, "type");
adaptSQL.InsertCommand = comm;adaptSQL.Update(dsPubs, "titles");
SqlCommand comm = new SqlCommand("Insert titles &_(title_id, title, type) values (@title_id,@title,@type)");comm.Parameters.Add("@title_id", SqlDbType.VarChar, 6, &_"title_id");comm.Parameters.Add("@title", SqlDbType.VarChar, 80, "title");comm.Parameters.Add("@type", SqlDbType.Char, 12, "type");
adaptSQL.InsertCommand = comm;adaptSQL.Update(dsPubs, "titles");
adaptSQL = new SqlDataAdapter("Select pub_id, title_id, title, " +"type, price from titles", conSQL);
adaptSQL.Fill(dsPubs, "Titles");DataRow drNewRow = dsPubs.Tables["Titles"].NewRow();drNewRow["type"] = "business";dsPubs.Tables["Titles"].Rows.Add(drNewRow);SqlCommandBuilder sqlCommBuild = new SqlCommandBuilder(adaptSQL);adaptSQL.Update(dsPubs, "titles");
adaptSQL = new SqlDataAdapter("Select pub_id, title_id, title, " +"type, price from titles", conSQL);
adaptSQL.Fill(dsPubs, "Titles");DataRow drNewRow = dsPubs.Tables["Titles"].NewRow();drNewRow["type"] = "business";dsPubs.Tables["Titles"].Rows.Add(drNewRow);SqlCommandBuilder sqlCommBuild = new SqlCommandBuilder(adaptSQL);adaptSQL.Update(dsPubs, "titles");
� Automatically specifying updates
� Explicitly specifying the updates
*****************************ILLEGAL FOR NON-TRAINER USE******************************
After you have updated the tables in your DataSet, you will want to replicate those changes to the underlying data source. To do this, use the Update method of the DataAdapter object, which is the link between DataSet and data source.
The Update method, like the Fill method, takes two parameters: the DataSet and the name of the DataTable in which the changes have been made. The Update method determines the changes to the data and executes the appropriate SQL command (Insert, Update or Delete) against the source data.
You use the InsertCommand, UpdateCommand, and DeleteCommand
properties of the DataAdapter to identify the changes occurring in your DataSet. You specify each of these as an existing command object for an Insert, Update, or Delete SQL statement. For any variable columns in the statements, you use SqlParameter objects to identify the column, data type, size, and data to be inserted.
Introduction
Procedure: Explicitly specifying the updates
Module 4: Using Data in Windows Forms Applications 27
The following code shows how to use the InsertCommand property to add a row to the Titles table in the Pubs database:
SqlCommand comm = new SqlCommand("Insert titles (title_id,
title, type) values (@title_id,@title,@type)");
comm.Parameters.Add("@title_id", SqlDbType.VarChar, 6,
"title_id");
comm.Parameters.Add("@title", SqlDbType.VarChar, 80, "title");
comm.Parameters.Add("@type", SqlDbType.Char, 12, "type");
adaptSQL.InsertCommand = comm;
adaptSQL.Update(dsPubs, "titles");
28 Module 4: Using Data in Windows Forms Applications
If your DataTable is generated from only one table in the data source, you can use the CommandBuilder object to automatically create the InsertCommand, UpdateCommand, and DeleteCommand properties. You can also use the DataAdapter Wizard to generate the InsertCommand, UpdateCommand, and DeleteCommand properties.
The following code shows how to use the CommandBuilder object to achieve the same results as the previous example:
adaptSQL = new SqlDataAdapter("Select pub_id, title_id, title,
" +
"type, price from titles", conSQL);
adaptSQL.Fill(dsPubs, "Titles");
DataRow drNewRow = dsPubs.Tables["Titles"].NewRow();
drNewRow["title_id"] = "hg8765";
drNewRow["title"] = "New Book";
drNewRow["type"] = "business";
dsPubs.Tables["Titles"].Rows.Add(drNewRow);
SqlCommandBuilder sqlCommBuild = new
SqlCommandBuilder(adaptSQL);
adaptSQL.Update(dsPubs, "titles");
Even though the automatically generated commands can simplify your coding, you will improve performance by using the InsertCommand, UpdateCommand, and DeleteCommand properties.
Procedure: Automatically generating the updates
Note
Module 4: Using Data in Windows Forms Applications 29
Practice: Populating and Updating DataSets
� In this practice, you will populate a DataSetand update a database with the changes made to the DataSet.
� Configure the SQLConnection control on to connect to the database
� Populate the DataSet
� Update the Database
� Test the application
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this practice, you will populate a dataset and update a database with the changes made to the dataset. You will fill the dataset with the Stores and Sales tables of the Pubs database. For the Stores table, you will write all of the code required to populate the dataset. For the Sales table, you will use the code generated by the Data Adapter Configuration Wizard and a typed dataset. You will also update the database with any changes to the Sales table.
◮ Open the project file
1. Start Visual Studio .NET.
2. In the Start Page window, click Open Project.
3. In the Look in list, navigate to
install_folder\Practices\Mod04\Mod04_02\Starter, and then open the PopulatingAndUpdatingDataSets.sln solution file.
◮ Configure the SQLConnection1 control on Form1 to connect to the
Pubs database
1. Open Form1 in Design View.
2. Select SQLConnection1, in the Properties window, click the
ConnectionString property, click the down arrow, and then click New
Connection.
Use the existing connection information for the Pubs database if it already exists and skip to the next procedure.
3. In the Data Link Properties dialog box, type <computername>\MOC
where <computername> is the name of your computer.
4. Select the Use Windows NT Integrated Security option.
Note
30 Module 4: Using Data in Windows Forms Applications
5. In the database connection drop down list, click the pubs database, click
Test Connection to ensure that you can access the pubs database, and then
click OK.
6. Click OK to close the Data Link Properties dialog box.
◮ Populate StoreSalesDataSet1 with data from the Stores table
1. Locate TODO: 1 in the code window of Form1.
2. Under TODO: 1, declare and instantiate a SqlDataAdapter named
storesSQLDataAdapter.
3. Declare and instantiate a SqlCommand named
storesSelectSQLCommand.
4. Declare a DataTable named storesTable and initialize it with the String
Stores. Your code should look like the following:
System.Data.SqlClient.SqlDataAdapter storesSQLDataAdapter =
new System.Data.SqlClient.SqlDataAdapter();
System.Data.SqlClient.SqlCommand storesSelectSQLCommand =
new System.Data.SqlClient.SqlCommand();
DataTable storesTable = new DataTable("Stores");
5. Locate TODO: 2 in the code window of Form1.
6. Under TODO: 2, set the CommandType property of
storesSelectSQLCommand to CommandType.Text.
7. Set the CommandText property of storesSelectSQLCommand to,
“SELECT stor_id, stor_name FROM stores”.
8. Set the Connection property of storesSelectSQLCommand to
SQLConnection1.
9. Set the SelectCommand property of storesSQLDataAdapter to
storesSelectSQLCommand. Your code should look like the following:
storesSelectSQLCommand.CommandType = CommandType.Text;
storesSelectSQLCommand.CommandText = "SELECT stor_id,
stor_name FROM stores";
storesSelectSQLCommand.Connection = sqlConnection1;
storesSQLDataAdapter.SelectCommand =
storesSelectSQLCommand;
10. Locate TODO: 3 in the code window of Form1.
11. Under TODO: 3, use the Fill method of storesSQLDataAdapter to
populate storesTable.
12. Use the Add method to add storesTable to the Tables collection of the
existing StoreSalesDataSet DataSet. Your code should look like the following:
storesSQLDataAdapter.Fill(storesTable);
StoreSalesDataSet1.Tables.Add(storesTable);
◮ Use existing code generated by the Data Adapter Configuration Wizard
and a typed dataset to populate StoreSalesDataSet1 with data from the
Sales table
Module 4: Using Data in Windows Forms Applications 31
The CommandText property of SalesSQLSelectCommand is set to the following:
“SELECT stor_id, ord_num, qty, ord_date, payterms, title_id
FROM sales WHERE (stor_id = @stor_id)”
You must assign the @stor_ID parameter a value in order to get the required results. You use the Parameters collection of the SQLCommand object to assign this value.
1. Locate TODO: 4 in the code window of Form1.
2. Under TODO: 4, use the SelectCommand property of
SalesSqlDataAdapter to access SalesSQLSelectCommand and set the Value property of the @storeid parameter in the Parameters collection to
storeID. Your code should look like the following:
SalesSQLDataAdapter.SelectCommand.Parameters["@stor_id"].Va
lue = storeID;
3. Locate TODO: 5 in the code window of Form1.
4. Under TODO: 5 use the Clear method of Sales DataTable in
StoreSalesDataSet1 to clear the Sales table of any existing data. Your code
should look like the following:
StoreSalesDataSet1.sales.Clear();
5. Locate TODO: 6 in the code window of Form1.
6. Under TODO: 6, use the Fill method of SalesSQLDataAdapter to
populate the sales property of StoreSalesDataSet1. Your code should look like the following:
SalesSqlDataAdapter.Fill(StoreSalesDataSet1.sales);
◮ Update the Pubs database with the changes in StoreSalesDataSet1
1. Locate TODO: 7 in the code window of Form1.
2. Under TODO: 7, use the Update method of SalesSqlDataAdapter and pass
StoreSalesDataSet1 as an argument. Your code should look like the
following:
SalesSqlDataAdapter.Update(StoreSalesDataSet1);
◮ Test the application
1. Press F5 to compile and run the application.
2. In the Stores list, click News and Brews.
You may want to set breakpoints in your code to follow the execution path.
3. Click the bottom row of the DataGrid to create a new row and enter the following fields.
Field Value stor_id 7067
ord_num P2122
Tip
32 Module 4: Using Data in Windows Forms Applications
qty 12
ord_date 6/13/2002
payterms Net 60
title_id PC9999
8. Click Update.
9. Switch to the Visual Studio.NET IDE and use the Server Explorer to verify that the database was updated.
10. Switch back to the Store Orders application, set the qty field of the new row to 24, and then click Update.
11. Switch to the Visual Studio.NET IDE and use the Server Explorer to verify
that the database was updated.
You can refresh the view by right-clicking the results and then click Run.
12. Switch back to the Store Orders application, delete the new row, and then
click Update.
13. Switch to the Visual Studio.NET IDE and use the Server Explorer to verify that the database was updated.
Module 4: Using Data in Windows Forms Applications 33
How to Create Relationships in DataSets
DataRelation relPubsTitle = new DataRelation("PubsTitles", dsPubs.Tables["Publishers"].Columns["pub_id"], dsPubs.Tables["Titles"].Columns["pub_id"]);
dsPubs.Relations.Add(relPubsTitle);
DataRelation relPubsTitle = new DataRelation("PubsTitles", dsPubs.Tables["Publishers"].Columns["pub_id"], dsPubs.Tables["Titles"].Columns["pub_id"]);
dsPubs.Relations.Add(relPubsTitle);
DataRow PubRow;DataRow[] TitleRows;
PubRow = dsPubs.Tables["Publishers"].Rows[0];TitleRows = PubRow.GetChildRows("PubsTitles");
foreach (DataRow TitleRow in TitleRows)listBox1.Items.Add(TitleRow["title"].ToString());
DataRow PubRow;DataRow[] TitleRows;
PubRow = dsPubs.Tables["Publishers"].Rows[0];TitleRows = PubRow.GetChildRows("PubsTitles");
foreach (DataRow TitleRow in TitleRows)listBox1.Items.Add(TitleRow["title"].ToString());
� Creating Relationships
� Accessing Related Data
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Databases rely on the ability to associate tables to each other to define their relationships. For example, the Titles table in the Pubs database is a child of the Publishers table. This relationship on the database enforces referential integrirty. ADO.NET provides this ability in DataSets through the DataRelation class.
Each DataRelation object contains an array of DataColumn objects that define the parent column or columns, or primary key, and the child column or columns, or foreign key, in the relationship. Referential integrity is maintained by the relationship, and you can specify how to deal with related changes.
Introduction
34 Module 4: Using Data in Windows Forms Applications
The following code shows how to create a relationship between two DataTable objects in a DataSet. The same DataAdapter populates the DataTable objects, and then a DataRelation is created between the two.
SqlConnection conSQL;
conSQL = new SqlConnection();
conSQL.ConnectionString = "Integrated Security=True;Data
Source=LocalHost;Initial Catalog=Pubs;";
conSQL.Open( );
SqlDataAdapter adaptSQL;
DataSet dsPubs = new DataSet();
adaptSQL = new SqlDataAdapter("Select pub_id, pub_name, city,
state from publishers", conSQL);
adaptSQL.Fill(dsPubs, "Publishers");
adaptSQL = new SqlDataAdapter("Select pub_id, title, type,
price from titles", conSQL);
adaptSQL.Fill(dsPubs, "Titles");
DataRelation relPubsTitle = new DataRelation("PubsTitles",
dsPubs.Tables["Publishers"].Columns["pub_id"],
dsPubs.Tables["Titles"].Columns["pub_id"]);
dsPubs.Relations.Add(relPubsTitle);
The main use of a DataRelation is to allow access to related records in a different table. You can do this by using the GetChildRows method of a DataRow object that returns an array of DataRow objects. The following code shows how to use this method to access the child rows that match the first publisher by using the relationship created in the previous example:
DataRow PubRow;
DataRow[] TitleRows;
PubRow = dsPubs.Tables["Publishers"].Rows[0];
TitleRows = PubRow.GetChildRows("PubsTitles");
foreach (DataRow TitleRow in TitleRows)
listBox1.Items.Add(TitleRow["title"].ToString());
For more information about DataRelations see Introduction to DataRelation Objects in the Visual Studio .NET documentation.
Procedure: Creating relationships
Procedure: Accessing related data
Module 4: Using Data in Windows Forms Applications 35
How to Create Database Schema on the Client
� XML Schemas (.xsd) enforce data integrity on the client
� Use the XML Designer to create and modify XML Schemas
1. Determine the schema design
2. On the Project menu, click Add New Item
3. Add the schema
4. Create the schema
*****************************ILLEGAL FOR NON-TRAINER USE******************************
ADO.NET typed datasets are classes that are generated from XML Schemas (.xsd file). The definition of the DataSet class changes if any changes are made to the schema. When working with XML Schemas and typed dataset representations in Visual Studio at design time there is essentially no difference. They are both .xsd files in the XML Designer, the difference is that typed datasets have an associated class file and a predefined document (or root) node that represents the encompassing dataset.
XML Schemas are documents that define and validate the content and structure of XML data, just as a database schema defines and validates the tables, columns, and data types that make up a database. The XML Schema performs the following functions:
� It describes the shape of the XML document — for example, whether the
XML document is constructed hierarchically or in a keyed relationship.
� It validates data imported from an XML stream or document into a dataset.
� It establishes the relational structure of the dataset's tables and columns, the key columns, constraints, and relationships between tables. The relational
structure information is used when generating a DataSet class.
Introduction
36 Module 4: Using Data in Windows Forms Applications
To create an XML schema:
1. Determine the design needed for your schema.
2. On the Project menu, click Add New Item.
3. Do one of the following:
a. To add a schema, open the appropriate folder, and then double-click XML Schema.
An XML Schema file (.xsd file) is added to your project.
b. To add a dataset, open the appropriate folder, and then double-click
DataSet.
An XML Schema file and typed DataSet class file (.vb or .cs file) are added to your project.
4. To create the schema, add elements and attributes.
Procedure
Module 4: Using Data in Windows Forms Applications 45
Lesson: Binding Data to Controls
� How to Perform Simple Binding Using the DataBindings Collection
� How to Perform Complex Databinding Using the DataBound Windows Controls
� Practice: Binding Controls to Data
� What Is CurrencyManager?
� How to Maintain Currency with the BindingContext Object
� Demonstration: Navigating a DataSet Using the BindingContextProperty
� How to Format and Parse DataBound Values
� Demonstration: Formatting Data Bound Controls
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In Windows Forms, you can bind to not just traditional data sources, but also to almost any structure that contains data. You can bind to an array of values that you calculate at run time, read from a file, or derive from the values of other controls. In addition, you can bind any property of any control to the data source. In traditional data binding, you typically bind the display property (for example, the Text property of a TextBox control) to the data source. With the .NET Framework, you also have the option of setting other properties via binding as well.
Windows Forms can take advantage of two types of data binding: simple binding and complex binding. This lesson covers how to bind data to controls by using simple binding and complex binding.
After completing this lesson, you will be able to:
� Describe the ControlBindings collection.
� Perform simple binding by using the DataBindings property.
� Perform complex binding by using data bound Windows controls.
� Describe the CurrencyManager object.
� Maintain the currency of an object by using the BindingContext object.
� Format data-bound values.
Introduction
Lesson objectives
46 Module 4: Using Data in Windows Forms Applications
How to Perform Simple Binding by Using the DataBindings
Property
txtCustomerAddress.DataBindings.Add("Text", dsNorthwindData1.Customers, "Address");
txtCustomerCity.DataBindings.Add("Text", dsNorthwindData1.Customers, "City");
txtCustomerAddress.DataBindings.Add("Text", dsNorthwindData1.Customers, "Address");
txtCustomerCity.DataBindings.Add("Text", dsNorthwindData1.Customers, "City");
Property of the control to which data is bound
Property of the control to which data is bound
Column in the tableColumn in the tableTable from the data sourceTable from the data source
To use the DataBindings Collection to bind a control
to a data source, set the DataBinding property of the
control to the data source
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In Windows Forms, you can bind to not just traditional data sources, but also to almost any structure that contains data. For example, you can bind to arrays,
collections, properties of other controls, and ADO.NET objects such as data views and table columns.
Simple data binding is accomplished by adding Binding objects to a ControlBindingsCollection. The Binding class is used to create and maintain a simple binding between the property of a control and the property of an object. Any object that inherits from the Control class maintains a list of the Binding objects in the ControlBindingsCollection. The DataBindings property exposes the ControlBindingsCollection, and like any collection, supports methods to Add, Remove, and Clear the objects (Bindings) in it.
To simple-bind a control:
1. In the form, select the control and display the Properties window.
2. Expand the (DataBindings) property.
The properties most often bound are displayed in the (DataBindings) property list. For example, in most controls, the Text property is most frequently bound.
3. If the property you want to bind is not one of the commonly bound
properties, click the Ellipsis button (…) in the (Advanced) box to display
the Advanced Data Binding dialog box with a complete list of properties for that control.
4. Click the list arrow for the property you want to bind.
A list of available data sources is displayed.
5. Expand the data source you want to bind to until you find the single data
element you want.
Introduction
Procedure: Simple binding at design time
Module 4: Using Data in Windows Forms Applications 47
For example, if you are binding to a column value in a dataset's table, expand the name of the dataset, and then expand the table name to display column names.
6. Click the name of an element to bind to it.
48 Module 4: Using Data in Windows Forms Applications
You can also create a Binding object programmatically at run time. To do so, use the Add method of the DataBindings collection. The method expects the following arguments:
� Name of the property of the control that will consume the data
� Data source
� Name of the field in the data source to bind to.
The following code binds the Text property of the txtCustomer TextBox to the Address column of the Customers tables in the dsNorthwind1 typed dataset:
txtCustomerAddress.DataBindings.Add("Text",
dsNorthwindData1.Customers, "Address");
A period-delimited navigation path is required when the data source is set to an object that contains multiple DataTable objects (such as a DataSet or DataViewManager). For example, the previous code could also be written as shown.
txtCustomerAddress.DataBindings.Add("Text", dsNorthwindData1,
"Customers.Address");
Procedure: Simple binding at runtime
Module 4: Using Data in Windows Forms Applications 49
How to Perform Complex Databinding by Using the DataBound
Windows Controls
� Complex Data Binding
� Bind a control property to a data table
� Used with combo boxes, list boxes, data grids
� Can bind controls to DataSets, Arrays, ArrayLists, etc
� Complex Databinding at design time
� Set the DataSource and DataMember properties
� Complex Databinding at Run Time
DataGrid1.DataSource = dsMyDataSet;
DataGrid1.DataMember = "Products";
DataGrid1.DataSource = dsMyDataSet;
DataGrid1.DataMember = "Products";
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Instead of binding each data field to a separate control, you bind the complete data source to one control. This is called complex data binding. A very useful component for complex data binding is the DataGrid control.
Because a DataSet can contain more than one DataTable, there are two relevant properties: DataSource and DisplayMember. DataSource refers to the DataSet and DisplayMember refers to the contained DataTable. Alternatively, you can use the SetDataBinding method to set both values at once.
To bind a combo box, list box or a data grid to a data source at design time:
1. Add the control to the form.
2. Select the control.
3. Set the DataSource property to the data source, such as a dataset.
4. Set the DisplayMember property to the name of a column in the data source.
To bind a data-bound control to a data source at run time, add the following lines of code that set the DataSource and DisplayMember properties:
DataGrid1.DataSource = dsMyDataSet;
DataGrid1.DataMember = "Products";
If the DataSource property is not ambiguous, you can use it without defining the DataMember. The following code accomplishes the same results as the previous line of code:
DataGrid1.DataSource = dsMyDataSet.Tables[“Products”];
Introduction
Procedure: Complex data binding at design time
Procedure: Complex data binding at run time
50 Module 4: Using Data in Windows Forms Applications
Practice: Binding Controls to Data
� In this practice, you will perform simple and complex binding to bind controls to data
� Configure the SQLConnection control to connect to the database
� Bind controls to columns in the DataSet at design time
� Bind controls to columns in the DataSet at run time
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this practice, you will bind various controls to data in a DataSet at design time and also programmatically at run time. You will begin by using simple binding to bind data to Label controls and then you will use complex data binding to bind data to a ComboBox and a DataGrid.
◮ Open the DataBinding project
1. Start Visual Studio .NET.
2. In the Start Page window, click Open Project.
3. In the Look in list, navigate to
install_folder\Practices\Mod04\Mod04_04\Starter, and then open the DataBinding.sln solution file.
◮ Configure the SQLConnection1 control on Form1 to connect to the
Pubs database
1. Open Form1 in design view.
2. Select SQLConnection1, and in the Properties window, click the
ConnectionString property, click the down arrow, and then click New
Connection.
Use the existing connection information for the Pubs database if it already exists and skip to the next procedure.
3. In the Data Link Properties dialog box, type computername\MOC where
computername is the name of your computer.
4. Select the Use Windows NT Integrated Security option.
5. In the database connection drop down list, click the pubs database, click
Test Connection to ensure that you can access the pubs database, and then
click OK.
Note
Module 4: Using Data in Windows Forms Applications 51
◮ Bind StateLabel control to the State column by using the Properties
window
1. Open Form1 in design view.
2. In the Properties window, select StateLabel on Form1, and then expand DataBindings.
3. Select the Text property, click the Text Property arrow, expand StoresSalesDataSet1, expand Sales, and then click State.
◮ Bind CityLabel to the city column programmatically at run time
1. Locate TODO: 1 in the code window of Form1.
2. Under TODO: 1, call the Add method of the DataBindings collection of CityLabel, and pass Text as the name of the property,
StoreSalesDataSet1.sales as the name of the data source, and city as the
name of the column.
◮ Bind DataGrid1 to the sales table by using the Properties window
1. Open Form1 in design view.
2. Select DataGrid1 on Form1 and use the Properties window to set the
DataSource property to StoreSalesDataSet1.
3. Use the Properties window to set the DataMember to sales.
◮ Bind StoresComboBox to the stores table programmatically at run time
1. Locate TODO: 2 in the code window of Form1.
2. Under TODO: 2, set the DataSource property of StoresComboBox to the Stores table in StoreSalesDataSet1.
3. Set the DisplayMember property of StoresComboBox to the stor_name
column.
4. Set the ValueMember property of StoresComboBox to the stor_id
column.
The ComboBox control allows you to bind the ValueMember property
to an alternate value that is not displayed in the ComboBox. This is often used when you want to display a user friendly value to the user and bind to another field that is used programmatically, such as a primary key.
◮ Test the application
1. Press F5 to compile and run the application.
2. Select different stores in the Stores list to ensure the controls display the data bound values.
Note
52 Module 4: Using Data in Windows Forms Applications
What Is CurrencyManager?
Datagrid
Data Source 1
Data Source 2
Currency Manager1Currency Manager1
TextBox1TextBox1
TextBox2TextBox2
Currency Manager2Currency Manager2
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Any data source you bind a to Windows Forms control to will have an associated CurrencyManager object.
The CurrencyManager is used to keep data-bound controls synchronized with a data source. The CurrencyManger is important because data sources, such as Tables in DataSets, do not keep track of the currently selected row. You need an intermediary object that is aware of the currently selected position in a data source and can notify databound controls when the position changes. That intermediary object is a CurrencyManager. The CurrencyManager object does this by managing a collection of the bound data supplied by a data source.
For each data source associated with a Windows Form, the form maintains at least one CurrencyManager. There is a CurrencyManager object on the form for each discrete data source that you are binding to. If the controls on the form all bind to a single source (for example, if several TextBox controls are bound to the same data table), then they will share the same CurrencyManager. However, there are times when controls on the form will be bound to different sources. In that case, there are multiple CurrencyManager objects on the form, each one keeping track of which record or data element is being used by the controls.
The following table lists some of the properties of the CurrencyManager object that helps it track data.
Property Description Bindings Gets the collection of bindings being
managed.
Count Determines the last item in the list of rows
Current Contains the value of the current item in
the data source
List Gets the data source (which implements
IList) for this CurrencyManager.
Position Specifies the position of the item in the
Introduction
Definition
CurrencyManager properties
Module 4: Using Data in Windows Forms Applications 53
underlying list
54 Module 4: Using Data in Windows Forms Applications
How to Maintain Currency with the BindingContext Object
� The BindingContext object keeps track of all CurrencyManager objects on a form
� Increment the Position property of the BindingContext to navigate the dataset and update databound controls
Currency ManagerCurrency Manager
Currency ManagerCurrency Manager
Currency ManagerCurrency Manager
Data TableData Table
CollectionCollection
ArrayArray
Binding ContextBinding Context
Form1
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Every Windows Form has a BindingContext object. The BindingContext object keeps track of all of the CurrencyManager objects on a form. Thus, any Windows Form with data-bound controls has at least one BindingContext object keeping track of one (or more) CurrencyManager object(s) keeping track of one data source (for each CurrencyManager).
For example, if you add a TextBox control to a form and bind it to a column of a table in a dataset, the control communicates with the BindingContext object for that form. The BindingContext object, in turn, communicates with the specific CurrencyManager object for that data association. If you query the CurrencyManager's Position property, it reports the current record for that TextBox control's binding.
You use the BindingContext of a form to access the various CurrencyManagers. To do so, you must specify the data source that the CurrencyManger is managing. For example, to access the CurrenyManager that manages the Authors table of DataSet1 you would use the following code:
CurrencyManager cm;
cm = (CurrencyManager)this.BindingContext[DataSet1,
"Authors"];
If you use a container control, such as a GroupBox, Panel, or TabControl to contain data-bound controls, you can create a BindingContext for just that container control and its controls. This allows each part of your form to be managed by its own CurrencyManager object.
To determine the currency of a control, use the Position property of the CurrencyManager as shown.
cm.Position += 1;
Introduction
Procedure: Determining the currency of a control
Module 4: Using Data in Windows Forms Applications 55
Demonstration: Navigating a DataSet by Using the BindingContext
Property
In this demonstration, you will see how to
navigate a DataSet by using the BindingContext
property
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this demonstration, you will learn how to navigate a DataSet by using the BindingContext property.
◮ Create a Windows application project
1. Open Visual Studio .NET.
2. On the File menu, point to New, and then click Project.
3. In the New Project dialog box, click Windows Application, name it
BindingContextNavigation, and then click OK.
◮ Use the Data Form Wizard to create a data bound form
1. On the File menu, click Add New Item.
2. In the Add New Item dialog box, in the Templates section, click Data
Form Wizard, and then click Open.
3. In the Data Form Wizard, click Next.
4. Specify the name of the new dataset as OrdersDataSet and click Next.
5. Select a connection to the Northwind database in the database connection
drop down list. If a connection does not exist, create a new connection. Click Next.
6. Add the Orders and Order Details tables by selecting them in the Available Items tree, click the Add (>) button, and then click Next.
7. In the Name box, type OrderOrderDetailsRelation.
8. Set the following settings.
List Setting Parent table Orders
Child table Order Details
56 Module 4: Using Data in Windows Forms Applications
Keys (for both tables) OrderID
9. Click the Add (>) button, and then click Next.
10. Ensure that the Orders table is set as the Master or single table and Order Details is set as the Detail table, and then click Next.
11. Select Single record in individual controls, and then click Finish.
◮ Display and discuss the code generated for the navigation buttons
1. Locate the Click event of the btnNavNext button in the code window of DataForm1 and discuss the following line of code:
this.BindingContext[objOrdersDataSet,"Orders"].Position =
(this.BindingContext[objOrdersDataSet,"Orders"].Position +
1);
2. Locate the objOrdersDataSet_PositionChanged() procedure and discuss the following line of code:
this.lblNavLocation.Text =
((((this.BindingContext[objOrdersDataSet,"Orders"].Position
+ 1)).ToString() + " of ")
+
this.BindingContext[objOrdersDataSet,"Orders"].Count.ToStri
ng());
3. Locate the Click event of the btnLast button in the code window of DataForm1 and discuss the following line of code:
this.BindingContext[objOrdersDataSet,"Orders"].Position =
(this.objOrdersDataSet.Tables["Orders"].Rows.Count - 1);
4. In Solution Explorer, right click the BindingContextNavigation project,
and then click Properties.
5. Set DataForm1 as the Startup object, and then click OK.
6. Press F5 to compile and run the application, and then demonstrate the use of the navigation buttons.
7. Close the application.
Sometimes you may choose to prototype a data application by using the Data Form Wizard and use the code generated for you.
Module 4: Using Data in Windows Forms Applications 57
How to Format and Parse DataBound Values
TextBox1TextBox1Format
Parse
Binding ObjectData Source
10 $10
$1010
*****************************ILLEGAL FOR NON-TRAINER USE******************************
Often the data retrieved from a data source may not match the data type accepted by a control in your application. The Binding object provides two methods, Format and Parse to ensure that the data received and sent back to the data source is of the right data type.
The Format event occurs both when data is pushed from the data source into the control, and when the data is pulled from the control into the data source. When the data is pushed from the data source into the control, the Binding object uses the Format event to put the formatted data into the control. When the data is pushed from the control into the data source, the Binding first parses the data by using the Parse event, then formats the data and sends it to the data source.
The Format and Parse events allow you to create custom formats for
displaying data. For example, if the data in a table is of type Decimal, you can display the data in the local currency format by setting the Value property of
the ConvertEventArgs object to the formatted value in the Format event. You
must consequently unformat the displayed value in the Parse event.
The Format event occurs whenever the current value of the BindingManagerBase changes, which includes:
� The first time the property is bound.
� Any time the Position changes.
� Whenever the data-bound list is sorted or filtered, which is accomplished
when a DataView supplies the list.
The Parse event occurs:
� After the Validated event of the Control object occurs.
� When the EndCurrentEdit method of the BindingManagerBase is called.
� When the current object of the BindingManagerBase changes (in other
words, when the Position changes).
Introduction
Format and Parse events
58 Module 4: Using Data in Windows Forms Applications
The following code creates event delegates for the Parse and Format events of a Binding object, and then uses event procedures to format the data between a String and a Decimal:
private void BindControl()
{
Binding priceBinding = new
Binding("Text",titlesDataSet1,"titles.price");
priceBinding.Format += new
ConvertEventHandler(this.FormatDecimalToString);
priceBinding.Parse += new
ConvertEventHandler(this.ParseStringToDecimal);
PriceTextBox.DataBindings.Add(priceBinding);
}
private void FormatDecimalToString(object sender,
ConvertEventArgs convertArgs)
{
convertArgs.Value =
Convert.ToDecimal(convertArgs.Value).ToString("c");
}
private void ParseStringToDecimal(object sender,
ConvertEventArgs convertArgs)
{
convertArgs.Value =
Decimal.Parse(convertArgs.Value.ToString(),
NumberStyles.Currency);
}
Procedure: Using the Format and Parse events
Module 4: Using Data in Windows Forms Applications 59
Practice: Formatting Data Bound Controls
� In this practice, you will use the Format and Parse events to format data.
� Configure the SQLConnection control to connect to the database
� Create an event procedure for the Parse event
� Create an event delegate for the Parse event
*****************************ILLEGAL FOR NON-TRAINER USE******************************
In this practice, you will add event handlers to the Format and Parse events of a Binding object and then use the ConvertEventArgs class to apply appropriate formatting to the data bound value.
◮ Open the project
1. Start Visual Studio .NET.
2. In the Start Page window, click Open Project.
3. In the Look in list, navigate to
install_folder\Practices\Mod04\Mod04_05\Starter, and then open the
FormatParse.sln solution file.
◮ Configure the SQLConnection1 control on Form1 to connect to the
Pubs database
1. Open Form1 in design view.
2. Select SQLConnection1, in the Properties window, click the ConnectionString property, click the down arrow, and then select New
Connection.
Use the existing connection information for the Pubs database if it already exists and skip to the next procedure.
3. In the Data Link Properties dialog box, type computername\MOC where
computername is the name of your computer.
4. Select the Use Windows NT Integrated Security option.
5. In the database connection drop down list, click the pubs database, click Test Connection to ensure you can access the pubs database, and then click
OK.
Note
60 Module 4: Using Data in Windows Forms Applications
◮ Create an event procedure invoked by the Parse event that converts the
Value of ConvertEventArgs from a String to a Decimal
1. Locate TODO: 1 in the code window of Form1.
2. Under TODO: 1, create a procedure called ParseStringToDecimal that
accepts two arguments: sender as an Object and convertArgs as a
ConvertEventArgs.
3. Assign the Value of convertArgs to a String named stringValue.
4. Call the Parse method of the Decimal object and pass the two arguments:
stringValue as the string to be formatted and NumberStyles.Currency as the NumberStyles constant.
5. Assign the results of the Parse method to Value property of convertArgs. Your code should look like:
private void ParseStringToDecimal(object sender,
ConvertEventArgs convertArgs)
{
convertArgs.Value =
Decimal.Parse(convertArgs.Value.ToString(),
NumberStyles.Currency);
}
The Parse method converts the String representation of a number in a specified style to its Decimal equivalent by using the specified formatting style.
◮ Create an event delegate for the Parse event that references the
FormatDecimalToString procedure
1. Locate TODO: 2 in the code window of Form1.
2. Under TODO: 2, use AddHandler to create an event delegate for the Parse event of the priceBinding object that references the
ParseStringToDecimal procedure. Your code should look like the following:
priceBinding.Parse += new
ConvertEventHandler(this.ParseStringToDecimal);
3. The priceBinding object is a Binding object that is added to the DataBindings collection of PriceTextBox. Review the following code:
Binding priceBinding = new
Binding("Text",titlesDataSet1,"titles.price");
PriceTextBox.DataBindings.Add(priceBinding);
◮ Demonstrate the application
1. Press F5 to compile and run the application.
2. Select different titles in the Book Titles list and review how the Price textbox is updated and formatted.
3. Use the Price textbox to change the price of a book, and then click the Debug.Write Value button.
4. Display and review the results in the Output window of the Visual Stuio.NET IDE.
!"#$%&'(' (
!" # $ % & ' (
!"#$%&'!()*+,,-*.-/'012))-)
!"#" "$$%&& '& "( ')*+,#"(# -"$#+, '( )+&# "**.'$"#'+(&/ "(0
1!23456 *,+7'0%& #8% )%"(& +- "$$%&&'(9 0"#" '( :+;,
"**.'$"#'+(&3 68'& $8"*#%, 0%&$,'<%& #8% 1!23456 0'&$+((%$#%0
0"#" $."&&%&= #8% (%># $8"*#%, 0%&$,'<%& #8% 1!23456 $+((%$#%0
0"#" $."&&%&3
68'& $8"*#%, '& "<+;# -+;(0"#'+( <;'.0'(93 68%&% $."&&%& 8"7%
<%%( '( #8% ?'$,+&+-# 3456 @,")%A+,B &'($% '#& C,&# ,%.%"&% <;#
",% (+# +<&+.%#%3 D+; &8+;.0 B(+A #8% $."&&%& $+7%,%0 '( #8'&
$8"*#%, #+ -%%. $+)-+,#"<.% ;&'(9 )"(: +- #8% (%A%, -%"#;,%&
$+7%,%0 '( #8% $8"*#%,& #8"# -+..+A3
%324'+56-*.(7-)'(,'.8()'*829.-:;■ E,%"#% 0'&$+((%$#%0 +<F%$#&3
■ E"$8% 0"#"3
■ G"(0.% &*%$'". 0"#" #:*%&3
<-))+,)'(,'.8()'*829.-:;'
■ H%&&+( IJ K+,B'(9 A'#8 #8% !"!#!$%& "(0 !"!'&" E."&&%& )
■ H%&&+( LJ M%,'".'N"#'+(/ M*%$'".'N%0 6:*%&/ "(0 !"#" O'(0'(9 )*
! " # $ % & ' %
!"#$%&'$(#!)$*!+#$,-,.=.'*+,.2(,)'721>251-''
(,?+:42.(+,':-@2:/(,@'
.8-')A(11)'B+>',--/'.+'
92))'.8-'-324#
' + !"#$%&'( 1!23456 !'&$+((%$#%0 E."&&%&
,-./0-'1/2',-345
6+ $+)*.%#% #8'& <++B/ :+; );&# 8"7% &+)% ;(0%,&#"(0'(9 +- ?'$,+&+-# EP +, ?'$,+&+-#
Q'&;". O"&'$3 68'& $8"*#%, ,%R;',%& #8% 8",0A",% "(0 &+-#A",% .'&#%0 "# #8% <%9'(('(9 +-
#8'& <++B3
!"#$%& #'
C1-,,'D+8,)+,
K8-,'.:B(,@'.+')+17-'2'9:+51-4E'4B'F:).'@+21'()'.+'F,/'.8-')+1>.(+,#'&8-'
)+1>.(+,'()',+.'21G2B)'-1-@2,.'+:'9:-..BE'5>.'.8-'@+21'()'.+'F,/'2')+1>.(+,E'
:(@8.H' ?.-:'.82.E'.8-',-3.').-9'()'.+':-?2*.+:'B+>:'*+/-'2,/'1++A'?+:'5-..-:'9-:?+:I
42,*-#'&8()'5++A'*+7-:)')+4-'2)9-*.)'+?' !"#$%&'9-:?+:42,*-E'5>.'2'@++/'5++A'
.82.'/-1(7-:)'4+:-'(,I/-9.8'(,?+:42.(+,':-@2:/(,@' !"#$%&'9-:?+:42,*-'.>,(,@'
()' !"#$%&'()*+,-).""/&012&$')34#5$#!1'04)1'6)701/18&/&29E'2,/'B+>'*2,'/+G,1+2/'
(.'?+:'?:--#'0829.-:'JKE'L=49:+7(,@' !"#$%&'M-:?+:42,*-EN'?+*>)-)'+,' !"#$%&'
9-:?+:42,*-#'
O2,B'+?'.8-'*12))-)'(,'.8-'?>.>:-'*829.-:)'>)-'.8-'*12))-)'(,'.8()'*829.-:#'P82.'/+'
.8+)-'8(@8-:I1-7-1'*12))-)'+??-:'.82.'.8-)-'*12))-)'/+,Q.'+??-:H'&8-B'+??-:'-2)-'+?'
9:+@:244(,@'?+:'B+>E'.8-'/-7-1+9-:#'C-,-:211BE'2//(,@'12B-:)'.+'9:+7(/-'-2)-'+?'
9:+@:244(,@'*2,':-/>*-'9-:?+:42,*-E'5>.'.8-'24+>,.'+?'9-:?+:42,*-'/-@:2/2I
.(+,'G(11'72:B'52)-/'+,'.8-'*+/-'B+>'G:(.-#'=?'B+>:'*+/-':>,)'?2).'-,+>@8E'(.'42A-)'
)-,)-'.+'.2A-'2/72,.2@-'+?'.8-'-2)-I+?I9:+@:244(,@'5-,-F.#
"5.2(,(,@'.8-'5-).'9-:?+:42,*-'(,')*-,2:(+)'(,'G8(*8'423(4>4'9-:?+:42,*-'()'
4+:-'(49+:.2,.'.82,'-2)-'+?'9:+@:244(,@'4(@8.'4-2,'>)(,@'.8-'*12))-)'*+7-:-/'(,'
.8()'*829.-:#
!"#$%& #'
C1-,,'D+8,)+,
K8-,'.:B(,@'.+')+17-'2'9:+51-4E'4B'F:).'@+21'()'.+'F,/'.8-')+1>.(+,#'&8-'
)+1>.(+,'()',+.'21G2B)'-1-@2,.'+:'9:-..BE'5>.'.8-'@+21'()'.+'F,/'2')+1>.(+,E'
:(@8.H' ?.-:'.82.E'.8-',-3.').-9'()'.+':-?2*.+:'B+>:'*+/-'2,/'1++A'?+:'5-..-:'9-:?+:I
42,*-#'&8()'5++A'*+7-:)')+4-'2)9-*.)'+?' !"#$%&'9-:?+:42,*-E'5>.'2'@++/'5++A'
.82.'/-1(7-:)'4+:-'(,I/-9.8'(,?+:42.(+,':-@2:/(,@' !"#$%&'9-:?+:42,*-'.>,(,@'
()' !"#$%&'()*+,-).""/&012&$')34#5$#!1'04)1'6)701/18&/&29E'2,/'B+>'*2,'/+G,1+2/' !"#$%&'()*+,-).""/&012&$')34#5$#!1'04)1'6)701/18&/&29 !"#$%&'()*+,-).""/&012&$')34#5$#!1'04)1'6)701/18&/&29
(.'?+:'?:--#'0829.-:'JKE'L=49:+7(,@' !"#$%&'M-:?+:42,*-EN'?+*>)-)'+,' !"#$%&'
9-:?+:42,*-#'
O2,B'+?'.8-'*12))-)'(,'.8-'?>.>:-'*829.-:)'>)-'.8-'*12))-)'(,'.8()'*829.-:#'P82.'/+'
.8+)-'8(@8-:I1-7-1'*12))-)'+??-:'.82.'.8-)-'*12))-)'/+,Q.'+??-:H'&8-B'+??-:'-2)-'+?'
9:+@:244(,@'?+:'B+>E'.8-'/-7-1+9-:#'C-,-:211BE'2//(,@'12B-:)'.+'9:+7(/-'-2)-'+?'
9:+@:244(,@'*2,':-/>*-'9-:?+:42,*-E'5>.'.8-'24+>,.'+?'9-:?+:42,*-'/-@:2/2I
.(+,'G(11'72:B'52)-/'+,'.8-'*+/-'B+>'G:(.-#'=?'B+>:'*+/-':>,)'?2).'-,+>@8E'(.'42A-)'
)-,)-'.+'.2A-'2/72,.2@-'+?'.8-'-2)-I+?I9:+@:244(,@'5-,-F.#
"5.2(,(,@'.8-'5-).'9-:?+:42,*-'(,')*-,2:(+)'(,'G8(*8'423(4>4'9-:?+:42,*-'()'
4+:-'(49+:.2,.'.82,'-2)-'+?'9:+@:244(,@'4(@8.'4-2,'>)(,@'.8-'*12))-)'*+7-:-/'(,'
.8()'*829.-:#
H%&&+( IJ K+,B'(9 A'#8 #8% !"!#!$%& "(0 !"!'&" E."&&%& !"#$%&'(' )
6-77/5'(8'9/0:453';4<='<=-'/!0!1!23#'>5?'/!0!4#0' @>77-7
68% 1!23456 $."&& 8'%,",$8: $"( <% &*.'# '(#+ #A+ $"#%9+,'%&J $+((%$#%0 "(0 0'&$+((%$#%0
+<F%$#&3 @'9;,% ISI &8+A& #8% *,'($'*". $+((%$#%0 "(0 0'&$+((%$#%0 $."&&%&3 68'& .%&&+(
0%&$,'<%& #8% #A+ *,')",: 0'&$+((%$#%0 $."&&%&/ !"!#!$%& "(0 !"!'&"/ "& &8+A( '( #8% 0'"S
9,")/ "(0 )"(: +#8%, $."&&%& +- #8'& $"#%9+,: "& A%..3 68% 0'&$+((%$#%0 $."&&%& ",% $+7%,%0 '(
0%#"'. <%$";&% #8%&% $."&&%& $"( <% ;&%0 A'#8+;# %7%, $,%"#'(9 " $+((%$#'+( #+ " 0"#" &#+,%3
DataSet
XML Data Store
DataRelationCollection
Disconnected Classes Connected Classes
DataTableCollection
DataTable
DataRowCollection
DataColumnCollection
ConstraintCollection
.NET Data Provider
DataAdapter
SelectCommand
InsertCommand
UpdateCommand
DeleteCommand
DataReader
Command
Connection
ADO.NET Classes
ABCD&%'(E(' 68% $+))+( 1!23456 $."&&%& ",% &8+A( 8%,%3
68% $."&&%& &8+A( '( @'9;,% ISI ",% #8% *,')",: 1!23456 $."&&%& "(0 ",% ')*+,#"(# -+,
&;$$%&&-;..: ')*.%)%(#'(9 "( 1!23456 &+.;#'+(3 K'#8 %"$8 (%A 7%,&'+( +- 1!23456/ $8"(9%&
8"7% <%%( )"0% #+ #8%&% *,')",: $."&&%& #+ ')*,+7% -;($#'+(".'#: "(0 *%,-+,)"($%3
68% 0'&$+((%$#%0 0"#" "$$%&& $."&&%& :+; '(&#"(#'"#% '( :+;, "**.'$"#'+(& ",% ')*.%S
)%(#%0 '( #8% M:&#%)3!"#"30.. "&&%)<.: -,+) #8% 3456 @,")%A+,B3 68%&% $."&&%& ",% '( #8%
'()"&*+, !"! (")%&*"$%3 O%$";&% :+; );&# ;&% #8% !"!#!$%& +<F%$# A8%( :+;T,% ;&'(9 0'&S
$+((%$#%0 $."&&%&/ #8'& $8"*#%, <%9'(& <: $+7%,'(9 #8% !"!#!$%& +<F%$# "(0 #8% +<F%$#& A'#8
A8'$8 #8% !"!#!$%& +<F%$# A+,B& $.+&%.:3 68% !"!'&" +<F%$# '& $+7%,%0 '( 0%#"'. ."#%, +(3
' * !"#$%&'( 1!23456 !'&$+((%$#%0 E."&&%&
?.-:'.8()'1-))+,E'B+>'G(11'5-'251-'.+;
■ U&% " !"!#!$%& +<F%$# #+ 8+.0 #"<;.", ,+A& +- 0"#"3
■ U&% " !"!'&" $."&& #+ 8+.0 !"!#!$%& +<F%$#& #8"# ",% ,%."#%03
■ V)*.%)%(# " !"!-.&/ +<F%$# #+ *,+7'0% &+,#'(9 "(0 C.#%,'(9 +- " 0"#" #"<.%3
%).(42.-/'1-))+,'.(4-;'RS'4(,>.-)
&8-':121-18/4'012))1 !"!#!$%& +<F%$# ,%*,%&%(#& #"<;.", 0"#" "& "( '(S)%)+,:/ #"<;.", $"$8% +- ,+A&/ $+.;)(&/
"(0 $+(&#,"'(#&3 D+; #:*'$"..: ;&% #8% !"!#!$%& $."&& #+ *%,-+,) "(: 0'&$+((%$#%0 0"#"
"$$%&&3 D+; &#",# <: $,%"#'(9 "( '(&#"($% +- #8% !"!#!$%& $."&&/ "(0 #8%( "00 !"!01%2*3
+<F%$#& #8"# 0%C(% #8% #:*% +- 0"#" #+ <% 8%.0 "(0 '(&%,# !"!41/ +<F%$#& #8"# $+(#"'( #8%
0"#"3 68% -+..+A'(9 $+0%/ A8'$8 $,%"#%& " #"<.% -+, &#+,'(9 $",& '(-+,)"#'+(/ 0%)+(&#,"#%& #8%
$,%"#'+( +- " 0"#" #"<.%J
T2491-'+?'U()>21'V2)(*'0+/-
'Create the DataTable named "Cars"
Dim cars As New DataTable("Cars")
T2491-'+?'0W'0+/-
//Create the DataTable named "Cars"
DataTable cars = new DataTable ("Cars");
(&)!' FG'$!%' FH#"GBFG'H%IB"'DJBGC'$!%'J"H#6%' FI%
&8-')2491-'*+/-'()'(,*1>/-/'(,'.8-'2**+492,B(,@'4-/(2#'O2,B'+?'.8-)-'2:-')4211'
)2491-)'.82.'*+>1/,Q.':>,'5B'.8-4)-17-)E')+'.8-B'827-'5--,'6+(,-/'.+'*:-2.-'2')2491-'
9:+6-*.'.82.'/+-)':>,#'<++A'?+:'.8-'9:+6-*.)'.82.'-,/'G(.8'LT2491-0+/-#N'X+:'-3I
2491-E'.8-)-')2491-)'2:-'(,'.8-'!()*+,,-*.-/012))-)T2491-0+/-'9:+6-*.'+?'.8-'
'!()*+,,-*.-/012))-)T2491-0+/-T+1>.(+,')+1>.(+,#
68'& $+0% $,%"#%& "( %)*#: 0"#" #"<.% -+, A8'$8 #8% #!$%&5!*& *,+*%,#: '& &%# #+ 0!6)3
D+; $"( ;&% #8% #!$%&5!*& *,+*%,#: #+ "$$%&& #8'& 0"#" #"<.% A8%( '# '& '( " !"!#!$%& $+..%$S
#'+( W"& 0%#"'.%0 ."#%, '( #8'& $8"*#%, '( #8% &%$#'+( #'#.%0 XU&'(9 " !"!'&" 2<F%$# #+ E++,0'S
("#% K+,B <%#A%%( !"#" 6"<.%&YZ3
//(,@':121;$/<!''"56-*.)'.+'0:-2.-'2'T*8-42
68% !"!#!$%& +<F%$# '& (+# ;&%-;. ;(#'. '# 8"& " &$8%)"/ A8'$8 '& $,%"#%0 <: "00'(9
!"!01%2*3 +<F%$#& "(0 &%##'(9 #8% $+(&#,"'(#& +- %"$8 $+.;)(3 E+(&#,"'(#& 8%.* )"'(#"'(
0"#" '(#%9,'#: <: .')'#'(9 #8% 0"#" #8"# $"( <% *."$%0 '( #8% $+.;)(3 68% -+..+A'(9 $+0% "00&
!"!01%2*3 +<F%$#& #+ #8% 7!6) !"!#!$%& +<F%$#J
?.-:'.8()'1-))+,E'B+>'G(11'5-'251-'.+;
■ U&% " !"!#!$%& +<F%$# #+ 8+.0 #"<;.", ,+A& +- 0"#"3
■ U&% " !"!'&" $."&& #+ 8+.0 !"!'&" !"!#!$%& +<F%$#& #8"# ",% ,%."#%03
■ V)*.%)%(# " !"!-.&/ +<F%$# #+ *,+7'0% &+,#'(9 "(0 C.#%,'(9 +- " 0"#" #"<.%3 !"!-.&/
%).(42.-/'1-))+,'.(4-;'RS'4(,>.-)
(&)! FG'$!%' FH#"GBFG'H%IB" DJBGC'$!%'J"H#6%' FI%
&8-')2491-'*+/-'()'(,*1>/-/'(,'.8-'2**+492,B(,@'4-/(2#'O2,B'+?'.8-)-'2:-')4211'
)2491-)'.82.'*+>1/,Q.':>,'5B'.8-4)-17-)E')+'.8-B'827-'5--,'6+(,-/'.+'*:-2.-'2')2491-'
9:+6-*.'.82.'/+-)':>,#'<++A'?+:'.8-'9:+6-*.)'.82.'-,/'G(.8'LT2491-0+/-#N'X+:'-3I
2491-E'.8-)-')2491-)'2:-'(,'.8-'!()*+,,-*.-/012))-)T2491-0+/-'9:+6-*.'+?'.8-'
!()*+,,-*.-/012))-)T2491-0+/-T+1>.(+,')+1>.(+,#
H%&&+( IJ K+,B'(9 A'#8 #8% !"!#!$%& "(0 !"!'&" E."&&%& !"#$%&'(' K
T2491-'+?'U()>21'V2)(*'0+/-
'Add the DataColumn object using all properties
Dim vin As New DataColumn("Vin")
vin.DataType = GetType(String)
vin.MaxLength = 23
vin.Unique = True
vin.AllowDBNull = False
vin.Caption = "VIN"
cars.Columns.Add(vin)
'Add the DataColumn using defaults
Dim make As New DataColumn("Make") 'default is String
make.MaxLength = 35 'default is -1
make.AllowDBNull = False 'default is True
cars.Columns.Add(make)
Dim year As New DataColumn("Year",GetType(Integer))
year.AllowDBNull = False
cars.Columns.Add(year)
'Derived column using expression
Dim yearMake As New DataColumn("Year and Make")
yearMake.MaxLength = 70
yearMake.Expression = "Year + ' ' + Make"
cars.Columns.Add(yearMake)
T2491-'+?'0W'0+/-
//Add the DataColumn using all properties
DataColumn vin = new DataColumn("Vin");
vin.DataType = typeof(string);
vin.MaxLength = 23;
vin.Unique = true;
vin.AllowDBNull = false;
vin.Caption = "VIN";
cars.Columns.Add(vin);
//Add the DataColumn using defaults
DataColumn make = new DataColumn("Make");
make.MaxLength = 35;
make.AllowDBNull = false;
cars.Columns.Add(make);
DataColumn year = new DataColumn("Year", typeof(int));
year.AllowDBNull = false;
cars.Columns.Add(year);
//Derived column using expression
DataColumn yearMake = new DataColumn("Year and Make");
yearMake.DataType = typeof(string);
yearMake.MaxLength = 70;
yearMake.Expression = "Year + ' ' + Make";
cars.Columns.Add(yearMake);
68% !"!01%2*3 +<F%$# 8"& &%7%,". $+(&#,;$#+, +7%,.+"0&/ &+ :+; $"( $8++&% #8% +7%,S
.+"0 #8"# "$$%*#& #8% *",")%#%, 7".;%& #8"# C# <%&# #+ :+;, &$%(",'+3 V( #8'& %>")*.%/ #8%
$+(&#,;$#+, +- %"$8 !"!01%2*3 +<F%$# %>*%$#& #8% $+.;)(T& (")%3 68% !"!#(8& *,+*%,#:
' L !"#$%&'( 1!23456 !'&$+((%$#%0 E."&&%&
'& &%# #+ '"6.39 -+, ".. #8% !"!01%2*3 +<F%$#& %>$%*# #8% :%",/ A8'$8 '& &%# #+ "( :3"&9&6 W'(#Z
#8"# .')'#& #8'& $+.;)( #+ <% (;)%,'$ 0"#"3 68% ;!<=&39"> *,+*%,#: .')'#& #8% .%(9#8 +- #8%
&#,'(9 0"#"3 M%##'(9 #8% ?3.@2& *,+*%,#: #+ "62& $,%"#%& "( '(0%> #+ *,%7%(# 0;*.'$"#'+( +-
%(#,'%&3 68% A%%1/ B52%% *,+*%,#: '& &%# #+ C!%)& #+ %(&;,% #8"# #8% $+.;)( '& *+*;."#%0 A'#8
0"#"3 V- A%%1/ B52%% '& &%# #+ "62&/ :+; ",% (+# +<.'9"#%0 #+ *+*;."#% #8% $+.;)( A'#8 0"#"/
"(0 #8% $+.;)(T& 0%-";.# 7".;% '& B52%%/ A8'$8 '& &#+,%0 #+ #8% 0"#"<"&% "& " (;.. 7".;%3 68%
0!8".13 *,+*%,#: '&(T# ,%"..: " $+(&#,"'(#= '#T& " &#,'(9 #8"# 8+.0& #8% $+.;)( 8%"0'(9 A8%( #8'&
!"!#!$%& +<F%$# '& ;&%0 A'#8 9,"*8'$ 0"#" 9,'0 $+(#,+.&3 68% (&!6;!D& !"!01%2*3 +<F%$#
0%)+(&#,"#%& #8% $,%"#'+( +- " $".$;."#%0 $+.;)(3 V( #8'& *",#'$;.", $"&%/ #8% &#,'(9 %>*,%&&'+(
0%C(%& " -+,);." #+ $+($"#%("#% #8% 7".;% +- #8% D%", $+.;)( A'#8 " &*"$% "(0 #8% 7".;% +-
#8% ?"B% $+.;)( #+ &8"*% A8"# #8'& $+.;)( $+(#"'(&3 100'(9 " $".$;."#%0 $+.;)( '& %&*%S
$'"..: <%(%C$'". A8%( 0"#" '& "7"'."<.% <;# (+# '( #8% $+,,%$# -+,)"#3
M+)% +- #8% !"!01%2*3 +<F%$#& A%,% $,%"#%0 A'#8+;# &*%$'-:'(9 7".;%& -+, ".. #8% *,+*S
%,#'%&3 68% 0%-";.# 7".;%& -+, #8% $+))+( *,+*%,#'%& ",% &8+A( '( 6"<.% ISI3
$",6%'(E(' !"!01%2*3 !%-";.#&
/5156789:;'#&F#%&$1 I%A"D6$'M"6D%
!"!#(8& !%-";.# '& #8% )"6.39 #:*%3
;!<=&39"> !%-";.# '& [I/ A8'$8 )%"(& #8"# (+ $8%$B -+, )">');)
.%(9#8 '& *%,-+,)%03
?3.@2& !%-";.# '& C!%)&/ A8'$8 "..+A& #8% %>'&#%($% +- 0;*.'$"#%
7".;%&3
A%%1/ B52%% !%-";.# '& "62&/ A8'$8 )%"(& #8% 0"#" $+.;)( 0+%& (+# (%%0
#+ 8"7% " 7".;%3 V- (+ 7".;% '& *,+7'0%0/ '#& 7".;% A'.. <%
B52%%3
0!8".13 !%-";.# '& #8% 01%2*35!*& *,+*%,#: 7".;% *"&&%0 '( #8%
$+(&#,;$#+,3
0:-2.(,@'M:(42:B'Y-B'0+1>4,)
68% *,')",: B%: +- " !"!#!$%& +<F%$# $+(&'&#& +- " $+.;)( +, $+.;)(& #8"# )"B% ;* " ;('R;%
'0%(#'#: -+, %"$8 0"#" ,+A3 V( #8% *,%7'+;& %>")*.%/ #8% 7%8'$.% '0%(#'C$"#'+( (;)<%, WQV4Z '&
$+(&'0%,%0 "& " ;('R;% B%: -,+) A8'$8 0"#" -+, " 9'7%( $", $"( <% ,%#,'%7%03 V( +#8%, &'#;"S
#'+(&/ 9%##'(9 " ;('R;% B%: )'98# ,%R;',% $+)<'('(9 #A+ +, )+,% C%.0&3 @+, %>")*.%/ " &".%&
+,0%, )'98# $+(#"'( &".%& +,0%, 0%#"'.& #8"# $+)*,'&% #8% '#%)& <%'(9 *;,$8"&%0 +( #8% &".%&
+,0%,3 68% *,')",: B%: -+, %"$8 +- #8% &".%& +,0%, 0%#"'. ,+A& )'98# <% #8% $+)<'("#'+( +-
#8% +,0%, (;)<%, "(0 #8% .'(% (;)<%,3 68% E6.*!6(F&( *,+*%,#: );&# <% &%# #+ "( ",,": +-
!"!01%2*3 +<F%$#& #+ "$$+))+0"#% $+)*+&'#% W);.#'*.%Z B%:&3 68% -+..+A'(9 $+0% &8+A&
8+A #+ &%# #8% E6.*!6(F&( *,+*%,#: -+, #8% 7!6) !"!#!$%& +<F%$#J
H%&&+( IJ K+,B'(9 A'#8 #8% !"!#!$%& "(0 !"!'&" E."&&%& !"#$%&'(' N
T2491-'+?'U()>21'V2)(*'0+/-
'Set the Primary Key
cars.PrimaryKey = new DataColumn(){vin}
T2491-'+?'0W'0+/-
//Set the Primary Key
cars.PrimaryKey = new DataColumn[] {vin};
Z)(,@' >.+42.(*'$>45-:(,@'?+:'.8-'M:(42:B'Y-B'0+1>4,
D+; $"( ".&+ 0%&'9("#% " $+.;)( '( :+;, #"<.% "& "( ";#+S'($,%)%(# $+.;)(3 68'& $+.S
;)( A'.. <% ";#+)"#'$"..: *+*;."#%0 A'#8 " (;)<%, #8"# A'.. <% #8% *,')",: B%:3 6+ &%# ;*
"( ";#+S '($,%)%(# $+.;)(/ &%# #8% A2"1:376&*&3" *,+*%,#: +- :+;, 0"#" $+.;)( #+ "62&3
1-#%, #8"#/ :+; &%# A2"1:376&*&3"'&&G #+ #8% 7".;% +- #8% C,&# (;)<%, :+; A"(# "(0 &%#
A2"1:376&*&3"'"&8 #+ #8% 7".;% :+; A"(# #+ '($,%)%(# <: %"$8 #')% " (%A ,+A '& "00%03
1;#+ '($,%)%(#'(9 '& -+;(0 '( )"(: 0"#"<"&% *,+0;$#&/ <;# 8+A $"( '# *+&&'<.: A+,B
*,+*%,.: '( :+;, "**.'$"#'+(\ 68% $+((%$#%0 $."&&%& 8"7%(T# <%%( $+7%,%0 :%#/ <;# :+; $"(
')"9'(% #8"# "# &+)% *+'(# :+; )'98# A"(# #+ &%(0 :+;, (%A 0"#" #+ " <"$BS%(0 0"#"<"&%3 V-
:+;, "**.'$"#'+( &;**.'%& #8% ";#+S'($,%)%(# 7".;%&/ A8"# A'.. #8% 0"#"<"&% 0+/ %&*%$'"..: '- '#
,%$%'7%& 0;*.'$"#% 7".;%& -,+) 0'--%,%(# $.'%(# "**.'$"#'+(&\
68% "(&A%, '& #8"# #8%&% ";#+S'($,%)%(# 7".;%& ",% (%7%, &%(# #+ #8% 0"#"<"&% <%$";&% #8%
";#+S'($,%)%(# $+.;)( '( #8% 0"#"<"&% #"<.% A'.. *,+7'0% " 7".;% A8%( #8% (%A ,+A '& "00%03
1-#%, %"$8 (%A ,+A '& "00%0/ #8% <"$BS%(0 0"#"<"&% #"<.% 9%(%,"#%& " (%A ";#+S'($,%)%(#
(;)<%,/ "(0 #8%( :+;, "**.'$"#'+( A'.. R;%,: #8% 0"#"<"&% #+ 9%# #8% (%A.: $,%"#%0 (;)<%,3
D+;, "**.'$"#'+( A'.. #8%( ;*0"#% '#& *,')",: B%: (;)<%, #+ #8% 7".;%& #8"# $")% -,+) #8%
0"#"<"&%3 68'& )%"(& #8"# ".. -+,%'9( B%: ,%-%,%($%& A'.. (%%0 #+ <% ;*0"#%0 "& A%..3
M+ A8"# 8"**%(& '- :+; "00 (%A ,+A& '( :+;, "**.'$"#'+( #+ 9%(%,"#% ";#+S'($,%)%(#
7".;%& +- I #+ I]] "(0 #8%( &%(0 #8%&% ,+A& <"$B #+ #8% 0"#"<"&% #"<.%/ "(0 #8% #"<.% ".,%"0:
8"& I] ,+A&\ K8%( #8% C,&# ,+A '& &%(# -,+) :+;, "**.'$"#'+(/ '# 8"& "( ";#+S'($,%)%(# 7".;%
+- I3 68% (%A ";#+S'($,%)%(# (;)<%, $,%"#%0 '( #8% 0"#"<"&% A'.. <% II3 D+;, "**.'$"#'+(
R;%,'%& -+, #8% II "(0 #,'%& #+ $8"(9% #8% I #+ "( II <;# #8,+A& "( %>$%*#'+( <%$";&% II '&
".,%"0: '( :+;, 0"#" #"<.%3
6+ &+.7% #8'& *,+<.%)/ &%# A2"1:376&*&3"'&&G #+ SI "(0 &%# A2"1:376&*&3"'"&8 #+ SI3 68'&
A'.. $";&% (%9"#'7% (;)<%,& #+ <% 9%(%,"#%0= #8%: A+(T# $+(^'$# A'#8 #8% 7".;%& $+)'(9 -,+)
#8% 0"#"<"&% <%$";&% #8% 0"#"<"&% 0+%&(T# 9%(%,"#% (%9"#'7% (;)<%,&3
!*"+$),-
X+:'.8-'-324E'/+,Q.'?+:@-.'.82.')-..(,@'.<2$ '04!4'2724"'2,/'.<2$ '0#4!4'27446'.+'IJ'G(11'
-,)>:-'.82.'B+>:',>45-:)'/+,Q.'*+,[(*.'G(.8'721>-)':-.:(-7-/'?:+4'.8-'/2.252)-')-:7-:E'
5-*2>)-'B+>'G(11'5-'\>-).(+,-/'+,'.8()#
' O !"#$%&'( 1!23456 !'&$+((%$#%0 E."&&%&
0:-2.(,@':121=$>'"56-*.)'.+']+1/'!2.2
1-#%, #8% !"!#!$%& +<F%$# '& $,%"#%0 "(0 $+(#"'(& !"!01%2*3 +<F%$#&/ :+; $"( *+*;."#% #8%
!"!#!$%& +<F%$# <: "00'(9 !"!41/ +<F%$#&3 1 !"!41/ +<F%$# $"( <% $,%"#%0 +(.: '( #8%
$+(#%># +- " 0"#" #"<.% <%$";&% #8% 0"#" ,+A );&# $+(-+,) #+ $+(&#,"'(#& +- #8% !"!#!$%&
+<F%$#T& $+.;)(&3
//(,@'!2.2'.+'.8-'!2.2'&251-
68% !"!#!$%& +<F%$# $+(#"'(& " 41/) *,+*%,#: +- #:*% !"!41/01%%&7".13 #8"# &#+,%&
!"!41/ +<F%$#&3 68%,% ",% &%7%,". A":& #+ '(&%,# 0"#" '(#+ #8'& $+..%$#'+(3
!"!41/01%%&7".13 8"& "( AGG )%#8+0 #8"# "$$%*#& " !"!41/ +<F%$#3 68% AGG )%#8+0
'& ".&+ +7%,.+"0%0 #+ "$$%*# "( ",,": +- +<F%$#& '(&#%"0 +- " !"!41/ +<F%$#3 V- "( ",,": +-
+<F%$#& '& *"&&%0 #+ #8% AGG )%#8+0/ #8% ",,": +<F%$# $+;(# );&# )"#$8 #8% %>"$# (;)<%, +-
!"!01%2*3 +<F%$#& #8% 0"#" #"<.% 8"&3
68% AGG )%#8+0 A+,B& A%.. A8%( :+; ",% $,%"#'(9 " (%A ,+A +- 0"#"3 V- :+; A"(# #+
')*+,# !"!41/ +<F%$#& #8"# 8"7% <%%( )+0'C%0/ :+; $"( ;&% #8% :*816" !"!41/ )%#8+0/
A8'$8 A'.. *,%&%,7% #8% +,'9'(".,&#"#% "(0 ".. +#8%, &%##'(9&3 68% !"!#!$%& $."&& ".&+ *,+7'0%&
&%7%,". +7%,.+"0%0 =1!G )%#8+0&/ A8'$8 $"( <% ;&%0 #+ ;*0"#% %>'&#'(9 !"!41/ +<F%$#& +,
.+"0 (%A !"!41/ +<F%$#&3 68% 0"#" #"<.% ,%R;',%& #8% E6.*!6(F&( *,+*%,#: #+ <% &%# &+ #8%
!"!#!$%& +<F%$# $"( .+$"#% #8% ,+A& #+ <% ;*0"#%03 V- :+; (%%0 #+ 9%(%,"#% " 0"#" ,+A/ :+;
$"( ;&% #8% =1!G !"!41/ )%#8+0/ A8'$8 "$$%*#& "( ",,": +- +<F%$#&/ "(0 " =1!GH8".13 %(;S
)%,"#'+( 7".;%3 68% *+&&'<.% 7".;%& -+, #8% =1!GH8".13 %(;)%,"#'+( ",% &8+A( '( 6"<.% ISL3
$",6%'(E+' =1!GH8".13 5(;)%,"#'+( ?%)<%,&
875/7<1=7;'H%H,%& I%J &B#$BFG
HI&6/6."&0>!39&) 27%,A,'#%& #8% +,'9'(". 0"#" ,+A 7%,&'+( "(0 #8% $;,,%(#
0"#" ,+A 7%,&'+( "(0 $8"(9%& #8% ,+A &#"#% #+ ?37>!39&G3
4%A ,+A& A'.. 8"7% " ,+A &#"#% +- ?37>!39&G "& A%..3
E6&)&6I&0>!39&),W0%-";.#Z 27%,A,'#%& #8% +,'9'(". 0"#" ,+A 7%,&'+( <;# 0+%& (+#
)+0'-: #8% $;,,%(# 0"#" ,+A 7%,&'+(3 4%A ,+A& A'.. 8"7% "
,+A &#"#% +- ?37>!39&G "& A%..3
?8)&6" 27%,A,'#%& #8% $;,,%(# 0"#" ,+A 7%,&'+( <;# 0+%& (+# )+0S
'-: #8% +,'9'(". 0"#" ,+A 7%,&'+(3 4%A ,+A& A'.. 8"7% " ,+A
&#"#% +- AGG&G3 _+A& #8"# 8"0 " ,+A &#"#% +- ?37>!39&G
A'.. 8"7% " ,+A &#"#% +- ?37>!39&G '- #8% $;,,%(# 0"#" ,+A
7%,&'+( '& #8% &")% "& #8% +,'9'(". 0"#" ,+A 7%,&'+(/ <;# '-
#8%: ",% 0'--%,%(#/ #8% ,+A &#"#% A'.. <% ;1G.J&G3
68% -+..+A'(9 $+0% &")*.% 0%)+(&#,"#%& #8% )%#8+0& +- $,%"#'(9 "(0 "00'(9 0"#" '(#+
#8% 7!6) !"!#!$%& +<F%$#J
H%&&+( IJ K+,B'(9 A'#8 #8% !"!#!$%& "(0 !"!'&" E."&&%& !"#$%&'(' P
T2491-'+?'U()>21'V2)(*'0+/-
'Add new DataRow by creating the DataRow first
Dim newCar As DataRow = cars.NewRow()
newCar ("Vin") = "123456789ABCD "
newCar ("Make") = "Ford"
newCar ("Year") = 2002
cars.Rows.Add(newCar)
'Add new DataRow by simply passing the values
cars.Rows.Add("987654321XYZ", "Buick", 2001)
'Load DataRow, replacing existing contents, if existing
cars.LoadDataRow(new object() _
{ "987654321XYZ", "Jeep", 2002 },LoadOption.OverwriteChanges)
T2491-'+?'0W'0+/-
//Add New DataRow by creating the DataRow first
DataRow newCar = cars.NewRow();
newCar ["Vin"] = "123456789ABCD";
newCar ["Make"] = "Ford";
newCar ["Year"] = 2002;
cars.Rows.Add(newCar);
//Add New DataRow by simply adding the values
cars.Rows.Add("987654321XYZ", "Buick", 2001);
//Load DataRow, replacing existing contents, if existing
cars.LoadDataRow(new object[]
{ "987654321XYZ", "Jeep", 2002 },LoadOption.OverwriteChanges);
68'& $+0% "00& (%A !"!41/ +<F%$#& #+ #8% 7!6) 0"#" #"<.%3 68% C,&# %>")*.% %>*.'$'#.:
$,%"#%& " (%A 0"#" ,+A/ ;&'(9 #8% 5&/41/ )%#8+0 +( #8% 7!6) 0"#" #"<.%3 68% (%># %>")*.%
"00& " (%A 0"#" ,+A <: &')*.: *"&&'(9 #8% 7".;%& #+ #8% 7!6)+41/)+AGG )%#8+03 _%)%)<%,
#8"# (+#8'(9 8"& <%%( *%,)"(%(#.: &#+,%0 #+ " 0"#"<"&%3 M%(0'(9 ;*0"#%& #+ " 0"#"<"&% A'..
<% $+7%,%0 '( E8"*#%, L/ X1!23456 E+((%$#%0 E."&&%&3Y
U(-G(,@'.8-'T.2.-'+?'.8-':121=$>'"56-*.'5B'Z)(,@':121=$>72124
!"!41/ 9+%& #8,+;98 " &%,'%& +- &#"#%& #8"# $"( <% 7'%A%0 "(0 C.#%,%0 "# "(: #')%3 D+; $"(
,%#,'%7% #8% $;,,%(# &#"#% +- " 0"#" ,+A -,+) '#& 41/'"!"& *,+*%,#:/ A8'$8 ,%#;,(& " 7".;% -,+)
#8% !"!41/'"!"& %(;)%,"#'+(3 68% !"!41/'"!"& 7".;%& ",% 0%&$,'<%0 '( 6"<.% IS`3
$",6%'(E)' 41/'"!"& 5(;)%,"#'+( ?%)<%,&
>7?4151@'M"6D% I%J &B#$BFG
&"!7>&G 68% 0"#" ,+A 8"& <%%( $,%"#%0 <;# (+# "00%0 #+ " 0"#" #"<.%3
AGG&G 68% 0"#" ,+A 8"& <%%( $,%"#%0 "(0 "00%0 #+ #8% 0"#" #"<.%3
'(Q !"#$%&'( 1!23456 !'&$+((%$#%0 E."&&%&
?37>!39&G 68% 0"#" ,+A 8"& (+# $8"(9%0 &'($% #8% ."&# $".. #+ #8%
A77&8"0>!39&) )%#8+03 K8%( #8% A77&8"0>!39&) )%#8+0 '&
$"..%0/ #8% 0"#" ,+A $8"(9%& #+ #8'& &#"#%3
;1G.J&G 68% 0"#" ,+A 8"& <%%( )+0'C%0 &'($% #8% ."&# #')% #8%
A77&8"0>!39&) )%#8+0 A"& $"..%03 100'(9 " ,+A "(0 )+0'-:'(9
#8% ,+A A'.. B%%* #8% ,+A '( #8% AGG&G &#"#%3 68% ,+A $8"(9%& #+
#8% ;1G.J&G &#"#% +(.: '- '# A"& *,%7'+;&.: '( #8% ?37>!39&G &#"#%3
&%&"&G 1( "##"$8%0 0"#" ,+A '& 0%.%#%0 <: ;&'(9 #8% &%&"& )%#8+0 +- #8%
!"!41/ +<F%$# +, A8%( '# '& ,%)+7%0 -,+) '#& #"<.% <: $"..'(9 #8%
!"!#!$%&+ &%&"&41/ )%#8+03
D+; $"( ,%"0 #8% 41/'"!"& *,+*%,#: +- #8% 0"#" ,+A "# "(: #')% #+ 0%#%,)'(% #8% $;,S
,%(# &#"#% +- #8% 0"#" ,+A3 @'9;,% ISL &8+A& #8% 41/'"!"& #,"(&'#'+(& "# 0'--%,%(# #')%& '( #8%
!"!41/ +<F%$#T& .'-%3
Dim dr as DataRow = dt.NewRow( )
dt.Rows.Add(dr)
dr("CustomerID")="AAAA"
dt.RejectChanges( )
dt.Rows.Add(dr)
dt.AcceptChanges( )
dr("CustomerID")=“BBBB"
dt.AcceptChanges( )
dr("CustomerID")="ZZZZ"
dt.RejectChanges ( )
RowState = Detached
RowState = Unchanged
RowState = Unchanged
RowState = Unchanged
dr.Delete ( )
dt.RejectChanges
RowState = Added
RowState = Added
RowState = Detached
RowState = Added
RowState = Modified
RowState = Modified
RowState = Deleted
RowState = Unchanged
Back toempty row
Back to“BBBB”
!"#$%&'()& !"#$%$& !" "#$%& '" !( )#'&*+" ,-.!&* (#+ /!0+(!1+ $0 ' '%$% !" $23+)(4
50(+. (#+ 6-"($1+.78 !" '""!*&+, ' 9'/-+ $0 :5555;< (#+ .$% "('(+ ,$+" &$( )#'&*+ ($
(!)*+&)4 =#+ .$% "('(+ !" "(!// ,))&) 2+)'-"+ !"#$%$& !" '& !&,!)'($. $0 '& ')(!$& .+>-!.+,
($ "+&, '& -?,'(+ $0 (#!" ,'(' ($ (#+ ,'('2'"+4 =#+ 0')( (#'( :5555< %'" ?/')+, !&($ (#+
6-"($1+.78 !" &$( '" !1?$.('&( '" (#+ 0')( (#'( (#+ ,'(' .$% &++," ($ 2+ ',,+, ($ (#+
,'('2'"+4
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& ''
!"!#$"#% &'($)'*%+,)$*-%,.%/!(!%01%2-$"#% !"!#$%&'()*$+
=#+ '%$%-%./& $23+)( )'& #$/, -? ($ (#.++ 9+."!$&" $0 (#+ ,'(' .$% ,'('B 01*2*3%/; 4511&3$;
'&, 61!7!8&)4 C#+& (#+ ,'(' .$% !" /$',+,; !( )$&('!&" ' "!&*/+ )$?E $0 (#+ ,'('4 5( (#'( (!1+;
$&/E (#+ 4511&3$ 9+."!$& +F!"("4 G$- 1!*#( 2+ %$&,+.!&* %#E E$- #'9+ $&/E (#+ 4511&3$ 9+.H
"!$& '&, &$( (#+ 01*2*3%/ 9+."!$&B 01*2*3%/ !1?/!+" (#'( (#+ .$% #'" 2++& 1$,!I+,4 JF+)-(!&*
(#+ 9&2*3:)*$ 1+(#$, %!// ?/')+ (#+ .$% !&($ +,!( 1$,+; '&, )#'&*+" ($ (#+ ,'(' '.+ ?/')+,
!&($ ' "+)$&, !&"('&)+ $0 (#+ ,'('; )'//+, (#+ 61!7!8&) 9+."!$&4 C#+& (#+ :3):)*$ 1+(#$, !"
+F+)-(+,; (#+ 4511&3$ 9+."!$& 2+)$1+" (#+ 01*2*3%/ 9+."!$&; (#+ 61!7!8&) 9+."!$& 2+)$1+"
(#+ 4511&3$ 9+."!$&; '&, (#+ 61!7!8&) 9+."!$& &$ /$&*+. +F!"("4 50(+. :3):)*$ !" )'//+,; (#+.+
'.+ (%$ !&"('&)+" $0 (#+ '%$% !" ,'('; (#+ 01*2*3%/ '&, (#+ 4511&3$ 9+."!$&"4 70 (#+ 9&2*3:)*$
1+(#$, !" )'//+, '*'!&; (#+ 4511&3$ 9+."!$& $0 (#+ ,'(' !" )$?!+, ($ ' (#!., !&"('&)+ $0 (#+
,'('; %#!)# !" (#+ 61!7!8&) 9+."!$&4 K&)+ '*'!&; )'//!&* (#+ :3):)*$ 1+(#$, )'-"+" (#+
61!7!8&) 9+."!$& ($ 2+)$1+ (#+ 4511&3$ 9+."!$&; '&, (#+ 61!7!8&) 9+."!$& &$ /$&*+. +F!"("4
L$(!)+ (#'( (#+ 01*2*3%/ 9+."!$& !" &$( )#'&*+,4
C#+& E$- .+(.!+9+ ,'(' 0.$1 (#+ ,'(' .$% $& ' ?+.H)$/-1& 2'"!"; (#+ ,'(' .$% 9+."!$& )'&
2+ "?+)!I+, '" %+//4 ='2/+ AHM ,+").!2+" (#+ '%$% !";&18*!3 +&-1+.'(!$& 1+12+." E$- )'&
"?+)!0E4
.,/0%&'(1&'%$% !";&18*!3 J&-1+.'(!$& N+12+."
!"!#$%&'#()$*&2,0#% 3%4*$!-.!56
4511&3$ =#+ )-..+&( 9'/-+ $0 (#+ ,'(' .$%; +9+& '0(+. )#'&*+" #'9+
2++& 1',+4 =#!" 9+."!$& +F!"(" !& '// "!(-'(!$&" +F)+?( %#+&
'%$% !"#$%$& !" '&/&$&)4 70 '%$% !"#$%$& !" '&/&$&); '& +FH
)+?(!$& !" (#.$%&4
'&<%5/$ 70 '%$% !"#$%$& !" ,))&) $. (!)*+&); (#+ ,+0'-/( 9+."!$& !"
4511&3$4 70 '%$% !"#$%$& !" '&/&$&); '& +F)+?(!$& !" (#.$%&4
70 (#+ 9&2*3:)*$ 1+(#$, #'" 2++& +F+)-(+,; (#+ 9+."!$& !"
61!7!8&)4
01*2*3%/ =#+ 9'/-+ (#'( %'" $.!*!&'//E /$',+, !&($ (#+ ,'(' .$% $.
(#+ 9'/-+ '( (#+ (!1+ (#+ /'"( ,==&7$4>%32&8 1+(#$, %'"
+F+)-(+,4 =#!" 9+."!$& !" &$( ?$?-/'(+, -&(!/ '%$% !"#$%$&
2+)$1+" (!)*+&); ?3=>%32&); $. '&/&$&)4 70 '%$% !"#$%$&
!" '&/&$&); (#!" !&0$.1'(!$& !" .+(.!+9'2/+4 70 '%$% !"#$%$& !"
,))&); ' ;&18*!3@!$A!53) +F)+?(!$& !" (#.$%&4
61!7!8&) =#+ 9'/-+ '( (#+ (!1+ $0 +,!(!&* (#+ ,'(' .$%4 70 '%$% !"#$%$&
!" '&/&$&); '& +F)+?(!$& !" (#.$%&4 70 (#+ 9&2*3:)*$ 1+(#$,
#'" &$( 2++& +F?/!)!(/E +F+)-(+,; $. !0 9&2*3:)*$ %'" !1?/!)H
!(/E +F+)-(+, 2E +,!(!&* ' ,+(')#+, ,'(' .$% O'& $.?#'&+,
'%$% !" $23+)( (#'( #'" &$( 2++& ',,+, ($ ' '%$%-%./&
$23+)(P; ' ;&18*!3@!$A!53) +F)+?(!$& !" (#.$%&4
&') *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
'%$% !" )$&('!&" (#+ B%8;&18*!3 1+(#$, (#'( )'& >-+.E 0$. (#+ +F!"(+&)+ $0 ' ?'.(!)-/'.
,'(' .$% 9+."!$&4 Q"!&* (#+ B%8;&18*!3 1+(#$,; E$- )'& )#+)D 0$. (#+ +F!"(+&)+ $0 ' ,'(' .$%
9+."!$& 2+0$.+ '((+1?(!&* ($ .+(.!+9+ !(4 =#+ 0$//$%!&* )$,+ "'1?/+ ,+1$&"(.'(+" #$% ($ .+H
(.!+9+ ' "(.!&*; -"!&* !"#$%$& '&, '%$% !";&18*!34 =#!" "'1?/+ -"+" (#+ B%8;&18*!3 1+(#$,
($ I*-.+ $-( (#+ ,'(' .$% 9+."!$& !&0$.1'(!$& %!(#$-( (#.$%!&* '& +F)+?(!$&4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Private Function GetDataRowInfo( _
ByVal row As DataRow, ByVal columnName As String) _
As String
Dim retVal As String = String.Format( _
"RowState: {0}" + vbCrLf
Dim versionString As String
For Each versionString In [Enum].GetNames(GetType(DataRowVersion))
Dim version As DataRowVersion = _
CType([Enum].Parse(GetType(DataRowVersion), versionString), _
DataRowVersion)
If (row.HasVersion(version)) Then
retVal += String.Format( _
"Version: {0} Value: {1}" + vbCrLf, _
version, row(columnName, version))
Else
retVal += String.Format( _
"Version: {0} does not exist." + VbCrLf, _
version)
End If
Next
Return retVal
End Function
3!4)'*%,.%+9%+,8*
private string GetDataRowInfo(DataRow row, string columnName)
{
string retVal=string.Format(
"RowState: {0} \r\n",
row.RowState);
foreach (string versionString in Enum.GetNames(typeof (DataRowVersion)))
{
DataRowVersion version = (
DataRowVersion)Enum.Parse(
typeof(DataRowVersion),versionString);
if (row.HasVersion(version))
{
retVal += string.Format(
"Version: {0} Value: {1} \r\n",
version, row[columnName, version]);
}
else
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& '7
{
retVal += string.Format(
"Version: {0} does not exist.\r\n",
version);
}
}
return retVal;
}
:*-*(($"#%(;*%3(!(*%01%2-$"#%(;*%,--'."/0!+1')%!"8%#'2'-"/0!+1')% *(;,8-
G$- )'& -"+ (#+ ,==&7$4>%32&8 1+(#$, ($ .+"+( (#+ '%$% !" "('(+ ($ ?3=>%32&)4 =#!"
1+(#$, +F!"(" $& (#+ '%$% !"; '%$%-%./&; '&, '%$%#&$ $23+)("4 O=#!" )#'?(+. )$9+." (#+
'%$%#&$ $23+)( /'(+.; !& (#+ "+)(!$& (!(/+,; :Q"!&* ' '%$%#&$ K23+)( ($ 6$$.,!&'(+ C$.D 2+H
(%++& 8'(' ='2/+"4<P 7& ' (E?!)'/ ,'(' +&9!.$&1+&( O'0(+. ,'(' #'" 2++& /$',+,P; (#+ '%$% !"
"('(+ $0 (#+ /$',+, .$%" !" "+( ($ ,))&)4 6'//!&* ,==&7$4>%32&8 $& (#+ ,'(' ('2/+ .+"+(" (#+
.$% "('(+ $0 '// (#+ '%$% !" $23+)(" ($ ?3=>%32&)4 L+F(; !0 E$- 1$,!0E (#+ '%$% !" $23+)(";
(#+!. .$% "('(+ )#'&*+" ($ (!)*+&)4 C#+& !( !" (!1+ ($ "'9+ (#+ ,'('; E$- )'& +'"!/E >-+.E
(#+ '%$%-%./& $23+)( 0$. !(" )#'&*+" 2E -"!&* (#+ '%$%-%./& $23+)(R" C&$4>%32&8 1+(#$,4
=#!" 1+(#$, .+(-.&" ' '%$%-%./& $23+)( ?$?-/'(+, %!(# $&/E (#+ '%$% !" $23+)(" (#'( #'9+
)#'&*+, "!&)+ (#+ /'"( (!1+ ,==&7$4>%32&8 %'" +F+)-(+,4 K&/E (#+"+ )#'&*+" &++, ($ 2+ "+&(
($ (#+ ,'(' "($.+4
50(+. (#+ )#'&*+" #'9+ 2++& "-))+""0-//E "+&( ($ (#+ ,'(' "($.+; E$- 1-"( )#'&*+ (#+ "('(+
$0 (#+ '%$% !" $23+)(" ($ ?3=>%32&); %#!)# +""+&(!'//E !&,!)'(+" (#'( (#+ '%$% !" $23+)("
'.+ "E&)#.$&!S+, %!(# (#+ ,'(' "($.+4 G$- -"+ (#+ ,==&7$4>%32&8 1+(#$, 0$. (#!" ?-.?$"+4
L$(+ (#'( +F+)-(!&* (#+ ,==&7$4>%32&8 1+(#$, '/"$ )'-"+" (#+ '%$% !" $23+)(R" 4511&3$
,'(' .$% 9+."!$& ($ 2+ )$?!+, ($ (#+ '%$% !" $23+)(R" 01*2*3%/ 9+."!$&4
!"#& 3568.& 5$"%.&.5&*,00&,**%-.*+,6"%4
:*4*40*<%(;!(%$(%$-%$4),<(!"(%(,%7!''%(;*%,--'."/0!+1')%4*(;,8%!.(*<%1,&%;!=*%4!8*%!%
-&77*--.&'%&)8!(*%(,%(;*%8!(!0!-*%-*<=*<%0*7!&-*%(;*%,--'."/0!+1')%4*(;,8%4!<>-%!''%
<,?-%!-%3+-0!+1'4@%A;1B%6*7!&-*%(;*%<,?-%!<*%",?%-1"7;<,"$C*8%?$(;%(;*%<,?-%!(%(;*%
8!(!0!-*%-*<=*<@
=#+ &D&=$4>%32&8 1+(#$, .$//" '%$%-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( ,'(' "($.+; E$- +F+)-(+ (#+ #&$,))&) 1+(#$, ($
1'D+ (#+ .$% /$$D /!D+ ' &+% .$%4 7& 6#'?(+. U; E$- /+'.& (#'( (#+ '%$%,)%7$&1 $23+)( "+&,"
)#'&*+" ($ (#+ ,'(' "($.+4 C#+& E$- )$&&+)( ($ (#+ ,+"(!&'(!$& ,'(' "($.+; (#+ ,'(' ','?(+.
$23+)( "++" (#'( E$-. .$% #'" '& ,))&) .$% "('(+; "$ (#+ ,'(' ','?(+. $23+)( +F+)-(+" '&
!&"+.( "('(+1+&( ($ ',, (#+ .$% ($ (#+ ,+"(!&'(!$& ,'(' "($.+4
=#+"+ 1+(#$," )'& 2+ +F+)-(+, $&/E $& '%$% !" $23+)(" %#$"+ .$% "('(+ !" ?3=>%32&)4
5& '((+1?( ($ +F+)-(+ (#+"+ 1+(#$," $& ' '%$% !" $23+)( %!(# ' ,!00+.+&( .$% "('(+ (#.$%"
(#+ +F)+?(!$& )'//+, E3F%/*)07&1%$*!3:G=&7$*!34
70 (#+ #&$,))&) 1+(#$, !" +F+)-(+,; (#+ '%$% !" $23+)( ,!")'.," !(" 01*2*3%/ ,'(' .$% 9+.H
"!$& 2+)'-"+ '%$% !" $23+)(" (#'( #'9+ ' .$% "('(+ $0 ,))&) &+9+. )$&('!& '& 01*2*3%/ ,'('
.$% 9+."!$&4
70 (#+ #&$(!)*+&) 1+(#$, !" +F+)-(+,; (#+ '%$% !" $23+)(R" !"#$%$& ?.$?+.(E !" "!1?/E
)#'&*+, ($ (!)*+&) %!(#$-( 1$,!0E!&* (#+ 01*2*3%/ $. 4511&3$ ,'(' .$% 9+."!$&4
/*'*($"#%(;*%/!(!%:,?D%!"8%A;!(%E0,&(%2"8*'*($"#B
'%$% !" )$&('!&" ' '&/&$& 1+(#$, %!(# %#!)# E$- )'& "+( (#+ .$% "('(+ $0 (#+ ,'(' .$%
($ '&/&$&)4 '%$% !" $23+)(" (#'( #'9+ ' .$% "('(+ $0 '&/&$&) !&,!)'(+ .$%" (#'( &++, ($ 2+
,+/+(+, 0.$1 (#+ ,'(' "($.+4 C#+& (#+ '%$% !" $23+)( !" ,+/+(+,; (#+ 4511&3$ '&, 61!7!8&)
,'(' .$% 9+."!$&" '.+ ,!")'.,+,; 2-( (#+ 01*2*3%/ ,'(' .$% 9+."!$& .+1'!&"4
V$1+(!1+" E$- &++, ($ .+)$9+. ' ,+/+(+, ,'(' .$%4 =#+ '%$% !" $23+)( ,$+"&R( #'9+ '&
?3)&/&$& 1+(#$,4 W$%+9+.; !& "$1+ "!(-'(!$&"; E$- )'& -"+ (#+ &D&=$4>%32&8 1+(#$, ($ .$//
2')D ($ ' ?.+9!$-" "('(+ %#+& (#+ ,+/+(+, .$% %'" "(!// (#+.+4 X+ '%'.+ (#'( +F+)-(!&* (#+
&D&=$4>%32&8 1+(#$, )$?!+" (#+ 01*2*3%/ ,'(' .$% 9+."!$& ($ (#+ 4511&3$ ,'(' .$% 9+."!$&4
=#!" +00+)(!9+/E .+"($.+" (#+ '%$% !" $23+)( ($ !(" "('(+ '( (#+ (!1+ (#+ /'"( ,==&7$4>%32&8
1+(#$, %'" +F+)-(+,; 2-( '&E "-2"+>-+&( )#'&*+" (#'( %+.+ 1',+ ($ (#+ ,'(' ?.!$. ($ ,+H
/+(!&* #'9+ 2++& ,!")'.,+,4
F"&4*<!($"#%(;*%/!(!%G!0'*
7( !" ?$""!2/+ ($ /$$? (#.$-*# (#+ .$%" '&, )$/-1&" $0 (#+ ,'(' ('2/+ 2E -"!&* ' <!1&%=>
"('(+1+&(4 =#+ 0$//$%!&* )$,+ "#$%" #$% (#+ .$%" '&, )$/-1&" $0 ' ,'(' ('2/+ )'& 2+
+&-1+.'(+,4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Public Sub EnumerateTable(ByVal cars As DataTable)
'enumerate the data table
Dim buffer As New System.Text.StringBuilder()
For Each dc As DataColumn In cars.Columns
buffer.AppendFormat("{0,15} ", dc.ColumnName)
Next
buffer.Append(vbCrLf)
For Each dr As DataRow In dt.Rows
If (dr.RowState = DataRowState.Deleted) Then
buffer.Append("Deleted Row")
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& '9
Else
For Each dc As DataColumn In cars.Columns
buffer.AppendFormat("{0,15} ", dr(dc))
Next
End If
buffer.Append(vbCrLf)
Next
TextBox1.Text = buffer.ToString()
End Sub
3!4)'*%,.%+9%+,8*
public void EnumerateTable(DataTable cars)
{
var buffer = new System.Text.StringBuilder();
foreach (DataColumn dc in cars.Columns)
{
buffer.AppendFormat("{0,15} ", dc.ColumnName);
}
buffer.Append("\r\n");
foreach (DataRow dr in cars.Rows)
{
if (dr.RowState == DataRowState.Deleted)
{
buffer.Append("Deleted Row");
}
else
{
foreach (DataColumn dc in cars.Columns)
{
buffer.AppendFormat("{0,15} ", dr[dc]);
}
}
buffer.Append("\r\n");
}
textBox1.Text = buffer.ToString();
}
=#+ )$,+ 2+*!&" 2E "!1?/E )$//+)(!&* (#+ )$/-1& &'1+" ($ -"+ '" ' #+',+. '&, ?/')+" (#!"
!&0$.1'(!$& !& (#+ #$1*3295*/)&1 $23+)(; )'//+, .5<<&14 L+F(; (#+ ('2/+ .$%" '&, )$/-1&" '.+
+&-1+.'(+,; '&, '// 9'/-+" '.+ ?/')+, !&($ (#+ 2-00+.4 6$,+ "-)# '" (#!" )'& 2+ -"+, ($ %'/D
(#.$-*# (#+ .$%" !& ' ,'(' ('2/+ '&, ?+.0$.1 '& ')(!$& $& '// (#+ ,'('4 T!*-.+ AHY "#$%" (#+
$-(?-( $0 (#!" )$,+4 O=#+ -&G$9!G 0$&( !" "+( ($ 6$-.!+. L+% ($ *+( (#+ )$/-1&" ($ /!&+ -?4P
!"#$%&'(7& V#$%& #+.+ !" (#+ $-(?-( %#+& +&-1+.'(!&* (#+ '%$%-%./& $23+)(R" )$/-1&" #+',+." '&, .$%"4
&': *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
+,)1$"#%!"8%+',"$"#%(;*%/!(!%G!0'*
V$1+(!1+" E$- %'&( ($ ).+'(+ ' 0-// )$?E $0 ' ,'(' ('2/+4 G$- )'& ,$ (#!" 2E -"!&* (#+
'%$%-%./& $23+)(R" 4!7H 1+(#$,; %#!)# )$?!+" (#+ '%$%-%./& $23+)(R" ")#+1' '&, ,'('4 =#+
0$//$%!&* )$,+ "'1?/+ "#$%" #$% ($ !&9$D+ (#+ 4!7H 1+(#$,4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
'copy the table and its data
Dim copy As DataTable = cars.Copy()
3!4)'*%,.%+9%+,8*
//copy the table and its data
DataTable copy = cars.Copy( );
K& "$1+ $))'"!$&"; E$- 1!*#( &++, ' )$?E $0 (#+ '%$%-%./& ")#+1' %!(#$-( ,'('4 =$
)$?E 3-"( (#+ ")#+1' %!(#$-( ,'('; E$- )'& !&9$D+ (#+ '%$%-%./& $23+)(R" 4/!3& 1+(#$,4 =#!"
1+(#$, !" )$11$&/E -"+, %#+& '& +1?(E )$?E $0 (#+ ,'(' ('2/+ !" .+>-!.+,Z '( ' /'(+. (!1+;
'%$% !" $23+)(" )'& 2+ ',,+,4 =#+ 0$//$%!&* )$,+ "#$%" (#+ 4/!3& 1+(#$,4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
'only copy the table, not the data
Dim clone As DataTable = cars.Clone()
3!4)'*%,.%+9%+,8*
//only copy the table, not the data
DataTable clone = cars.Clone( );
H4),<($"#% !"!#$%%I0J*7(-%$"(,%!%/!(!%G!0'*
50(+. )/$&!&* ' ,'(' ('2/+; E$- 1!*#( &++, ($ )$?E )+.('!& '%$% !" $23+)(" 0.$1 $&+ ,'('
('2/+ ($ '&$(#+.4 '%$%-%./& )$&('!&" '& EI7!1$ !" 1+(#$,; %#!)# E$- )'& -"+ ($ )$?E ' ,'('
.$% 0.$1 ' ,'(' ('2/+ (#'( #'" (#+ "'1+ ")#+1'4 =#+ EI7!1$ !" 1+(#$, !" -"+0-/ %#+& (#+
4511&3$ '&, 01*2*3%/ ,'(' .$% 9+."!$& 1-"( 2+ 1'!&('!&+,4 T$. +F'1?/+; '0(+. +,!(!&* ' ,'('
('2/+; E$- 1!*#( %'&( ($ )$?E (#+ )#'&*+, '%$% !" $23+)(" ($ ' ,!00+.+&( ,'(' ('2/+ 2-(
1'!&('!& (#+ 01*2*3%/ '&, 4511&3$ ,'(' .$% 9+."!$&4 =#+ EI7!1$ !" 1+(#$, $& (#+ '%$%-%./&
$23+)( %!// !1?$.( (#+ '%$% !" $23+)(" '" /$&* '" ' ,'(' .$% %!(# (#+ "'1+ ?.!1'.E D+E ,$+"
&$( +F!"(4 O70 ' ,-?/!)'(+ ,'(' .$% +F!"("; ' 4!38$1%*3$:G=&7$*!3 !" (#.$%&4P =#+ 0$//$%!&* )$,+
"'1?/+ "#$%" (#+ ?.$)+"" 0$. )/$&!&* (#+ ,'(' ('2/+ '&, (#+& )$?E!&* ' "!&*/+ ,'(' .$% ($
(#+ )/$&+, )$?E4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Dim clone as DataTable = cars.Clone( )
'import the row and include all row versions
clone.ImportRow(cars.Rows(0))
3!4)'*%,.%+9%+,8*
DataTable clone = cars.Clone();
//import the row and include all row versions
clone.ImportRow(cars.Rows[0]);
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& ';
2-$"#% !"!&*'%%!-%!%A$"8,?%$"(,%!%/!(!%G!0'*=#+ '%$%;*&" $23+)( ?.$9!,+" ' %!&,$% !&($ ' ,'(' ('2/+ (#'( )'& 2+ "$.(+, '&, I/(+.+,4
5 ,'(' ('2/+ )'& #'9+ 1'&E '%$%;*&" $23+)(" '""!*&+, ($ !(; "$ (#+ ,'(' )'& 2+ 9!+%+, !&
1'&E %'E" %!(#$-( .+>-!.!&* !( ($ 2+ .+.+', 0.$1 (#+ ,'('2'"+4 =#+ #!1$; !"A*/$&1; '&,
!"#$%$&A*/$&1 ?.$?+.(!+" $& (#+ '%$%;*&" $23+)( )'& 2+ )$12!&+, '" &++,+,4 G$- )'& -"+
(#+ '%$%;*&" $23+)(R" ,//!"'&/&$&; ,//!":)*$; '&, ,//!"@&" ?.$?+.(!+" ($ )$&"(.'!& -"+.
!&?-(4
7&(+.&'//E; (#+ '%$%;*&" $23+)( !" +""+&(!'//E '& !&,+F4 G$- )'& ?.$9!,+ ' "$.( ,+I&!(!$& ($
"$.( (#+ !&,+F !& ' )+.('!& $.,+.; '&, E$- )'& ?.$9!,+ ' I/(+. ($ "!1?/E I/(+. (#+ !&,+F +&(.!+"4
I<8*<$"#%/!(!%2-$"#%(;*%5$("%K<,)*<(1
=#+ #!1$ ?.$?+.(E .+>-!.+" ' "$.( +F?.+""!$&4 =#+ ,+0'-/( $.,+. 0$. (#+ "$.( !" '")+&,!&*; 2-(
E$- )'& "?+)!0E 5V6 $. 8JV6 %!(# ' )$11'H"+?'.'(+, /!"( $0 )$/-1&" ($ 2+ "$.(+,4 =#+ 0$/H
/$%!&* )$,+ "'1?/+ "#$%" #$% ' ,'(' 9!+% !" ).+'(+, $& (#+ =%18 ,'(' ('2/+ %!(# ' )$1H
?$-&, "$.( $& (#+ N'D+ )$/-1& !& '")+&,!&* $.,+. '&, $& (#+ G+'. )$/-1& !& ,+")+&,!&*
$.,+.4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Dim view as new DataView(cars)
view.Sort = "Make ASC, Year DESC"
3!4)'*%,.%+9%+,8*
DataView view = new DataView(cars);
view.Sort = "Make ASC, Year DESC";
L!<<,?$"#%(;*%3*!<7;%01%2-$"#%(;*%#$%8*9"'(%!"8%#$%5"!"'8*9"'(%K<,)*<($*-
5 9!+% +F?$"+" ' !"A*/$&1 ?.$?+.(E '&, ' !"#$%$&A*/$&1 ?.$?+.(E4 =#+ !"A*/$&1 ?.$?+.(E !"
"+( ($ ' V[@ CWJ\J )/'-"+ %!(#$-( (#+ %$., :CWJ\J<4 =#+ 0$//$%!&* )$,+ "#$%" ' I/(+. $&
(#+ N'D+ )$/-1& 0$. )'." 2+*!&&!&* %!(# (#+ /+((+. X '&, $& (#+ G+'. )$/-1& 0$. )'." &+%+.
(#'& U]]Y4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Dim view as new DataView(cars)
view.RowFilter = "Make like 'B%' and Year > 2003"
3!4)'*%,.%+9%+,8*
DataView view = new DataView(cars);
view.RowFilter = "Make like 'B%' and Year > 2003";
=#+ !"#$%$&A*/$&1 ?.$?+.(E ?.$9!,+" ' I/(+. (#'( '??/!+" $& (#+ !"#$%$& ?.$?+.(E $.
$& +')# ,'(' .$%4 =#!" I/(+. ?.$9!,+" '& +'"E 1+(#$, $0 .+(.!+9!&* "?+)!I) 9+."!$&" $0 .$%"
%!(#!& (#+ ,'(' ('2/+4 =#+ !"#$%$&A*/$&1 ?.$?+.(E .+>-!.+" (#+ -"+ $0 '%$%;*&" !"#$%$&
+&-1+.'(!$& 9'/-+"; %#!)# '.+ "#$%& !& ='2/+ AH^4 =#+ '%$%;*&" !"#$%$& +&-1+.'(!$& !" '
&'< *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
2!(H_'* +&-1+.'(!$&; %#!)# 1+'&" E$- )'& -"+ (#+ 2!(%!"+ K\ $?+.'($. O(#'( !"; `P ($ 2-!/,
)$1?$-&, I/(+."4 T$. +F'1?/+; (#+ ,+0'-/( !"#$%$& I/(+. 9'/-+ !" "+( ($ ,!"?/'E 1-/(!?/+
"('(+" 2E -"!&* ` ($ )$12!&+ (#+ ?3=>%32&); ,))&); '&, (!)*+&)4511&3$ +&-1+.'(!$& 9'/-+"4
L$(+ (#'( (#!" )$12!&'(!$& !" "$ -"+0-/ (#'( ' ,+,!)'(+, 9'/-+ #'" 2++& ,+I&+, !& (#+ +&-H
1+.'(!$&B 4511&3$ !"84
.,/0%&'(9&'%$%;*&" !"#$%$& J&-1+.'(!$& N+12+."
!"!&)'%#$%("!"'&2,0#% 3%4*$!-.!56
,))&) \+(.!+9+" (#+ 4511&3$ ,'(' .$% 9+."!$& $0 '%$% !" $23+)("
(#'( #'9+ ' .$% "('(+ $0 ,))&)4
4511&3$ !"8 \+(.!+9+" '// '%$% !" $23+)(" (#'( #'9+ ' 4511&3$ ,'(' .$%
9+."!$&4 J>-!9'/+&( ($ ,))&)JKJ?3=>%32&)JKJ(!)*+&)4511&3$4
'&/&$&) \+(.!+9+" (#+ 01*2*3%/ ,'(' .$% 9+."!$& $0 '%$% !" $23+)("
(#'( #'9+ ' .$% "('(+ $0 '&/&$&)4
(!)*+&)4511&3$ \+(.!+9+" (#+ 4511&3$ ,'(' .$% 9+."!$& $0 '%$% !" $23+)("
(#'( #'9+ ' .$% "('(+ $0 (!)*+&)4
(!)*+&)01*2*3%/ \+(.!+9+" (#+ 01*2*3%/ ,'(' .$% 9+."!$& $0 '%$% !" $23+)("
(#'( #'9+ ' .$% "('(+ $0 (!)*+&)4
@!3& 6/+'." (#+ !"#$%$&A*/$&1 ?.$?+.(E; %#!)# 1+'&" (#'( (#+.+
!" &$ I/(+. '&, E$- "++ '// .$%"4
01*2*3%/ !"8 \+(.!+9+" (#+ '%$% !" $23+)(" (#'( #'9+ '& 01*2*3%/ ,'('
.$% 9+."!$&4
?3=>%32&) \+(.!+9+" '%$% !" $23+)(" (#'( #'9+ ' .$% "('(+ $0
?3=>%32&)4
=#+ 0$//$%!&* )$,+ "'1?/+ "#$%" ' !"#$%$&JI/(+. -"+, ($ .+(.!+9+ $&/E (#+ '%$% !"
$23+)(" (#'( #'9+ ' .$% "('(+ $0 '&/&$&)4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Dim view as new DataView(cars)
view.RowFilter = "Make like 'B%' and Year > 2003"
view.RowStateFilter = DataViewRowState.Deleted
3!4)'*%,.%+9%+,8*
DataView view = new DataView(cars);
view.RowFilter = "Make like 'B%' and Year > 2003";
view.RowStateFilter = DataViewRowState.Deleted;
F"&4*<!($"#%(;*%/!(!%5$*?
=#+ ?.$)+,-.+ 0$. %'/D!&* (#.$-*# (#+ ,'(' 9!+% !" "!1!/'. ($ (#'( 0$. +&-1+.'(!&* (#+ ,'('
('2/+ +F)+?( (#'( (#+ $23+)(" '.+ ,!00+.+&(4 =#+ 0$//$%!&* )$,+ )'& 2+ -"+, ($ +&-1+.'(+ (#+
.$%" '&, )$/-1&" $0 ' ,'(' 9!+%4
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& '=
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Public Sub EnumerateView(ByVal view As DataView)
Dim buffer As New System.Text.StringBuilder()
For Each dc As DataColumn In view.Table.Columns
buffer.AppendFormat("{0,15} ", dc.ColumnName)
Next
buffer.Append(vbCrLf)
For Each dr As DataRowView In view
For Each dc As DataColumn In view.Table.Columns
buffer.AppendFormat("{0,15} ", dr.Row(dc))
Next
buffer.Append(vbCrLf)
Next
TextBox1.Text = buffer.ToString()
End Sub
3!4)'*%,.%+9%+,8*
private void EnumerateView(DataView view)
{
var buffer = new System.Text.StringBuilder();
foreach (DataColumn dc in view.Table.Columns)
{
buffer.AppendFormat("{0,15} ", dc.ColumnName);
}
buffer.Append("\r\n");
foreach (DataRowView dr in view)
{
foreach (DataColumn dc in view.Table.Columns)
{
buffer.AppendFormat("{0,15} ", dr.Row[dc]);
}
buffer.Append("\r\n");
}
textBox1.Text = buffer.ToString();
}
=#!" )$,+ /$$?" $9+. (#+ .$%" !& (#+ 9!+%4 =#+ ,'(' (E?+ 0$. (#+ .$% !" '%$% !";*&" '"
$??$"+, ($ '%$% !"; %#!)# '%$%-%./& #'"4 5/"$; .+(.!+9!&* )$/-1& !&0$.1'(!$& .+>-!.+" E$-
($ '))+"" (#+ -%./& ?.$?+.(E (#'( (#+ 9!+% #'"4 =#+ .+"-/(" '.+ .+&,+.+, !&($ ' (+F( 2$F4
FM),<($"#%!% !"!&*'%%I0J*7(%(,%!%L*?%/!(!%G!0'*
5 '%$%;*&" $23+)( )'& 2+ -"+, ($ +F?$.( ,'(' 0.$1 $&+ '%$%-%./& $23+)( ($ '&$(#+.4 =#!" )'&
2+ +"?+)!'//E -"+0-/ %#+& ' -"+.H,+I&+, "+( $0 I/(+." !" '??/!+, '&, (#+ -"+. %'&(" ($ )$&9+.(
(#+ 9!+% (#'( !" "++& !&($ ' &+% ,'(' ('2/+4 JF?$.(!&* ($ ' &+% ,'(' ('2/+ !" ,$&+ %!(# (#+
'%$%;*&" $23+)(R" -!-%./& 1+(#$,; '" "#$%& #+.+4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
'here is the method signature that will be used
'Public Function ToTable(tableName as String, distinct as Boolean, _
' ParamArray columnNames() as String) as System.Data.DataTable
Dim export as DataTable = view.ToTable( _
"MyCarTable", true, "Vin", "Make", "Year")
&)> *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
3!4)'*%,.%+9%+,8*
//here is the method signature that will be used
//DataTable DataView.ToTable(string tableName,
// bool distinct, params string[] columnNames)
DataTable export = view.ToTable(
"MyCarTable", true, "Vin", "Make", "Year");
=#!" )$,+ "'1?/+ +F?$.(" (#+ ,'(' "++& (#.$-*# (#+ ,'(' 9!+% )'//+, :9!+%< ($ ' &+%
'%$%-%./& $23+)( &'1+, &G7!1$4 L$(+ (#'( (#+ &'1+ $0 (#!" ('2/+ !" :NE6'.='2/+<4 a'""!&* $15&
0$. (#+ )*8$*3=$ ?'.'1+(+. !&,!)'(+" (#'( $&/E ,!"(!&)( 9'/-+" '.+ D+?( O%#!)# I/(+. $-( ,-?/!)'(+
9'/-+"P4 70 <%/8& !" -"+,; '// 9'/-+" "#$-/, 2+ "#$%&4 =#+ &'1+" $0 (#+ )$/-1&" ($ !&)/-,+ !& (#+
&+% ('2/+ '.+ (#+& ?'""+, ($ (#+ 1+(#$,4
2-$"#%!% !"!5'"%I0J*7(%(,%+,,<8$"!(*%A,<>%6*(?**"%/!(!%G!0'*-'%$%#&$ !" ' 1+1$.EH2'"+,; ('2-/'.; .+/'(!$&'/ .+?.+"+&('(!$& $0 ,'(' '&, !" (#+ ?.!1'.E ,!"H
)$&&+)(+, ,'(' $23+)(4 6$&)+?(-'//E; (#!&D $0 '%$%#&$ '" '& !&H1+1$.E .+/'(!$&'/ ,'('2'"+;
2-( !(R" "!1?/E )')#+, ,'(' '&, ,$+"&R( ?.$9!,+ '&E $0 (#+ (.'&"')(!$&'/ ?.$?+.(!+" O'($1!)!(E;
)$&"!"(+&)E; !"$/'(!$&; ,-.'2!/!(EP (#'( '.+ +""+&(!'/ ($ ($,'ER" .+/'(!$&'/ ,'('2'"+"4 '%$%#&$
)$&('!&" ' )$//+)(!$& $0 '%$%-%./& '&, '%$% &/%$*!3 $23+)("; '" "#$%& !& T!*-.+ AHM4 =#+
'%$%-%./& $23+)(" )'& )$&('!& -&!>-+ '&, 0$.+!*& D+E )$&"(.'!&(" ($ +&0$.)+ ,'(' !&(+*.!(E4
'%$%#&$ '/"$ ?.$9!,+" 1+(#$," 0$. )/$&!&* (#+ '%$%#&$ ")#+1'; )$?E!&* (#+ ,'(' "+(; 1+.*H
!&* %!(# $(#+. '%$%#&$ $23+)("; '&, /!"(!&* )#'&*+"4
DataRelations Collection
DataTables Collection
DataSet
vendor_parts
!"#$%&'(1& =#+ '%$%#&$ $23+)( )$&('!&" ' )$//+)(!$& $0 '%$%-%./& '&, '%$% &/%$*!3 $23+)("4
G$- )'& ).+'(+ (#+ '%$%#&$ ")#+1' ?.$*.'11'(!)'//E $. 2E ?.$9!,!&* '& bN@ ")#+1'
,+I&!(!$&4 =#+ 0$//$%!&* )$,+ ,+1$&"(.'(+" (#+ ).+'(!$& $0 ' "!1?/+ ,'(' "+( )$&('!&!&* '
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& )'
,'(' ('2/+ 0$. 9+&,$." '&, ' ,'(' ('2/+ 0$. ?'.("4 =#+ (%$ '%$%-%./& $23+)(" '.+ 3$!&+, -"!&*
' '%$% &/%$*!3 $23+)( &'1+, F&3)!18L7%1$84 O'%$% &/%$*!3 !" ,!")-""+, !& 1$.+ ,+('!/ !& (#+
&+F( "+)(!$&4P
3!4)'*%,.%5$-&!'%6!-$7%+,8*
'create vendor dataset
Dim vendorData as new DataSet("VendorData")
Dim vendor as DataTable = vendorData.Tables.Add("Vendors")
vendors.Columns.Add("Id", GetType(Guid))
vendors.Columns.Add("Name", GetType(string))
vendors.Columns.Add("Address1", GetType(string))
vendors.Columns.Add("Address2", GetType(string))
vendors.Columns.Add("City", GetType(string))
vendors.Columns.Add("State", GetType(string))
vendors.Columns.Add("ZipCode", GetType(string))
vendors.Columns.Add("Country", GetType(string))
vendors.PrimaryKey = new DataColumn() { vendors.Columns("Id") }
Dim parts as DataTable = vendorData.Tables.Add("Parts")
parts.Columns.Add("Id", GetType(Guid))
parts.Columns.Add("VendorId", GetType(Guid))
parts.Columns.Add("PartCode", GetType(string))
parts.Columns.Add("PartDescription", GetType(string))
parts.Columns.Add("Cost", GetType(decimal))
parts.Columns.Add("RetailPrice", GetType(decimal))
parts.PrimaryKey = new DataColumn() { parts.Columns("Id") }
vendorData.Relations.Add( _
"vendors_parts", _
vendors.Columns("Id"), _
parts.Columns("VendorId"))
3!4)'*%,.%+9%+,8*
//create vendor dataset
DataSet vendorData = new DataSet("VendorData");
DataTable vendors = vendorData.Tables.Add("Vendors");
vendors.Columns.Add("Id", typeof(Guid));
vendors.Columns.Add("Name", typeof(string));
vendors.Columns.Add("Address1", typeof(string));
vendors.Columns.Add("Address2", typeof(string));
vendors.Columns.Add("City", typeof(string));
vendors.Columns.Add("State", typeof(string));
vendors.Columns.Add("ZipCode", typeof(string));
vendors.Columns.Add("Country", typeof(string));
vendors.PrimaryKey = new DataColumn[] { vendors.Columns["Id"] };
DataTable part = vendorData.Tables.Add("Parts");
parts.Columns.Add("Id", typeof(Guid));
parts.Columns.Add("VendorId", typeof(Guid));
parts.Columns.Add("PartCode", typeof(string));
parts.Columns.Add("PartDescription", typeof(string));
parts.Columns.Add("Cost", typeof(decimal));
&)) *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
parts.Columns.Add("RetailPrice", typeof(decimal));
parts.PrimaryKey = new DataColumn[] { parts.Columns["Id"] };
vendorData.Relations.Add(
"vendors_parts",
vendors.Columns["Id"],
parts.Columns["VendorId"]);
6*$"#% ,<*%3)*7$N7%?$(;%G1)*8% !"!5'"%I0J*7(-
=#+ ?.+9!$-" )$,+ ).+'(+, ' ")#+1' 0$. ' ,'(' "+(4 5))+""!&* (#+ ,'(' ('2/+ )$..+"?$&,!&* ($
(#+ 9+&,$." %$-/, .+>-!.+ )$,+ /!D+ (#!"B
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Dim vendorTable as DataTable = vendorData.Tables("Vendors")
3!4)'*%,.%+9%+,8*
DataTable vendorTable = vendorData.Tables["Vendors"];
C#'( #'??+&" !0 (#+ ('2/+ &'1+ !" "?+//+, !&)$..+)(/Ec 5& +F)+?(!$& !" (#.$%&; 2-( &$( -&H
(!/ .-& (!1+4 5 2+((+. '??.$')# !" ($ ).+'(+ ' &+%; "?+)!'/!S+, '%$%#&$ )/'"" (#'( !&#+.!(" 0.$1
'%$%#&$; ',,!&* ' ?.$?+.(E 0$. +')# $0 (#+ ('2/+"4 T$. +F'1?/+; ' "?+)!'/!S+, '%$%#&$ )/'""
1!*#( )$&('!& ' ?.$?+.(E )'//+, ;&3)!18 (#'( )'& 2+ '))+""+, '" 0$//$%"B
3!4)'*%,.%5$-&!'%6!-$7%+,8*
Dim vendorTable as DataTable = vendorData.Vendors
3!4)'*%,.%+9%+,8*
DataTable vendorTable = vendorData.Vendors;
Q"!&* (#!" "E&('F; ' )$1?!/+H(!1+ +..$. !" *+&+.'(+, !0 ;&3)!1 !" &$( "?+//+, )$..+)(/E4 5/"$;
(#+ )#'&)+" $0 !&)$..+)( "?+//!&* '.+ "!*&!I)'&(/E .+,-)+, 2+)'-"+ d!"-'/ V(-,!$ 7&(+//!V+&"+
,!"?/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and parts
Dim vendorRow as DataRow = nothing
vendorRow = vendors.NewRow()
Dim vendorId as Guid = Guid.NewGuid()
vendorRow("Id") = vendorId
vendorRow("Name") = "Tailspin Toys"
vendors.Rows.Add(vendorRow)
Dim partRow as DataRow = nothing
partRow = parts.NewRow()
partRow("Id") = Guid.NewGuid()
partRow("VendorId") = vendorId
partRow("PartCode") = "WGT1"
partRow("PartDescription") = "Widget 1 Description"
partRow("Cost") = 10.00
partRow("RetailPrice") = 12.32
parts.Rows.Add(partRow)
partRow = parts.NewRow()
&)1 *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
partRow("Id") = Guid.NewGuid()
partRow("VendorId") = vendorId
partRow("PartCode") = "WGT2"
partRow("PartDescription") = "Widget 2 Description"
partRow("Cost") = 9.00
partRow("RetailPrice") = 11.32
parts.Rows.Add(partRow)
'Navigate parent to children
textBox1.AppendText(vbCrLf + "Parent to Children" + vbCrLf)
Dim childParts As DataRow() = vendorRow.GetChildRows("vendors_parts")
For Each dr As DataRow In childParts
textBox1.AppendText( _
String.Format("Part: {0} from {1}" + vbCrLf, _
dr("PartCode"), vendorRow("Name")))
Next
textBox1.AppendText("--------------------------------" + vbCrLf)
'Navigate child to parent
textBox1.AppendText(vbCrLf + "Parent to Children" + vbCrLf)
Dim parentRow As DataRow = parts.Rows(1).GetParentRow("vendors_parts")
textBox1.AppendText( _
String.Format("Vendor: {0} for {1}" + vbCrLf, _
parentRow("Name"), parts.Rows(1)("PartCode")))
textBox1.AppendText("--------------------------------" + vbCrLf)
3!4)'*%,.%+9%+,8*
//add vendors and parts
DataRow vendorRow = null;
vendorRow = vendors.NewRow();
Guid vendorId = Guid.NewGuid();
vendorRow["Id"] = vendorId;
vendorRow["Name"] = "Tailspin Toys";
vendors.Rows.Add(vendorRow);
DataRow partRow = null;
partRow = parts.NewRow();
partRow["Id"] = Guid.NewGuid();
partRow["VendorId"] = vendorId;
partRow["PartCode"] = "WGT1";
partRow["PartDescription"] = "Widget 1 Description";
partRow["Cost"] = 10.00;
partRow["RetailPrice"] = 12.32;
parts.Rows.Add(partRow);
partRow = parts.NewRow();
partRow["Id"] = Guid.NewGuid();
partRow["VendorId"] = vendorId;
partRow["PartCode"] = "WGT2";
partRow["PartDescription"] = "Widget 2 Description";
partRow["Cost"] = 9.00;
partRow["RetailPrice"] = 11.32;
parts.Rows.Add(partRow);
//Navigate parent to children
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& )9
textBox1.AppendText("\r\nParent to Children\r\n");
DataRow[] childParts = vendorRow.GetChildRows("vendors_parts");
foreach (DataRow dr in childParts)
{
textBox1.AppendText(
string.Format("Part: {0} from {1}\r\n",
dr["PartCode"],vendorRow["Name"]));
}
textBox1.AppendText("--------------------------------\r\n");
//Navigate child to parent
textBox1.AppendText("\r\nChild to Parent\r\n");
DataRow parentRow = parts.Rows[1].GetParentRow("vendors_parts");
textBox1.AppendText(
string.Format("Vendor: {0} for {1}\r\n",
parentRow["Name"], parts.Rows[1]["PartCode"]));
textBox1.AppendText("--------------------------------\r\n");
+<*!($"#%K<$4!<1%!"8%O,<*$#"%P*1%+,"-(<!$"(-
G$- )'& ).+'(+ ' '%$% &/%$*!3 $23+)( %!(# $. %!(#$-( -&!>-+ '&, 0$.+!*& D+E )$&"(.'!&(" 0$.
(#+ "$/+ ?-.?$"+ $0 &'9!*'(!&* 2+(%++& ?'.+&( '&, )#!/, '%$%-%./& $23+)("4 =#+ '%$% &/%$*!3
)/'"" ?.$9!,+" ' )$&"(.-)($. (#'( +&'2/+" (#+ ).+'(!$& $0 ' -&!>-+ )$&"(.'!&( $& (#+ ?'.+&(
'%$%-%./& $23+)( '&, ' 0$.+!*& D+E )$&"(.'!&( $& (#+ )#!/, '%$%-%./& $23+)(4 =#+"+ )$&"(.'!&("
+&0$.)+ ,'(' !&(+*.!(E 2E +&"-.!&* (#'( ' ?'.+&( '%$% !" $23+)( +F!"(" 0$. '&E )#!/, '%$% !"
$23+)(4 =#+ 0$//$%!&* )$,+ ,+1$&"(.'(+" (#+ ).+'(!$& $0 (#+ '%$% &/%$*!3 $23+)( &'1+,
F&3)!1L7%1$; ?'""!&* $15& ($ ).+'(+ )$&"(.'!&(" !0 (#+E ,$&R( '/.+',E +F!"(4
!"#& 5$%!"6&?%@4&,63&6#00&2,0#%4
H.%!%.,<*$#"%>*1%7,"-(<!$"(%$-%-*(%(,%!% !"!/$9:;+%,0J*7(%(;!(%!'',?-%"&''-D%(;$-%7;$'8%8!(!%
<,?%7!"%*M$-(%?$(;,&(%;!=$"#%!%)!<*"(% !"!#$%%,0J*7(@%H"%-,4*%-$(&!($,"-D%(;$-%4$#;(%0*%
8*-$<*8%,<%<*Q&$<*8D%0&(%$"%,(;*<%-$(&!($,"-D%$(%4$#;(%",(@%6*%-&<*%(,%=*<$.1%(;*%,99$% <=:99%
)<,)*<(1%,.%(;*% !"!/$9:;+%,0J*7(-%0*$"#%&-*8%!-%.,<*$#"%>*1-@%
3!4)'*%,.%5$-&!'%6!-$7%+,8*
vendorData.Relations.Add( _
"vendors_parts", _
vendors.Columns("Id"), _
parts.Columns("VendorId"), True)
3!4)'*%,.%+9%+,8*
vendorData.Relations.Add(
"vendors_parts",
vendors.Columns["Id"],
parts.Columns["VendorId"], true);
!"# 5$%!"6&?%@4&,63&6#00&2,0#%4
H.%!%.,<*$#"%>*1%7,"-(<!$"(%$-%-*(%(,%!% !"!/$9:;+%,0J*7(%(;!(%!'',?-%"&''-D%(;$-%7;$'8%8!(!%
<,?%7!"%*M$-(%?$(;,&(%;!=$"#%!%)!<*"(% !"!#$%%,0J*7(@%H"%-,4*%-$(&!($,"-D%(;$-%4$#;(%0*%%
8*-$<*8%,<%<*Q&$<*8D%0&(%$"%,(;*<%-$(&!($,"-D%$(%4$#;(%",(@%6*%-&<*%(,%=*<$.1%(;*%,99$% <=:99
)<,)*<(1%,.%(;*% !"!/$9:;+%,0J*7(-%0*$"#%&-*8%!-%.,<*$#"%>*1-@%
&): *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
+!-7!8$"#%/*'*(*-%!"8%+!-7!8$"#%2)8!(*-
5 0$.+!*& D+E )$&"(.'!&( +&"-.+" (#'( ' )#!/, '%$% !" $23+)( )'&&$( 2+ ',,+, -&/+"" ' 9'/!,
?'.+&( '%$% !" $23+)( +F!"("4 7& "$1+ "!(-'(!$&"; !( !" ,+"!.'2/+ ($ 0$.)+ (#+ ,+/+(!$& $0 (#+
)#!/, '%$% !" $23+)(" %#+& (#+ ?'.+&( '%$% !" $23+)( !" ,+/+(+,4 G$- )'& ,$ (#!" 2E "+((!&*
'&/&$& 5/& ($ 4%8=%)& $& (#+ A!1&*23M&H4!38$1%*3$ )$&"(.'!&( $0 (#+ )#!/, ('2/+ )$..+"?$&,H
!&* ($ (#+ .+/'(!$&4 4%8=%)& !" (#+ ,+0'-/( "+((!&*4 ='2/+ AHg ,+").!2+" (#+ $(#+. 1+12+." $0
(#+ 5/& +&-1+.'(!$&4
5" %!(# ,+/+(!&*; $& "$1+ $))'"!$&"; E$-R// %'&( ($ )'")',+ )#'&*+" ($ ' -&!>-+ D+E !& (#+
?'.+&( '%$% !" $23+)( ($ (#+ )#!/, '%$% !" $23+)(R" 0$.+!*& D+E4 G$- )'& "+( 4>%32& 5/& ($
' 1+12+. $0 (#+ 5/& +&-1+.'(!$& ($ *+( (#+ '??.$?.!'(+ 2+#'9!$.4
.,/0%&'(:& 5/& J&-1+.'(!$& N+12+."
$#0%&2,0#% 3%4*$!-.!56
4%8=%)& 8+0'-/(4 8+/+(+" $. -?,'(+" (#+ )#!/, '%$% !" $23+)(" %#+& (#+
'%$% !" $23+)( !" ,+/+(+, $. !(" -&!>-+ D+E !" )#'&*+,4 =#!" !"
(#+ ,+0'-/( 2+#'9!$.4
@!3& =#.$%" '& E3F%/*)4!38$1%*3$:G=&7$*!3 !0 (#+ ?'.+&( '%$% !"
$23+)( !" ,+/+(+, $. !(" -&!>-+ D+E !" )#'&*+,4
#&$'&<%5/$ V+(" (#+ 0$.+!*& D+E )$/-1&O"P 9'/-+ ($ (#+ ,+0'-/( 9'/-+ $0 (#+
'%$%4!/5I3 $23+)(O"P !0 (#+ ?'.+&( '%$% !" $23+)( !" ,+/+(+, $.
!(" -&!>-+ D+E !" )#'&*+,4
#&$@5// V+(" (#+ 0$.+!*& D+E )$/-1&O"P 9'/-+ ($ '9@5// !0 (#+ ?'.+&(
'%$% !" $23+)( !" ,+/+(+, $. !(" -&!>-+ D+E !" )#'&*+,4
=#+ ,+0'-/( "+((!&* 0$. ' A!1&*23M&H4!38$1%*3$ $23+)(R" '&/&$& 5/& ?.$?+.(E !" 5/&N4%8=%)&4
=#+ 0$//$%!&* )$,+ "'1?/+ "#$%" #$% ($ 0$.)+ '& E3F%/*)4!38$1%*3$:G=&7$*!3 ($ 2+ (#.$%&
%#+& ' ?'.+&( (#'( #'" )#!/,.+& !" ,+/+(+, $. %#+& ' )#!/, !" 2+!&* ',,+, (#'( #'" &$ ?'.+&(4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
'set delete rule
Dim fk as ForeignKeyConstraint = part.Constraints("vendors_parts")
fk.DeleteRule = Rule.None
3!4)'*%,.%+9%+,8*
//set delete rule
ForeignKeyConstraint fk =
(ForeignKeyConstraint)part.Constraints["vendors_parts"];
fk.DeleteRule = Rule.None;
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& );
2-$"#% *<#*%(,%+,40$"*% !"!5'"%/!(!
K& 1'&E $))'"!$&"; ,'(' '9'!/'2/+ !& $&+ ,'(' "+( 1-"( 2+ )$12!&+, %!(# '&$(#+. ,'(' "+(4
T$. +F'1?/+; ' "'/+" '??/!)'(!$& 1!*#( &++, ($ )$12!&+ "+.!'/!S+, '%$%#&$ $23+)(" .+)+!9+,
2E +1'!/ 0.$1 ' &-12+. $0 "'/+" ?+$?/+4 J9+& !&(+.&'//E %!(#!& '& '??/!)'(!$&; E$- 1!*#(
%'&( ($ ).+'(+ ' )$?E $0 '%$%-%./& $23+)(" (#+ -"+. )'& +,!(; '&,; 2'"+, $& (#+ -"+. )/!)D!&*
Q?,'(+; (#+ 1$,!I+, ,'(' )'& 2+ 1+.*+, 2')D ($ (#+ $.!*!&'/ ,'(' "+(4
=#+ '%$%#&$ )/'"" )$&('!&" ' 1+(#$, )'//+, (&12& (#'( )'& 2+ -"+, ($ )$12!&+ ,'('
0.$1 1-/(!?/+ '%$%#&$ $23+)("4 =#+ (&12& 1+(#$, #'" "+9+.'/ $9+./$'," ($ 1+.*+ ,'(' 0.$1
'%$%#&$; '%$%-%./&O $. '%$% !" $23+)("4 =#+ 0$//$%!&* )$,+ +F'1?/+ ,+1$&"(.'(+" -"!&* (#+
(&12& 1+(#$, ($ )$12!&+ )#'&*+" 0.$1 $&+ ,'(' "+( !&($ '&$(#+. ,'(' "+(4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
'Create an initial DataSet
Dim masterData As New DataSet("Sales")
Dim people As DataTable = masterData.Tables.Add("People")
people.Columns.Add("Id", GetType(Guid))
people.Columns.Add("Name", GetType(String))
people.PrimaryKey = New DataColumn() { people.Columns("Id")}
people.Rows.Add(Guid.NewGuid(), "Joe")
'Create a temp DataSet and make changes
Dim tempData As DataSet = masterData.Copy()
'get Joe's info
Dim tempPeople As DataTable = tempData.Tables("People")
Dim joe As DataRow = tempPeople.Select("Name='Joe'")(0)
Dim joeId As Guid = CType(joe("Id"), Guid)
'Modify joe's name
joe("Name") = "Joe in Sales"
'Create an Order table and add orders for Joe
Dim orders As DataTable = tempData.Tables.Add("Orders")
orders.Columns.Add("Id", GetType(Guid))
orders.Columns.Add("PersonId", GetType(Guid))
orders.Columns.Add("Amount", GetType(Decimal))
orders.PrimaryKey = New DataColumn() { orders.Columns("Id")}
orders.Rows.Add(Guid.NewGuid(), joeId, 100)
'Now merge back to master
masterData.Merge(tempData, False, MissingSchemaAction.AddWithKey)
3!4)'*%,.%+9%+,8*
//Create an initial DataSet
DataSet masterData = new DataSet("Sales");
DataTable people = masterData.Tables.Add("People");
people.Columns.Add("Id", typeof(Guid));
people.Columns.Add("Name", typeof(string));
people.PrimaryKey = new DataColumn[] { person.Columns["Id"] };
people.Rows.Add(Guid.NewGuid(), "Joe");
//Create a temp DataSet and make changes
&)< *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
DataSet tempData = masterData.Copy();
//get Joe's info
DataTable tempPeople = tempData.Tables["People"];
DataRow joe = tempPeople.Select("Name='Joe'")[0];
Guid joeId = (Guid)joe["Id"];
//Modify joe's name
joe["Name"] = "Joe in Sales";
//Create an Order table and add orders for Joe
DataTable orders = tempData.Tables.Add("Orders");
orders.Columns.Add("Id", typeof(Guid));
orders.Columns.Add("PersonId", typeof(Guid));
orders.Columns.Add("Amount", typeof(decimal));
orders.PrimaryKey = new DataColumn[] { orders.Columns["Id"] };
orders.Rows.Add(Guid.NewGuid(), joeId, 100);
//Now merge back to master
masterData.Merge(tempData, false, MissingSchemaAction.AddWithKey);
=#!" )$,+ ).+'(+" ' ,'(' "+( (#'( )$&('!&" ' "!&*/+ '%$%-%./& $23+)(; )'//+, 6&!7/&4 5 ?+."$&
&'1+, f$+ %'" ',,+, ($ (#+ 7&!7/& '%$%-%./& $23+)(4 =#+ ,'(' .$% "('(+ 0$. f$+R" ,'(' .$%
!" ,))&)4 L+F(; (#+ )$,+ )$?!+" (#+ I%8$&1'%$% '%$%#&$ $23+)( ($ ' '%$%#&$ $23+)( )'//+,
$&I7'%$%4 =#+ )$,+ 1$,!I+" (#+ $&I7'%$% '%$%#&$ $23+)( 2E )#'&*!&* f$+R" &'1+ ($ :f$+ !&
V'/+"<; '&, (#+& !( ).+'(+" ' &+% '%$%-%./& $23+)( )'//+, 01)&18 '&, ',," '& $.,+.4
=#+ (&12& 1+(#$, $& I%8$&1'%$%; %#!)# ('D+" (#.++ ?'.'1+(+."; !" (#+& )'//+,4
=#+ I."( ?'.'1+(+. !" (#+ $&I7'%$% $23+)(4 =#+ "+)$&, ?'.'1+(+. !" ' X$$/+'& )'//+,
71&8&1F&4>%32&8; %#!)# "?+)!I+" %#+(#+. -?,'(+" 0.$1 (#+ $&I7'%$% ,'(' "+( "#$-/,
$9+.%.!(+ )#'&*+" 1',+ !& (#+ I%8$&1'%$% $23+)(4 T$. +F'1?/+; f$+R" ,'(' .$% "('(+ !&
(#+ I%8$&1'%$% ,'(' "+( !" &$( ?3=>%32&); "$ !0 (#+ 71&8&1F&4>%32&8 "+((!&* !" $15&; f$+R"
&'1+ )#'&*+ O($ :f$+ !& V'/+"<P %!// &$( 2+ 1+.*+, !&($ I%8$&1'%$%4 =#+ /'"( ?'.'1+(+. !" '
(*88*32#=>&I%,=$*!3 +&-1+.'(!$& 1+12+.4 =#+ ,))P*$>M&H 9'/-+ !" "+/+)(+,; %#!)# 1+'&"
(#+ V'/+" ,'(' ('2/+ '&, !(" ,'(' '.+ ',,+, ($ I%8$&1'%$%4 ='2/+ AHh ,+").!2+" (#+ +&-1+.'H
(!$& 1+12+."4
.,/0%&'(;&(*88*32#=>&I%,=$*!3 J&-1+.'(!$& N+12+."
+)(()*,(-.'+!!-")$*&2,0#% 3%4*$!-.!56
,)) 5,," (#+ &+)+""'.E '%$%-%./& '&, '%$%4!/5I3 $23+)("
($ )$1?/+(+ (#+ ")#+1'4
,))P*$>M&H 5,," (#+ &+)+""'.E '%$%-%./&; '%$%4!/5I3; '&,
61*I%1HM&H $23+)(" ($ )$1?/+(+ (#+ ")#+1'4
:11!1 5& +F)+?(!$& !" (#.$%& !0 ' ,'(' )$/-1& ,$+" &$( +F!"(
!& (#+ ,'(' "+( 2+!&* -?,'(+,4
E23!1& 7*&$.+" ,'(' (#'( .+"!,+" !& ,'(' )$/-1&" (#'( '.+ &$( !&
(#+ ,'(' "+( 2+!&* -?,'(+,4
@+""$& AB C$.D!&* %!(# (#+ '%$%-%./& '&, '%$%#&$ 6/'""+" *+,-.%$&'& )=
C#+& E$- -"+ (#+ (&12& 1+(#$,; 1'D+ "-.+ (#+ '%$%-%./& $23+)(" #'9+ ' ?.!1'.E D+E4
T'!/-.+ ($ "+( (#+ 61*I%1HM&H ?.$?+.(E $0 (#+ '%$%-%./& $23+)( .+"-/(" !& '%$% !" $23+)(" 2+H
!&* '??+&,+, .'(#+. (#'& +F!"(!&* '%$% !" $23+)(" 2+!&* 1$,!I+,4
!"#$%&$' ABCDEFG&HEIJ& /0/"/123&KFL& /0/(30&*MKNNON
7& (#!" ?.')(!)+; E$- ).+'(+ ' "1'// '??/!)'(!$& (#'( %$.D" %!(# (#+ ,!")$&&+)(+, ,'(' )/'""+"
(#'( #'9+ 2++& ,+I&+, !& (#!" /+""$&4 =#+ ")+&'.!$ !" 2'"+, $& ' ?+."$& %#$ $%&" "+9+.'/
9+#!)/+" '&, %'&(" ($ (.')D '// .+?'!." 0$. +')# 9+#!)/+4
C#+& (#+ '??/!)'(!$& "('.(" 0$. (#+ I."( (!1+; ' ,'(' "+( %!// 2+ ).+'(+, '&, ?$?-/'(+, %!(#
' ")#+1'4
=#!" ?.')(!)+ !" !&(+&,+, ($ 0$)-" $& (#+ )/'""+" (#'( #'9+ 2++& +F?/'!&+, !& (#!" /+""$&;
'&, '( (#!" (!1+; (#+.+ !" &$ 0$)-" $& (#+ *.'?#!)'/ -"+. !&(+.0')+ OiQ7P4 =#+ &+F( /+""$& )$9+."
,'(' 2!&,!&* ($ (#+ iQ7 '&, %!// 0$)-" $& (#+ iQ74
70 E$- +&)$-&(+. ' ?.$2/+1 )$1?/+(!&* '& +F+.)!"+; (#+ )$1?/+(+, ?.$3+)(" )'& 2+ !&H
"('//+, 0.$1 (#+ 6$,+ 0$/,+. $& (#+ )$1?'&!$& 684
'('"$&)' +<*!(*%(;*%K<,J*7(%!"8%(;*% !"!5'"%37;*4!
7& (#!" +F+.)!"+; E$- ).+'(+ ' C!&,$%" '??/!)'(!$& ?.$3+)( '&, (#+& ',, )$,+ ($ ).+'(+ '
,'(' "+( %!(# ' d+#!)/+" ,'('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$,+4 G$- )'& '/"$ -"+ '%$%-%./& &%)&1 ($ ?$?-/'(+ 1'&E C+2 )$&(.$/" %!(#$-( #'9!&* ($
%.!(+ /$$?!&* )$,+ 2+)'-"+ 1'&E $0 (#+ /!"(H(E?+ C+2 )$&(.$/" '))+?( '& $23+)( (#'( !1?/+H
1+&(" (#+ E'%$% &%)&1 !&(+.0')+4
70 '& -&,+./E!&* '%$% !"J$23+)( !" ,+/+(+, $. .+1$9+, 0.$1 !(" ,'(' ('2/+ 2+0$.+
'%$%-%./& &%)&1 *+(" ($ (#+ '%$% !" $23+)(; &$ '((+1?( !" 1',+ ($ .+(.!+9+ (#+ '%$% !"
$23+)(4 70 ' '%$% !" $23+)( (#'( #'" '/.+',E 2++& .+', !" ,+/+(+, $. .+1$9+,; (#+ )-..+&(
?$"!(!$& !" 1'!&('!&+,Z (#+.+ !" &$ .+"-/(!&* "#!0( !& ?$"!(!$&4
70 '%$% !" $23+)(" '.+ ',,+, ($ (#+ -&,+./E!&* '%$%-%./& $23+)( %#!/+ '%$%-%./& &%)&1
!" /$$?!&*; (#+"+ '%$% !" $23+)(" '.+ !&)/-,+, !& (#+ '%$%-%./& &%)&1 !(+.'(!$&" $&/E !0 (#+
,'(' .$% !" ',,+, '0(+. (#+ )-..+&( ?$"!(!$& $0 (#+ '%$%-%./& &%)&1 $23+)(4 '%$% !" $23+)("
!&"+.(+, 2+0$.+ (#+ )-..+&( ?$"!(!$& $0 (#+ '%$%-%./& &%)&1 )/'"" '.+ &$( !&)/-,+, !& (#+
!(+.'(!$&"4
=#+ '%$%-%./& &%)&1 )/'"" )$&('!&" ' 1+(#$, )'//+, &%) (#'( !" +F+)-(+, ($ /$',
'%$%-%./& &%)&1 %!(# (#+ ,'(' .$% '( (#+ )-..+&( ?$"!(!$&; '&, (#+& (#+ ?$"!(!$& !" ',9'&)+,4
70 (#+ +&, $0 ,'(' !" .+')#+,; (#+ &%) 1+(#$, .+(-.&" &-//4 5&E '((+1?( ($ +F+)-(+ (#+ &%)
1+(#$, '0(+. (#+ +&, $0 ,'(' !" .+')#+, %!// '/%'E" .+(-.& &-//; +9+& !0 1$.+ '%$% !" $23+)("
'.+ ',,+,4
=#+ '%$%#&$ )/'"" )$&('!&" ' 1+(#$, )'//+, 41&%$&'%$% &%)&1 (#'( .+(-.&" '& !&"('&)+ $0
(#+ '%$%-%./& &%)&1 )/'""4 70 (#+ ,'(' "+( )$&('!&" 1$.+ (#'& $&+ ('2/+; (#+ '%$%-%./& &%)&1
$23+)( .+'," .$%" 0.$1 (#+ I."( '%$%-%./& $23+)(; '&, E$- )'& -"+ (#+ @&G$ &85/$ 1+(#$, ($
)$&(!&-+ /$$?!&* (#.$-*# '// ,'(' ('2/+" !& (#+ ,'(' "+(4
=#+ 0$//$%!&* )$,+ +F'1?/+ ,+1$&"(.'(+" (#+ -"+ $0 '%$%-%./& &%)&1 ($ /$$? $9+. ' ,'('
('2/+ '&, ,!"?/'E (#+ 6&18!3 $23+)(R" @%I& ?.$?+.(E; '&, (#+& (#+ @&G$ &85/$ 1+(#$, !"
+F+)-(+, ($ 1$9+ ($ (#+ 6%1$ ,'(' ('2/+ '&, ,!"?/'E (#+ 6%1$@%I& ?.$?+.(E ($ ' (+F( 2$F4
3!4)'*%,.%5$-&!'%6!-$7%+,8*
'Create an initial DataSet
Dim masterData As New DataSet("Sales")
Dim person As DataTable = masterData.Tables.Add("Person")
person.Columns.Add("Id", GetType(Guid))
person.Columns.Add("Name", GetType(String))
person.PrimaryKey = New DataColumn() {person.Columns("Id")}
Dim part As DataTable = masterData.Tables.Add("Part")
part.Columns.Add("Id", GetType(Guid))
part.Columns.Add("PartName", GetType(String))
part.PrimaryKey = New DataColumn() {part.Columns("Id")}
For i As Integer = 0 To 100
person.Rows.Add(Guid.NewGuid(), "Joe " + i.ToString())
part.Rows.Add(Guid.NewGuid(), "Part " + i.ToString())
&1< *+,-.%$&' 58K4LJ= 8!")$&&+)(+, 6/'""+"
Next
'read the data in the DataTable
Dim rd As DataTableReader = masterData.CreateDataReader()
While (rd.Read())
TextBox1.AppendText(rd("Name").ToString() + vbcrlf)
End While
rd.NextResult()
While (rd.Read())
TextBox1.AppendText(rd("PartName").ToString() + vbcrlf)
End While
!"#$%&'(&)*&)'+%
//Create an initial DataSet
DataSet masterData = new DataSet("Sales");
DataTable person = masterData.Tables.Add("Person");
person.Columns.Add("Id", typeof(Guid));
person.Columns.Add("Name", typeof(string));
person.PrimaryKey = new DataColumn[] { person.Columns["Id"] };
DataTable part = masterData.Tables.Add("Part");
part.Columns.Add("Id", typeof(Guid));
part.Columns.Add("PartName", typeof(string));
part.PrimaryKey = new DataColumn[] { part.Columns["Id"] };
for (int i = 0; i < 100; i++)
{
person.Rows.Add(Guid.NewGuid(), "Joe " + i);
part.Rows.Add(Guid.NewGuid(), "Part " + i);
}
//read the data in the DataTable
DataTableReader rd = masterData.CreateDataReader();
while (rd.Read())
{
textBox1.AppendText(rd["Name"].ToString() + "\r\n");
}
rd.NextResult();
while (rd.Read())
{
textBox1.AppendText(rd["PartName"].ToString() + "\r\n");
}
!"# !"!#!$%&'&!(&)#$%&''#()!"*(+'#,*-.#+!"# $ !"!'&!(&)#$%&''/#0-12%%#3)4#.-*"#(),-*.&5
+(-)#-)#+!"#6*-6"*+("'#()!"*(+"4#,*-.# $ !"!'&!(&)#()#7!&6+"*#8/
,!-+$.-/& #%0.!$.1%+&23#%4 !"# !"!#!$%&#$%&''#")&9%"'#:-1#+-#!&;"#&#$-%1.)#<!-'"#+:6"#('#'6"$(&%(="4>#<!($!#&%%-<'#,-*#
$-%1.)'#+-#$-)+&()#?@A#4&+&#-*#";")#&)#()'+&)$"#-,#&#$1'+-.#$%&''#:-1#$*"&+"4/
B#$-%1.)#<!-'"#4&+&#+:6"#('#&#*","*")$"#+:6"C"D$"6+#'+*()EC*"F1(*"'#'6"$(&%#+*"&+.")+#
()#$"*+&()#$&'"'>#9"$&1'"#(,#&#$-%1.)2'#4&+&#+:6"#('#&#*","*")$"#+:6"#&)4#('#1'"4#&'#*(.&*:#
G":#-*#&'#&#*+)"#-*#'+,-.%"&)#G":#,-*#&+&#;("<>#&):#$!&)E"#+-#+!"#$-%1.)#;&%1"#.1'+#();-%;"#
# A"''-)#8H#I"*(&%(=&+(-)>#I6"$(&%(="4# :6"'>#&)4#J&+&#K()4()E# !"#$%&'(' )*
&''(E)()E#&#)"<#-9L"$+#+-#+!"#$-%1.)#&'#-66-'"4#+-#L1'+#$!&)E()E#6*-6"*+("'#-)#+!"#$-%1.)2'#
"D('+()E#-9L"$+/# !('#&''(E).")+#('#*"F1(*"4#+-#+*(EE"*#+!"#164&+"#-,#+!"#()+"*)&%#()4"D"'#1'"4#
9:#'-*+()E>#3%+"*()E>#&)4#6*(.&*:#G":#-6"*&+(-)'/# !"#,-%%-<()E#$-4"#"D&.6%"#'!-<'#!-<#:-1#
$&)#&''(E)#&#$1'+-.#/!)#-9L"$+#+-#&#$-%1.)#;&%1"/#
!"#$%&'(&5.46!$&7!4.0&)'+%
<Serializable()> _
Public Class Car
Public Property Make() As String
Public Property Model() As String
Public Property Year() As Integer
End Class
Private Sub specializedTypesToolStripMenuItem_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles specializedTypesToolStripMenuItem.Click
Dim cars = CreateTableWithUDT()
'Add New DataRow by creating the DataRow first
Dim newAuto = cars.NewRow()
newAuto("Vin") = "123456789ABCD"
Dim c = New Car With {.Make = "Chevy", .Model = "Impala", .Year = 2003}
newAuto("CarObject") = c
cars.Rows.Add(newAuto)
Dim theCar = CType(cars.Rows(0)("CarObject"), Car)
textBox1.AppendText(String.Format("Car: {0} {1} {2}\r\n", _
theCars.Year, theCars.Make, theCars.Model))
End Sub
Public Function CreateTableWithUDT() As DataTable
'Create the DataTable named "Car"
Dim cars = New DataTable("Car")
'Add the DataColumn using all properties
Dim vin = New DataColumn("Vin")
vin.DataType = GetType(String)
vin.MaxLength = 23
vin.Unique = True
vin.AllowDBNull = False
vin.Caption = "VIN"
cars.Columns.Add(vin)
'UDT column
Dim carColumn = New DataColumn("CarObject", GetType(Car))
cars.Columns.Add(carColumn)
'Set the Primary Key
cars.PrimaryKey = New DataColumn() {vin}
Return Car
End Function
!"#$%&'(&)*&)'+%
[Serializable]
public class Car
'+, !"#$%&'( BJM/NO #J('$-))"$+"4#7%&''"'
{
public int Year { get; set; }
public string Make { get; set; }
public string Model { get; set; }
}
private void specializedTypesToolStripMenuItem_Click(
object sender, EventArgs e)
{
DataTable cars = CreateTableWithUDT();
//Add New DataRow by creating the DataRow first
DataRow newAuto = cars.NewRow();
newAuto["Vin"] = "123456789ABCD";
Car c = new Car { Make = "Chevy", Model = "Impala", Year = 2003 };
newAuto["CarObject"] = c;
cars.Rows.Add(newAuto);
Car theCar = (Car)cars.Rows[0]["CarObject"];
textBox1.AppendText(string.Format("Car: {0} {1} {2}\r\n",
theCars.Year, theCars.Make, theCars.Model));
}
public DataTable CreateTableWithUDT()
{
//Create the DataTable named "Car"
DataTable cars = new DataTable("Car");
//Add the DataColumn using all properties
DataColumn vin = new DataColumn("Vin");
vin.DataType = typeof(string);
vin.MaxLength = 23;
vin.Unique = true;
vin.AllowDBNull = false;
vin.Caption = "VIN";
cars.Columns.Add(vin);
//UDT column
DataColumn carColumn = new DataColumn("CarObject", typeof(Car));
cars.Columns.Add(carColumn);
//Set the Primary Key
cars.PrimaryKey = new DataColumn[] { vin };
return car;
}
P)#+!('#$-4"#"D&.6%">#+!"#/!)#$%&''#!&'#+!"#*&).!%.0!$%&#&++*(91+"#-)#(+>#<!($!#('#)"$"''&*:#(,#
:-1#<(%%#9"#'"*(&%(=()E#+!"#4&+&#+&9%"#+!&+#$-)+&()'#+!('#;&%1"/
# A"''-)#8H#I"*(&%(=&+(-)>#I6"$(&%(="4# :6"'>#&)4#J&+&#K()4()E# !"#$%&'(' +(
8!9!&7.-+.-/&:;%<;.%=@-'+#-,#+!"#$-)+*-%'#:-1#<-1%4#1'"#()#Q()4-<'#R-*.'>#BIS/NO >#-*#Q()4-<'#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"+>#&)4#&44#$-4"#+-#4"3)"#+!"#)&."#-,#+!"#?@A#3%"#+!&+#<(%%#!-%4#
+!"#4&+&/#0-1*#$-4"#'!-1%4#9"#&44"4#&+#+!"#$%&''#%";"%#-,#R-*.X#&)4#'!-1%4#)-<#%--G#
%(G"#+!"#,-%%-<()EH
!"#$%&'(&5.46!$&7!4.0&)'+%
Private ReadOnly xsdFile = Path.Combine(Environment.GetFolderPath( _
Environment.SpecialFolder.ApplicationData), "VehiclesRepairs.xsd")
Private ReadOnly xmlFile = Path.Combine(Environment.GetFolderPath( _
Environment.SpecialFolder.ApplicationData), "VehiclesRepairs.xml")
Private ds As DataSet
'+) !"#$%&'( BJM/NO #J('$-))"$+"4#7%&''"'
!"#$%&'(&)*&)'+%
private readonly string xsdFile = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData),"VehiclesRepairs.xsd");
private readonly string xmlFile = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData),"VehiclesRepairs.xml");
private DataSet ds;
!"#6&+!#('#'6"$(3"4#<(+!#+!"#3%"#)&."'/#R""%#,*""#+-#$!&)E"#+!"#6&+!'#-,#9-+!#-,#+!"'"#
3%"'#+-#'1(+#:-1*#)""4'/
1+# 7!&)E"#+!"#$-4"#()#+!"#-+);EF4+!(#";")+#!&)4%"*#."+!-4#+-#$&%%#&#@+>1%!"& !"!*&"#
."+!-4#+!&+#!&')2+#9"")#$*"&+"4#:"+/#
!('#$-4"#<(%%#*"6%&$"#+!"#"D('+()E#$&%%#+-#+!"#/)&!"&*2C&;!#."+!-4#+!&+#:-1#&44"4#()#
+!"#A"''-)#X#6*&$+($"/# !('#."+!-4#<(%%#6-61%&+"#+!"#4&+&#'"+#<(+!#&#'$!".&#&)4#4&+&/#
0-1*#$-4"#'!-1%4#%--G#%(G"#+!"#,-%%-<()EH
!"#$%&'(&5.46!$&7!4.0&)'+%
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
PopulateDataSet()
End Sub
!"#$%&'(&)*&)'+%
private void Form1_Load(object sender, EventArgs e)
{
PopulateDataSet();
}
2+# B44#$-4"#+-#$*"&+"#+!"#@+>1%!"& !"!*&"#."+!-4/# !('#."+!-4#<(%%#$!"$G#+-#'""#
<!"+!"*#+!"#'$!".%"#"D('+'#&)4>#(,#(+#4-"'#"D('+>#%-&4'#+!"#'$!".&#()+-#+!"#4&+&#'"+/#
P,#+!"#'$!".-"')2+#"D('+>#&44#$-4"#+-#$&%%#+!"#/)&!"&*2C&;!#."+!-4#+!&+#<&'#$*"5
&+"4#()#+!"#A"''-)#X#6*&$+($"/#B%'-#&44#$-4"#+-#%-&4#+!"#?@A#3%"#(,#(+#"D('+'/#0-1#<(%%#
&%'-#<&)+#+-#&44#3;>+)"5G*?5"&;H3I#T7_#1'()E#*?5"&;H3IJU#+-#+!"#+-6#-,#:-1*#$-4"/#0-1*#
G@+>1%!"& !"!*&"#."+!-4#'!-1%4#%--G#%(G"#+!"#,-%%-<()EH
!"#$%&'(&5.46!$&7!4.0&)'+%
Private Sub PopulateDataSet()
If File.Exists(xsdFile) Then
ds = New DataSet()
ds.ReadXmlSchema(xsdFile)
Else
CreateSchema()
End If
If File.Exists(xmlFile) Then
ds.ReadXml(xmlFile, XmlReadMode.IgnoreSchema)
End If
End Sub
# A"''-)#8H#I"*(&%(=&+(-)>#I6"$(&%(="4# :6"'>#&)4#J&+&#K()4()E# !"#$%&'(' ++
!"#$%&'(&)*&)'+%
private void PopulateDataSet()
{
if(File.Exists(xsdFile))
{
ds = new DataSet();
ds.ReadXmlSchema(xsdFile);
}
else
{
CreateSchema();
}
if(File.Exists(xmlFile))
{
ds.ReadXml(xmlFile, XmlReadMode.IgnoreSchema);
}
}
3+# B+#+!"#9-++-.#-,#+!"#/)&!"&*2C&;!#."+!-4>#*".-;"#+!"#$&%%#+-#:&55!8&6+<H*C+,#&)4#
&44#&#$&%%#+-#'&;"#+!"# !"!*&"#'$!".&#+-#%"/#0-1*#/)&!"&*2C&;!#."+!-4#'!-1%4#%--G#
%(G"#+!"#,-%%-<()EH
!"#$%&'(&5.46!$&7!4.0&)'+%
Private Sub CreateSchema()
ds = New DataSet("VehiclesRepairs")
Dim vehicles = ds.Tables.Add("Vehicles")
vehicles.Columns.Add("VIN", GetType(String))
vehicles.Columns.Add("Make", GetType(String))
vehicles.Columns.Add("Model", GetType(String))
vehicles.Columns.Add("Year", GetType(Integer))
vehicles.PrimaryKey = New DataColumn() {vehicles.Columns("VIN")}
Dim repairs = ds.Tables.Add("Repairs")
Dim pk = repairs.Columns.Add("ID", GetType(Integer))
pk.AutoIncrement = True
pk.AutoIncrementSeed = -1
pk.AutoIncrementStep = -1
repairs.Columns.Add("VIN", GetType(String))
repairs.Columns.Add("Description", GetType(String))
repairs.Columns.Add("Cost", GetType(Decimal))
repairs.PrimaryKey = New DataColumn() {repairs.Columns("ID")}
ds.Relations.Add( _
"vehicles_repairs", _
vehicles.Columns("VIN"), _
repairs.Columns("VIN"))
ds.WriteXmlSchema(xsdFile)
End Sub
!"#$%&'(&)*&)'+%
private void CreateSchema()
{
'+H !"#$%&'( BJM/NO #J('$-))"$+"4#7%&''"'
ds = new DataSet("VehiclesRepairs");
var vehicles = ds.Tables.Add("Vehicles");
vehicles.Columns.Add("VIN", typeof(string));
vehicles.Columns.Add("Make", typeof(string));
vehicles.Columns.Add("Model", typeof(string));
vehicles.Columns.Add("Year", typeof(int));
vehicles.PrimaryKey = new DataColumn[] { vehicles.Columns["VIN"] };
var repairs = ds.Tables.Add("Repairs");
var pk = repairs.Columns.Add("ID", typeof(int));
pk.AutoIncrement = true;
pk.AutoIncrementSeed = -1;
pk.AutoIncrementStep = -1;
repairs.Columns.Add("VIN", typeof(string));
repairs.Columns.Add("Description", typeof(string));
repairs.Columns.Add("Cost", typeof(decimal));
repairs.PrimaryKey = new DataColumn[] { repairs.Columns["ID"] };
ds.Relations.Add(
"vehicles_repairs",
vehicles.Columns["VIN"],
repairs.Columns["VIN"]);
ds.WriteXmlSchema(xsdFile);
}
*4+# B44#$-4"#+-#+!"#-+);EF4+!(#."+!-4#+-#9()4#T$-))"$+U#+!"#["!($%"'#4&+&#+&9%"#+-#
+!"#(89&C.2%&5#$-)+*-%#&)4#&44#$-4"#+-#9()4#+!"#;"!($%"'`*"6&(*'#*"%&+(-)'!(6#+-#+!"#
G(8'&>!.)5#$-)+*-%#&'#,-%%-<'H
!"#$%&'(&5.46!$&7!4.0&)'+%
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
PopulateDataSet()
dgVehicles.DataSource = ds
dgVehicles.DataMember = "Vehicles"
dgRepairs.DataSource = ds
dgRepairs.DataMember = "Vehicles.vehicles_repairs"
End Sub
!"#$%&'(&)*&)'+%
private void Form1_Load(object sender, EventArgs e)
{
PopulateDataSet();
dgVehicles.DataSource = ds;
dgVehicles.DataMember = "Vehicles";
dgRepairs.DataSource = ds;
dgRepairs.DataMember = "Vehicles.vehicles_repairs";
}
**+# B44#$-4"#+-#'&;"#+!"#4&+&#'"+#+-#+!"#?@A#3%"#<!")#R-*.X#('#$%-'()E/# -#&44#&#
#-+);EFG/%+5.78#";")+#!&)4%"*#."+!-4>#$%($G#+!"#R-*.X#aJ"'(E)b#+&9>#$%($G#+!"#+(+%"#9&*#-,#
# A"''-)#8H#I"*(&%(=&+(-)>#I6"$(&%(="4# :6"'>#&)4#J&+&#K()4()E# !"#$%&'(' +I
R-*.X#+-#'"%"$+#(+>#&)4#+!")>#()#+!"#S*-6"*+("'#<()4-<>#$%($G#+!"#O;")+#%(E!+)()E#9-%+#+-#
;("<#+!"#&;&(%&9%"#";")+'#,-*#R-*.X/#
*,+# P)#+!"#O;")+'#<()4-<>#4-19%"5$%($G#+!"#R-*.7%-'()E#";")+#+-#&44#+!"#";")+#!&)4%"*#
."+!-4#+-#:-1*#$-4"/#P)#+!('#."+!-4>#&44#$-4"#+-#'&;"#+!"#?@A#3%"#&'#,-%%-<'H
!"#$%&'(&5.46!$&7!4.0&)'+%
Private Sub Form1_FormClosing(ByVal sender As System.Object, _
ByVal e As FormClosingEventArgs) _
Handles MyBase.FormClosing
ds.WriteXml(xmlFile, XmlWriteMode.DiffGram)
End Sub
!"#$%&'(&)*&)'+%
private void Form1_FormClosing(
object sender, FormClosingEventArgs e)
{
ds.WriteXml(xmlFile, XmlWriteMode.DiffGram);
}
*-+# K1(%4#+!"#&66%($&+(-)/#M)#+!"#.&()#.")1>#$%($G#K1(%4#]#K1(%4#I-%1+(-)#+-#91(%4/#P,#:-1#
!&;"#"**-*'>#:-1#$&)#4-19%"5$%($G#+!"#"**-*#+-#E-#+-#+!"#"**-*#%()"#&)4#$-**"$+/
*.+# W1)#+!"#&66%($&+(-)/#M)#+!"#.&()#.")1>#$%($G#J"91E#]#J"91E#B66%($&+(-)#+-#*1)/#
B44#&#$-16%"#-,#;"!($%"'#&)4#+!")#E-#9&$G#+-#+!"#3*'+#;"!($%"#&)4#&44#'-."#*"6&(*'/#
#R(E1*"#X5c#'!-<'#&)#"D&.6%"#-,#<!&+#:-1*#'$*"")#'!-1%4#%--G#%(G"/
#
@ABC&%'(D*' !"#$-.6%"+"#&66%($&+(-)#('#'!-<)#!"*"#<(+!#+<-#;"!($%"'#&)4#+!"#*"6&(*'#,-*#+!"#'"%"$+"4#;"!($%"/
K%44'-& 6""!<3 !('#%"''-)#6*-;(4"4#4"+&(%"4#(),-*.&+(-)#&9-1+#'"*(&%(=&+(-)#&)4#4"'"*(&%(=&+(-)#-,#+!"#
#BJM/#NO #4('$-))"$+"4#$%&''"'#&'#<"%%#&'#&9-1+#!&)4%()E#'6"$(&%(="4#4&+&#+:6"'#()#&+&#'"+#
-*#4&+&#+&9%"/#R()&%%:>#+!('#$!&6+"*#6*-;(4"4#&)#-;"*;("<#-,#4&+	()4()E/
# # !"#$%&'-' H?
!" # $ % & ' -
@8:BCD2&)'--%09%+&)$!44%4
P)#+!"#6*";(-1'#$!&6+"*>#+!"#4('$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"$+(-)#'+*()E#+-#$*"&+"#&#$-))"$+(-)/# !"#,-%%-<()E#$-4"#'&.6%"#'!-<'#
!-<#3*'+#+-#$*"&+"#+!"#$-))"$+(-)#&)4#+!")#&''(E)#+!"#$-))"$+(-)#'+*()E/#Q(+!#&#;&%(4#$-)5
)"$+(-)#'+*()E>#:-1#$&)#-6")#+!"#$-))"$+(-)#&)4#"D"$1+"#$-..&)4'/#Q!")#:-1#&*"#3)('!"4#
<-*G()E#<(+!#+!"#$-))"$+(-)#-9L"$+>#:-1#.1'+#$%-'"#+!"#$-))"$+(-)#+-#,*""#16#+!"#*"'-1*$"'#
A"''-)#XH#7-))"$+()E#+-#+!"#J&+&#I+-*" !"#$%&'-' HI
9"()E#!"%4/#0-1#)""4#+!"#N-*+!<()4#'&.6%"#4&+&9&'"#+-#1'"#+!('#$-))"$+(-)/# !('#'&.6%"#4&5
+&9&'"#('#&;&(%&9%"#,*-.#+!"#@($*-'-,+#4-<)%-&4#'(+"#&)4#('#()$%14"4#<(+!#+!"#'&.6%"#."4(&/
!"#$%&'(&5.46!$&7!4.0&)'+%
Dim connection = new SqlConnection()
connection.ConnectionString = _
"Server=.;Database=northwind;Trusted_Connection=true"
connection.Open()
'Do lots of cool work here
connection.Close()
!"#$%&'(&)*&)'+%
var connection = new SqlConnection();
connection.ConnectionString =
"Server=.;Database=Northwind;Trusted_Connection=true";
connection.Open();
//Do lots of cool work here
connection.Close();
(&)!' 852#9'T%$!Q8'F%&PCP':#;<='JNQ UP
JC&@8:BCD2T&9G%&0'--%09.'-&0$!44%4&!$4'&."#$%"%-9&9G%&) (*+#*,!-%&.-9%<(!0%T&4'&3'6&0!-&
!$4'&+%Y-%&9G%&0'--%09.'-&.-&!&.*($/&M$'0U&!-+T&=G%-&3'6&%L.9&9G%&.*($/&M$'0UT&9G%&0'-Q
-%09.'-&=.$$&!69'"!9.0!$$3&M%&+.4#'4%+B&2G%& (*+#*%&"%9G'+&'-&9G%&0'--%09.'-&0!$$4&9G%&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"!$!5& !"#4&+&9&'"#+-#<!($!#+-#$-))"$+
6Q :6($&%%:#*","*'#+-#+!"#6!:'($&%#6&+!#+-#&+&#'-1*$"
!"#$%&:87)&)'--%09.'-& 9<.-/4
!"#,-%%-<()E#$-))"$+(-)#'+*()E#()'+*1$+'#+!"#+"D+#4*(;"*#+-#+*"&+#+!"#3%"'#%-$&+"4#()#+!"#
#7Ho# "'+o@:R-%4"*#'194(*"$+-*:#&'#+&9%"'#()#&+&9&'"/
Driver={Microsoft Text Driver (*.txt; *.csv)};
DBQ=C:\\Test\\MyFolder;
!"#$%&&%'()*#+%))"+,(%)#-,.()*#()-,./+,-#,!"#0++"--#1.(2".#,%#%3")#,!"#4%.,!'()1#15,56
75-"#8&"#&%+5,"1#()#,!"#9:;<.%*.5=#>(&"-;=?033#$%&1".@
Driver={Microsoft Access Driver (*.mdb)};
DBQ=C:\\program files\\myApp\\Northwind.mdb
!"#$%&&%'()*#+%))"+,(%)#-,.()*#/-"-#,!"#-",,()*-#,!5,#!52"#7"")#+%)8*/."1#5-#5#15,5#
-%/.+"#)5="#ABC4D#%)#,!"#+/.."),#=5+!()"@
DSN=My Application DataSource
!"#$%&&%'()*#(-#5#+%))"+,(%)#,%#5)#E.5+&"#15,575-"#%)#,!"#EF09GHI(J#-".2".-@# !"#)5="#
5)1#35--'%.1#5."#35--"1#()#5-#'"&&@
Driver={Microsoft ODBC for Oracle};
Server=ORACLE8i7;
UID=john;
PWD=s3$W%1Xz
# G"--%)#K:#9%))"+,()*#,%#,!"#B5,5#C,%."# !"#$%&'(' )*
!"#$%&&%'()*#+%))"+,(%)#-,.()*#/-"-#,!"#HL+".(2".#,%#%3")#,!"#M?N%%O@L&-#8&"@
Driver={Microsoft Excel Driver (*.xls)};
DBQ=C:\\Samples\\MyBook.xls
!"#$%&&%'()*#+%))"+,(%)#-,.()*#/-"-#,!"#CPG#C".2".#1.(2".#,%#%3")#,!"#4%.,!'()1#15,56
75-"#%)#M?C".2".Q#/-()*#,!"#35--"16()#/-".#)5="#5)1#35--'%.1@
DRIVER={SQL Server};
SERVER=MyServer;
UID=AppUserAccount;
PWD=Zx%7$ha;
DATABASE=Northwind;
!(-#+%))"+,(%)#-,.()*#/-"-#,!"#CPG#C".2".#1.(2".#,%#%3")#,!"#4%.,!'()1#15,575-"#%)#
M?C".2".#/-()*#CPG#C".2".#,./-,"1#-"+/.(,?@
DRIVER={SQL Server};
SERVER=MyServer;
Trusted_Connection=yes
DATABASE=Northwind;
!"#$%&'"$()"(*+,-.( !""/01'!"(21&'"$(
0)%,!".#+%==%)#7/,#"5.&(".#,"+!)%&%*?#/-"1#,%#5++"--#15,575-"-#(-#E7R"+,#G()O()*#5)1#
H=7"11()*#$%.#B5,575-"-#AEGHBND@# 57&"#S6T#1"-+.(7"-#,!"#=%-,#+%==%)#EBN9#+%))"+,(%)#
-,.()*#-",,()*-@
$"+,%'(-.'EGHBN#9%))"+,(%)#C,.()*#U"?'%.1-
/%012&3 3%4 &5#$526
!"!#$%&'() !"#)5="#%$#,!"#15,575-"#%.#3!?-(+5&#&%+5,(%)#%$#,!"#15,575-"#8&"@
*+,)#-!.) !"#3!?-(+5&#&%+5,(%)#%$#5#8&"#,!5,#+%),5()-#,!"#."5&#+%))"+,(%)#
-,.()*@
/)'0+0"#$)(&'+"1#234% V$#-",#,%#"'&)Q#.",.("2()*#,!"#+%))"+,(%)#-,.()*#.",/.)-#,!"#+%=3&","#
+%))"+,(%)#-,.()*#,!5,#'5-#%.(*()5&&?#3.%2(1"1@#V$#-",#,%#4!,0)Q#,!"#
+%))"+,(%)#-,.()*#'(&&#+%),5()#,!"#()$%.=5,(%)#,!5,#'5-#%.(*()5&&?#
3.%2(1"1Q#=()/-#,!"#-"+/.(,?#()$%.=5,(%)@
/'%5+6)' !"#2")1%.6-3"+(8+#1.(2".#,%#/-"#$%.#+%))"+,()*#,%#,!"#15,5#-,%."@
2)345/(*+,-.( !""/01'!"(21&'"$6
!(-#+%))"+,(%)#-,.()*#/-"-#,!"#-",,()*-#-,%."1#()#,!"#M?033B5,5@/1&"@# !"#@/1&#"L,")-(%)#
-,5)1-#$%.#&3+5)'0!,#6!"!#,+37@
FILE NAME=C:\Program Files\MyApp\MyAppData.udl
'78 !"#$%&'( 0BE@4H #9%))"+,"1#9&5--"-
!(-#+%))"+,(%)#-,.()*#/-"-#,!"#W",#1.(2".Q#'!(+!#(-#,!"#0++"--#1.(2".Q#5)1#%3")-#,!"#1"=%#
15,575-"#8&"@#F",.("2()*#,!"#+%))"+,(%)#-,.()*#$.%=#,!"#+%))"+,(%)#'(&&#.",/.)#,!"#+%))"+,(%)#
,!5,#'5-#%.(*()5&&?#35--"1#()Q#=()/-#,!"#-"+/.(,?#()$%.=5,(%)@
Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\Program Files\myApp\demo.mdb;
Persist Security Info=False
!"#$%&'"$()"(27+(2/&8/&( !""/01'!"(21&'"$(
!"#CPG#C".2".#3.%2(1".#")57&"-#?%/#,%#5++"--#CPG#C".2".#J@X#5)1#&5,".@#V$#?%/#)""1#,%#+%)6
)"+,#,%#CPG#C".2".#Y@Z#5)1#"5.&(".Q#/-"#,!"#EGHBN#3.%2(1".@# 57&"#S6[#1"-+.(7"-#,!"#=%-,#+%=6
=%)#CPG#C".2".#+%))"+,(%)#-,.()*#-",,()*-@
$"+,%'(-9' CPG#C".2".#9%))"+,(%)#C,.()*#U"?'%.1-#A)%,#+5-"#-")-(,(2"D
/%012&3 3%4 &5#$526
!"!#$%&'()8#966'8#966')008#
-)":%'7#966')008#$)'5)'
!"#)5="#%.#V<#511."--#%$#,!"#15,575-"#-".2".#AKSI#+!5.6
5+,".-#=5LD@# !"#1"$5/&,#(-#5)#).;"1#0"'+3<@
*!+,%5)'#/!'"3)' <.%2(1"-#-/33%.,#$%.#15,575-"#=(..%.()*#()#CPG#C".2".#
SXXZ#5)1#&5,".#AKSI#+!5.5+,".-#=5LD@# !"#1"$5/&,#(-#5)#
).;"1#0"'+3<@
9""!(= >*+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%'70"!"+%3#2 8#W0+6 !"#)5="#%$#,!"#+&("),#+%=3/,".#+%))"+,()*#,%#CPG#
C".2".#AKSI#+!5.5+,".-#=5LD@# !"#1"$5/&,#(-#3&,,@
G%3")?"#G%33)("+%3 `-"1#'(,!#CPG9GF@#a!")#-",#,%#"'&)Q#5)#()63.%+"--#+%)6
)"+,(%)#,%#CPG#C".2".#-!%/&1#7"#=51"@# !"#1"$5/&,#(-#
4!,0)@
H'!30!("+%3#R+36+3< 9%),.%&-#+%))"+,(%)#5--%+(5,(%)#'(,!#5)#")&(-,"1#
#$10").F#H'!30!("+%30FH'!30!("+%30F#d5&(1#25&/"-#5."#2.;,+(+"#
I3>+36Q#J?;,+(+"#I3>+36@# !"#1"$5/&,#(-#2.;,+(+"#I3>+36@
H'&0"$)'5)'G)'"+@(!") a!")#-",#,%#"'&)Q#,!"#,.5)-3%.,#&5?".#/-"-#CCG#,%#")+.?3,#
,!"#+!5))")1#7?35--#"L3&%.()*#,!"#+".,(8+5,"#+!5()#,%#
25&(15,"#,./-,@# !"#1"$5/&,#(-#4!,0)@
H1;)#$10").#X)'0+%3 C3"+(8"-#,!"#+&("),6-(1"#."3."-"),5,(%)#%$#CPG#C".2".#
,?3"-#,%#52%(1#3%,"),(5.%7&"=-#,!5,#+%/&1#+5/-"#5)#
533&(+5,(%)#,%#7."5O#($#5#1($$"."),#2".-(%)#%$#CPG#C".2".#
(-#/-"1@#<%--(7&"#25&/"-#5."#Q!")0"Q#$VQ#$)'5)'#YNNNQ#$VQ#
$)'5)'#YNNPQ#5)1#$VQ#$)'5)'#YNNU@# !"#1"$5/&,#(-#Q!")0"@#
I0)'#230"!3() a!")#-",#,%#"'&)Q#-,5.,-#5)#()-,5)+"#%$#CPG#HL3."--Q#/-()*#
,!"#+/.."),#/-".]-#5++%/),@# !"#1"$5/&,#(-#4!,0)@
2)345/(27+(2/&8/&( !""/01'!"(21&'"$6
!"#$%&&%'()*#+%))"+,(%)#-,.()*#+%))"+,-#,%#,!"#4%.,!'()1#15,575-"#%)#,!"#+/.."),#+%=6
3/,".#A&%+5&!%-,DQ#/-()*#(),"*.5,"1#-"+/.(,?@# !(-#+%))"+,(%)#=/-,#7"#=51"#'(,!()#TX#-"+%)1-#
%.#5)#"L+"3,(%)#'(&"#,!.%')@# !"#-"+/.(,?#()$%.=5,(%)#'(&&#)%,#7"#3".-(-,"1@
Persist Security Info=False;
Integrated Security=SSPI;
# G"--%)#K:#9%))"+,()*#,%#,!"#B5,5#C,%."# !"#$%&'(' 7.
database=northwind;
server=localhost;
Connect Timeout=30
!(-#)"L,#+%))"+,(%)#-,.()*#/-"-#,!"# 9<#-%+O",-#&(7.5.?#ABNMCCE94D#5)1#+%))"+,-#,%#
,!"#M?B745="#15,575-"#%)#,!"#+%=3/,".#&%+5,"1#5,#V<#511."--#KX@K@S@TQ#/-()*#3%.,#K[TT@#
0/,!"),(+5,(%)#(-#75-"1#%)#/-()*#K1I0)'3!.)#5-#,!"#/-".#)5="#5)1#?ZMW[6*\#5-#,!"#
#35--'%.1@#
Network Library=DBMSSOCN;
Data Source=10.1.2.3,1433;
Initial Catalog=MyDbName;
User ID=myUsername;
Password=x&1W$dF9
911)0:'"$(1!()(+!0)5(27+(-)1);)6/(<'5/(='1:(27+(,>4&/66
CPG#HL3."--#(-#5#$.""#15,575-"#3.%1/+,#,!5,#(-#"5-?#,%#()-,5&)1#/-"#5)1#(-#75-"1#%)#CPG#
C".2".#,"+!)%&%*?@#a!")#?%/]."#7/(&1()*#-=5&&#'"7-(,"-#5)1#-()*&"6/-".#533&(+5,(%)-Q#CPG#
HL3."--#(-#5#)5,/.5&#+!%(+"#1/"#,%#(,-#e9E<g#1"3&%?="),#+5357(&(,("-Q#."&(57(&(,?Q#5)1#!(*!6#
3".$%.=5)+"#")*()"@#V)#511(,(%)Q#CPG#HL3."--#15,575-"-#+5)#"5-(&?#7"#5,,5+!"1#,%#,!"#$/&&#
."&"5-"#%$#CPG#C".2".@#CPG#HL3."--#(-#()-,5&&"1#5-#35.,#%$#,!"#1"$5/&,#d(-/5&#C,/1(%#@4H #()-,5&6
&5,(%)Q#'!(+!#=5O"-#(,#5)#"L+"&&"),#15,575-"#,%#/-"#'!")#?%/]."#1"2"&%3()*#533&(+5,(%)-#
1"-,()"1#,%#7"#/-"1#%)#CPG#HL3."--#%.#CPG#C".2".@# %#5,,5+!#5#&%+5,575-"#8&"Q#?%/#+5)#/-"#
,!"#$%&&%'()*#+%))"+,(%)#-,.()*@
Data Source=.\SQLEXPRESS;
AttachDbFilename=C:\MyApplication\Northwind.MDF;
Integrated Security=True;
User Instance=True;
V)#,!(-#"L5=3&"Q#,!"#15,5#-%/.+"#(-#-",#,%#5)#()-,5)+"#%$#CPG#HL3."--#+5&&"1#@;CPGHe<FHCC@#
!"#15,575-"#8&"#)5="#(-#-",#,%#,!"#15,575-"#8&"#&%+5,"1#5,#9:;M?033&(+5,(%);4%.,!'()1@
MB>@#4%,"#,!5,#,!"#&%*#8&"#A4%.,!'()1hGEi@GB>D#=/-,#5&-%#"L(-,@#V),"*.5,"1#-"+/.(,?#5/,!")6
,(+5,"-#'(,!#CPG#HL3."--j#-",,()*#I0)'#230"!3()#,%#"'&)#-,5.,-#5)#()-,5)+"#%$#CPG#HL3."--Q#/-()*#
,!"#+/.."),#/-".]-#5++%/),@#
0&,!%/*!#?%/#+5)#/-"#CPG#C".2".#,%#5,,5+!#,%#5#&%+5&"Q#CPG#C".2".#1%"-#)%,#'%.O#'(,!#
,!"#I0)'#230"!3()]"'&)#-",,()*@#0&-%Q#CPG#C".2".#O""3-#,!"#15,575-"#5,,5+!"1#'!")#?%/.#536
3&(+5,(%)#")1-Q#-%#,!"#)"L,#,(="#?%/#./)#CPG#C".2".Q#5)#"L+"3,(%)#'(&"#,!.%')#7"+5/-"#,!"#
15,5#8&"#(-#5&."51?#5,,5+!"1@
0,,5+!BN>(&"#+5)#5&-%#/)1".-,5)1#,!"#O"?'%.1#\ !"! +')("%'1\#,%#/-"#,!"#533&(+5,(%)]-#
15,5#1(."+,%.?@#k"."#(-#,!"#."2(-"1#+%))"+,(%)#-,.()*@
Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\Northwind.MDF;
Integrated Security=True;
User Instance=True
'79 !"#$%&'( 0BE@4H #9%))"+,"1#9&5--"-
?!=( !"! #$%&"'$((@6(A/6!58/B
V),".)5&&?Q#,!"#C?-,"=@B5,5@1&&#&(7.5.?#+%),5()-#5#+&5--#+5&&"1#$10").F !"!FG%..%3
F >G%33)("+%3^;"+%30Q#'!(+!#!5-#5#=",!%1#+5&&"1#J?;!36 !"! +')("%'1@# !(-#=",!%1#()6
+&/1"-#+%1"#,!5,#."-%&2"-#,!"#A !"! +')("%'1A#O"?'%.1#7?#"L"+/,()*#+%1"#,!5,#&%%O-#-%="6
,!()*#&(O"#,!"#$%&&%'()*@
2)345/(!C(D'6%)5(.)6'0( !B/
Dim path = AppDomain.CurrentDomain.GetData("DataDirectory")
If string.IsNullOrEmpty(path)) Then
path = AppDomain.CurrentDomain.BaseDirectory
End If
Return path
2)345/(!C( E( !B/
var path = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
if (string.IsNullOrEmpty(path)))
{
path = AppDomain.CurrentDomain.BaseDirectory;
}
return path;
a!5,#1%"-#,!(-#="5)l# !"#J?;!36 !"! +')("%'1#=",!%1#,.("-#,%#*",#,!"#15,5#1(."+,%.?#
&%+5,(%)#$.%=#,!"#+/.."),#5--"=7&?@# !"#15,5#1(."+,%.?#(-#-",#$%.#"2".?#9&(+OE)+"#533&(+5,(%)#
()-,5&&"1#%)#5#&%+5&#+%=3/,".@#V,]-#&%+5,"1#()#,!"#/-".]-#B%+/="),-#0)1#C",,()*-#$%&1".@#V$#5#
15,575-"#8&"#A@=1$D#5)1#(,-#&%*#8&"#A@&1$D#5."#()+&/1"1#()#5#9&(+OE)+"#533&(+5,(%)#5)1#=5.O"1#5-#
5#^15,5_#8&"Q#,!"?#5."#+%3("1#,%#,!(-#1(."+,%.?#%)#533&(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#"&"="),#/)1".#,!"#m(%3@<&'!"+%3n#.%%,#"&"="),@#
!(-#-"+,(%)#-/33%.,-#,!"#m!66nQ#m').%5)nQ#5)1#m(,)!'n#,5*-Q#5-#-!%')#!".":
KL+(9445'0)1'!"( !"C'$%&)1'!"(<'5/
<connectionStrings>
<clear />
<add name="nw"
providerName="System.Data.SqlClient"
connectionString=
"Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|Northwind.MDF;
Integrated Security=True;
User Instance=True"/>
</connectionStrings>
!(-#"L5=3&"#+&"5.-#,!"#&(-,#%$#+%))"+,(%)#-",,()*-#,!5,#=(*!,#!52"#7"")#1"8)"1#()#,!"#
=5+!()"#+%)8*/.5,(%)#8&"#5)1#,!")#511-#5#)"'#+%))"+,(%)#-,.()*#-",,()*#+5&&"1#3:@# !"#+%)6
)"+,(%)#-,.()*-#+5)#7"#5++"--"1#()#+%1"#7?#/-()*#,!"#-,5,(+#G%33)("+%3$"'+3<0#+%&&"+,(%)#%)#
,!"#G%3@<&'!"+%3K!3!<)'#+&5--#A(=3&"="),"1#()#,!"#C?-,"=@9%)8*/.5,(%)@1&--"=7&?DQ#5-#
-!%')#()#,!"#$%&&%'()*#+%1"#-5=3&"@
2)345/(!C(D'6%)5(.)6'0( !B/
'Get the settings from the configuration file
Dim nw = ConfigurationManager.ConnectionStrings("nw")
'name = "nw"
Dim name = nw.Name
'provider = "System.Data.SqlClient"
Dim provider = nw.ProviderName
'cnString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|
' \Northwind.MDF;Integrated Security=True;User Instance=True"
Dim cnString = nw.ConnectionString
MessageBox.Show("From App.Config: " & cnString)
2)345/(!C( E( !B/
//Get the settings from the configuration file
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection(nw.ConnectionString);
//name = "nw"
var name = nw.Name;
//provider = "System.Data.SqlClient"
var provider = nw.ProviderName;
'7) !"#$%&'( 0BE@4H #9%))"+,"1#9&5--"-
//cnString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|
// \Northwind.MDF;Integrated Security=True;User Instance=True"
var cnString = nw.ConnectionString;
MessageBox.Show("From App.Config: " + cnString);
,"0&G41/B( !33%"'0)1'!"6(1!(27+(2/&8/& %#")57&"#")+.?3,"1#+%==/)(+5,(%)-#7",'"")#,!"#+&("),#5)1#CPG#C".2".Q#5#1(*(,5&#+".,(8+5,"#
=/-,#7"#()-,5&&"1#5,#CPG#C".2".Q#5)1#,!")#?%/#+5)#/-"#,!"#J3('1;"#-",,()*#()#,!"#+%))"+,(%)#
-,.()*#,%#,/.)#%)#")+.?3,(%)@
!"#$%&&%'()*#(-#5)#"L5=3&"#%$#5#+%))"+,(%)#-,.()*#,!5,#+5)#,/.)#%)#")+.?3,"1#
#+%==/)(+5,(%)-@
Data Source=.\SQLEXPRESS;
AttachDbFilename=C:\MyApplication\Northwind.MDF;
Integrated Security=True;
User Instance=True;
Encrypt=true
V$#?%/]."#/-()*#9oQ#1%)],#$%.*",#,!5,#?%/#=/-,#"-+53"#,!"#-,.()*-#'(,!#75+O-&5-!"-#7?#/-()*#
,'%#75+O-&5-!"-#A;;D#$%.#"5+!#-()*&"#75+O-&5-!Q#%.#7?#3."+"1()*#,!"#-,.()*#'(,!#5)#5,#ApD#-?=6
7%&#,%#,/.)#%$$#"-+53"#3.%+"--()*@# !"#J3('1;"#-",,()*#(-#-",#,%#"'&)#-%#,!5,#5&&#+%==/)(+5,(%)#
7",'"")#,!"#+&("),#5)1#,!"#-".2".#(-#")+.?3,"1@
21!&'"$(,"0&G41/B( !""/01'!"(21&'"$6('"(M/;(9445'0)1'!"6a"7#533&(+5,(%)-#1%)],#!52"#5)#033@+%)8*#8&"j#,!"?#!52"#5#a"7@+%)8*#8&"@#V,]-#+%==%)#
3.5+,(+"#,%#-,%."#+%))"+,(%)#-,.()*-#()#,!"#a"7@+%)8*#8&"@# !(-#=5O"-#(,#"5-?#,%#+!5)*"#
,!"#+%))"+,(%)#-,.()*#'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'**%&"#'*+"$#*,(N&!4/&1G
g%/#+5)#")+.?3,#,!"#a"7@+%)8*#8&"#7?#./))()*#,!"#d(-/5&#C,/1(%#@4H #+%==5)1#3.%=3,#5)1#
"L"+/,()*#,!"#$%&&%'()*#+%==5)1Q#-3"+($?()*#,!"#$/&#,!#,%#?%/.#'"7-(,"#$%&1".:
aspnet_regiis -pef "connectionStrings" "C:\...\EncryptWebSite"
4%,"#,!5,#,!"# !"#$-'(,+!#."b/(."-#?%/#,%#35--#,!"#3!?-(+5&#'"7-(,"#35,!Q#'!(+!#(-#,!"#&5-,#
35.5=",".@#N"#-/."#,%#2".($?#,!"#35,!#,%#?%/.#a"7@+%)8*#8&"@#
V$#+!5)*"-#5."#=51"#,%#,!"#(%33)("+%3$"'+3<0#-"+,(%)q$%.#"L5=3&"Q#($#5)%,!".#+%))"+,(%)#
(-#511"1#/-()*#,!"#i`V#,%%&-q,!"#)"'#+%))"+,(%)#'(&"#")+.?3,"1j#,!5,#(-Q#?%/#'%)],#!52"#
,%#./)#,!"#5-3)",h."*((-#/,(&(,?#5*5()@
g%/#+5)#1"+.?3,#,!"#(%33)("+%3$"'+3<0#-"+,(%)#7?#/-()*#,!"#$%&&%'()*#+%==5)1:
aspnet_regiis -pdf "connectionStrings" "C:\...\EncryptWebSite"
!""/01'!"(N!!5'"$9."5,()*#5#3!?-(+5&#+%))"+,(%)#,%#,!"#15,575-"#(-#5)#"L3")-(2"#,5-O@#9%))"+,(%)#3%%&()*#
(-#."/-()*#"L(-,()*#5+,(2"#+%))"+,(%)-#'(,!#,!"#-5="#+%))"+,(%)#-,.()*#()-,"51#%$#+."5,()*#
)"'#+%))"+,(%)-#'!")#5#."b/"-,#(-#=51"#,%#,!"#15,575-"@#V,#()2%&2"-#,!"#/-"#%$#5#+%))"+6
,(%)#=5)5*".#,!5,#(-#."-3%)-(7&"#$%.#=5(),5()()*#5#&(-,Q#%.#3%%&Q#%$#525(&57&"#+%))"+,(%)-#$%.#5#
*(2")#+%))"+,(%)#-,.()*@#C"2".5%%&-#"L(-,#($#1($$"."),#+%))"+,(%)#-,.()*-#5-O#$%.#+%))"+,(%)#
#3%%&()*@
a!")#,!"#+%))"+,(%)#=5)5*".#."+"(2"-#5#."b/"-,#$%.#5#)"'#+%))"+,(%)Q#(,#+!"+O-#()#,!"#
3%%&#+%.."-3%)1()*#,%#,!"#+%))"+,(%)#-,.()*#$%.#525(&57&"#+%))"+,(%)-@#V$#5#+%))"+,(%)#(-#
525(&57&"Q#(,#(-#.",/.)"1@#V$#)%#+%))"+,(%)-#5."#525(&57&"#5)1#,!"#=5L(=/=#3%%&#-(f"#!5-#)%,#
7"")#."5+!"1Q#5#)"'#+%))"+,(%)#(-#+."5,"1Q#511"1#,%#,!"#3%%&Q#5)1#.",/.)"1@#V$#,!"#=5L(=/=#
3%%&#-(f"#!5-#7"")#."5+!"1Q#,!"#+%))"+,(%)#."b/"-,#(-#511"1#,%#5#b/"/"#,%#'5(,#/),(#+%)6
)"+,(%)#7"+%="-#525(&57&"#5)1#(-#.",/.)"1@#V$#,!"#+%))"+,(%)#,(="6%/,#1"8)"1#()#,!"#+%))"+6
,(%)#-,.()*#"L3(."-Q#5)#"L+"3,(%)#(-#.5(-"1@#
9%))"+,(%)#3%%&()*#(-#+%),.%&&"1#7?#35.5=",".-#3&5+"1#(),%#,!"#+%))"+,(%)#-,.()*@# !"#$%&6
&%'()*#35.5=",".-#5$$"+,#3%%&()*:
■# G%33)("+%3#H+.)%&"
■# K+3#/%%,#$+L)
■# K!?#/%%,#$+L)
■# /%%,+3<
■# G%33)("+%3#O)0)"
■# Q%!6#R!,!3(+3<#H+.)%&"#SG%33)("+%3#Q+4)"+.)T
■# J3,+0"
!"-"#35.5=",".-#5."#1"8)"1#()# 57&"#S6[@#
'7< !"#$%&'( 0BE@4H #9%))"+,"1#9&5--"-
9;'B/(;G(N!!5(A%5/6
%#(=3&"="),#+%))"+,(%)#3%%&()*Q#?%/#=/-,#$%&&%'#5#$"'#./&"-@
■# !"#+%))"+,(%)#-,.()*#=/-,#7"#,!"#-5="#$%.#"2".?#/-".#%.#-".2(+"#,!5,#35.,(+(35,"-#()#
,!"#3%%&@#H5+!#+!5.5+,".#=/-,#=5,+!#()#,".=-#%$#&%'".+5-"#5)1#/33".+5-"#5-#'"&&@
■# !"#/-".#VB#=/-,#7"#,!"#-5="#$%.#"2".?#/-".#%.#-".2(+"#,!5,#35.,(+(35,"-#()#,!"#3%%&@#
H2")#($#?%/#-3"+($?#+3")<'!")6#0)(&'+"1]"'&)Q#,!"#a()1%'-#/-".#5++%/),#%$#,!"#3.%+"--#
1",".=()"-#3%%&#="=7".-!(3@#
■# !"#3.%+"--#VB#=/-,#7"#,!"#-5="@#V,#!5-#)"2".#7"")#3%--(7&"#,%#-!5."#+%))"+,(%)-#
5+.%--#3.%+"--"-Q#5)1#,!(-#&(=(,5,(%)#"L,")1-#,%#3%%&()*@
()% ' 1!%6' "6'02='+%6%>5$'?24$'>&2?'#22,56@A
N!!5'"$(0/&1)'"5G(:)6(1:/(3!61(8)5%/(=:/"('345/3/"1/B(!"()(M/;(6/&8/&(0!"#$%&/B(1!(
%6/(1:/(6)3/(0!""/01'!"(61&'"$(='1:(1:/(6)3/(%6/&()00!%"1(1!()00/66(1:/(B)1);)6/(;/0)%6/(
3)"G(=/;6'1/(%6/&6(='55(;/"/#1(C&!3(1:/(%6/(!C(1:/(4!!5J
M:/&/O6(1:/(N!!5P
9%))"+,(%)#3%%&()*#(-#5#+&("),6-(1"#,"+!)%&%*?@# !"#15,575-"#!5-#)%#(1"5#,!5,#%)"#%.#=%."#
+%))"+,(%)#3%%&-#=(*!,#7"#()2%&2"1#()#?%/.#533&(+5,(%)@#9&("),6-(1"#="5)-#,!5,#,!"#+%))"+6
,(%)#3%%&()*#,5O"-#3&5+"#%)#,!"#=5+!()"#()(,(5,()*#,!"# >G%33)("+%3#%7R"+,]-#^;)3#-,5,"="),@
M:/"(@6(1:/(N!!5( &/)1/BP
!"#+%))"+,(%)#3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'()1%'@#g%/.#533&(+5,(%)#5&."51?#
!5-#5)#033@9%)8*#8&"@#F(*!,6+&(+O#,!"#033@+%)8*#8&"#5)1#+&(+O#V)+&/1"#V)#<.%R"+,@
■# 5O'PBQRCK'QNEFG' VU#V)#C%&/,(%)#HL3&%.".Q#.(*!,6+&(+O#,!"#3.%R"+,#5)1#+&(+O#011#\#4"'#
V,"=#\#033&(+5,(%)#9%)8*/.5,(%)#>(&"#\#EU@#N"#-/."#,%#/-"#033@9%)8*#5-#,!"#8&"#
)5="@
.+# 011#,!"#+%))"+,(%)#-,.()*#,%#,!"#+%)8*#8&"@#V)-(1"#,!"#m(%3@<&'!"+%3n#"&"="),Q#511#
,!"#$%&&%'()*#+%))"+,(%)#-,.()*:
944J !"C'$( !""/01'!"
<connectionStrings>
<add name="db" connectionString=
"Data Source=.\SQLEXPRESS;Integrated Security=True" />
</connectionStrings>
!(-#+%))"+,(%)#-,.()*#."3."-"),-#5#=()(=/=#533.%5+!#,%#+%))"+,#,%#CPG#C".2".#HL6
3."--#%)#?%/.#&%+5&#=5+!()"Q#/-()*#,!"#1"$5/&,#15,575-"#-",,()*@# !"#1"$5/&,#15,575-"#
(-#/-/5&&?#,!"#=5-,".#15,575-"Q#'!(+!#"L(-,-#%)#5&".-(%)-#%$#CPG#C".2".@# !"#=5-,".#
15,575-"#-!%/&1#)%,#7"#/-"1#$%.#/-".61"8)"1#,57&"-Q#-%#,!"#+%))"+,(%)#-,.()*#'(&"#
=%1(8"1#()#,!"#)"L,#&"--%)Q#'!")#?%/#+."5,"#?%/.#15,575-"@
/+# 011#5#."$".")+"#,%#C?-,"=@9%)8*/.5,(%)@BGG@
0+# 011#,!"#$%&&%'()*#+&5--6&"2".(57&"#,%#,!"#,%3#%$#?%/.#a()1%'-#$%.=@# !(-#25.(57&"#
."$".")+"-#?%/.#+%))"+,(%)#-,.()*#5$,".#(,]-#."51#$.%=#,!"#+%)8*/.5,(%)#8&"@
G"--%)#K:#9%))"+,()*#,%#,!"#B5,5#C,%." !"#$%&'(' <:
2)345/(!C(D'6%)5(.)6'0( !B/
Private cnString As String
2)345/(!C( E( !B/
private string cnString;
1+# 0,#,!"#,%3#%$#,!"#*%'.MEQ%!6#"2"),#!5)1&".#=",!%1Q#511#+%1"#,%#.",.("2"#,!"#+%)6
)"+,(%)#-,.()*#$.%=#,!"#+%)8*/.5,(%)#8&"#5)1#=5O"#5#+5&&#,%#,!"#G=)(7G%33)("+5+"1#
=",!%1#?%/#'(&&#+."5,"#()#,!"#)"L,#-,"3@# !"#+%=3&","1#*%'.MEQ%!6#-!%/&1#&%%O#&(O"#
,!"#$%&&%'()*@
2)345/(!C(D'6%)5(.)6'0( !B/
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
cnString = ConfigurationManager _
.ConnectionStrings("db") _
.ConnectionString
CheckConnectivity()
PopulateDataSet()
dgVehicles.DataSource = ds
dgVehicles.DataMember = "Vehicles"
dgRepairs.DataSource = ds
dgRepairs.DataMember = "Vehicles.vehicles_repairs"
End Sub
2)345/(!C( E( !B/
private void Form1_Load(object sender, EventArgs e)
{
cnString = ConfigurationManager
.ConnectionStrings["db"]
.ConnectionString;
CheckConnectivity();
PopulateDataSet();
dgVehicles.DataSource = ds;
dgVehicles.DataMember = "Vehicles";
dgRepairs.DataSource = ds;
dgRepairs.DataMember = "Vehicles.vehicles_repairs";
}
()% ' "33'5?#2&$4'W V'* +,-X'>2&'6"?%4#" %4
<!&(1:/("/>1(61/4(1!(=!&I(4&!4/&5GF(G!%(3%61()BB(647'$"8(Q E(58#*,R(61)1/3/"16(C!&(
+(8"%49 !"!9+:1)1#%*"()"B(+(8"%49)'*;,5$!"#'*()1(1:/(1!4(!C(G!%&(0!B/J
2+# 011#,!"#G=)(7G%33)("+5+"1#=",!%1Q#'!(+!#'(&,,"=3,#,%#%3")#$a,G%33)("+%3Q#.",.("2"#
,!"#2".-(%)#%$#CPG#C".2".Q#5)1#.",/.)#,./"#%.#$5&-"Q#75-"1#%)#'!",!".#,!"#5,,"=3,#'5-#
-/++"--$/&@#4%,"#!%'#,!"#&0+3<#+%)-,./+,#")-/."-#,!5,#,!"#+%))"+,(%)#%7R"+,#(-#5&'5?-#
1(-3%-"1@#0#="--5*"#'(&"#1(-3&5?"1#,%#()1(+5,"#-/++"--#%.#$5(&/."@
()% "33'5?#2&$4'W V'* +,-X'>2&'6"?%4#" %4
<!&(1:/("/>1(61/4(1!(=!&I(4&!4/&5GF(G!%(3%61()BB(647'$"8(Q E(58#*,R(61)1/3/"16(C!&(
+(8"%49 !"!9+:1)1#%*"()"B(" +(8"%49)'*;,5$!"#'*()1(1:/(1!4(!C(G!%&(0!B/J
'<( !"#$%&'( 0BE@4H #9%))"+,"1#9&5--"-
2)345/(!C(D'6%)5(.)6'0( !B/
Private Function CheckConnectivity() As Boolean
Try
Using cn = New SqlConnection(cnString)
cn.Open()
Dim version = cn.ServerVersion
MessageBox.Show("Connectivity established! " & version)
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
End Try
Return True
End Function
2)345/(!C( E( !B/
private bool CheckConnectivity()
{
try
{
using (var cn = new SqlConnection(cnString))
{
cn.Open();
var version = cn.ServerVersion;
MessageBox.Show("Connectivity established! " + version);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
return true;
}
3+# V$#?%/#'"."#,%#./)#,!(-#3.%*.5=#5-#(,#(-#5)1#")1#,!"#3.%*.5=#'(,!%/,#511()*#5)?#15,5Q#
?%/#'%/&1#*",#5)#"..%.#()1(+5,()*#,!5,#,!"#?"5.#%$#,!"#2"!(+&"#+5))%,#7"#)/&&@# !(-#(-#7"6
+5/-"#?%/#5."#()#"1(,#=%1"#()#,!"#*.(1Q#5)1#?%/#!52")],#511"1#5)?#15,5@# %#!5)1&"#,!"#
"..%.#5#7(,#=%."#*.5+"$/&&?#'(,!%/,#=5-O()*#(,Q#511#5)#"..%.#!5)1&".#$%.#,!"#6<X)=+(,)#
*.(1#7?#-"&"+,()*#,!"#6<X)=+(,)0#*.(1#()#,!"#a()1%'-#>%.=-#1"-(*)".#5)1#,!")Q#()#,!"#
<.%3".,("-#'()1%'Q#+&(+O#,!"#H2"),-#A&(*!,)()*#7%&,D#7/,,%)@#V)#,!"# !"!J''%'#"2"),Q#,?3"#
GCEY%CCBC#5)1#3."--#H),".#,%#511#5)#"2"),#!5)1&".#=",!%1#,%#?%/.#+%1"@
V)#,!"#)"'#"2"),#!5)1&".#=",!%1Q#511#+%1"#,%#1(-3&5?#,!"#"..%.#*.5+"$/&&?@#g%/.#+%1"#
-!%/&1#&%%O#&(O"#,!"#$%&&%'()*@
2)345/(!C(D'6%)5(.)6'0( !B/
Private Sub gridError(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) _
Handles dgVehicles.DataError
MessageBox.Show(e.Exception.Message)
End Sub
G"--%)#K:#9%))"+,()*#,%#,!"#B5,5#C,%." !"#$%&'(' <.
2)345/(!C( E( !B/
private void gridError(object sender, DataGridViewDataErrorEventArgs e)
{
MessageBox.Show(e.Exception.Message);
}
*4+# %#!5)1&"#5)?#"..%.#,!5,#=(*!,#%++/.#()#,!"#7%,,%=#*.(1#*.5+"$/&&?Q#-"&"+,#,!"#
6<O);!+'0#*.(1#()#,!"#a()1%'-#>%.=-#1"-(*)".@
**+# V)#,!"#<.%3".,("-#'()1%'Q#-"&"+,#H2"),-@#
*,+# V)#,!"# !"!J''%'#3.%3".,?Q#+&(+O#,!"#1.%361%')#&(-,#5)1#-"&"+,#,!"#<'+6J''%'#=",!%1#?%/#
+."5,"1#()#,!"#3."2(%/-#-,"3@#
4%'Q#"(,!".#*.(1#'(&&#+5&&#,!"#"2"),#!5)1&".#=",!%1#($#"(,!".#%)"#!5-#5)#"..%.@
*-+# N/(&1#,!"#533&(+5,(%)#5)1#+%.."+,#5)?#"..%.-@
*.+# "-,#,!"#533&(+5,(%)@#<."--#>Z#,%#./)#,!"#533&(+5,(%)#'(,!#,!"#1"7/**".@#
a!")#,!"#533&(+5,(%)#-,5.,-Q#(,#'(&&#&%51#,!"#%$r()"#eMG#8&"#($#(,#"L(-,-@#V,#'(&&#,!")#+!"+O#
'!",!".#(,#+5)#+%))"+,#,%#CPG#C".2".@#V$#5#+%))"+,(%)#+5)#7"#=51"Q#?%/#'(&&#-""#5#
="--5*"#-,5,()*#,!5,#+%))"+,(2(,?#"L(-,-@#V$#?%/#+5)],#+%))"+,Q#?%/#'(&&#-""#,!"#"..%.#
="--5*"@
+/66!"(2%33)&G !(-#&"--%)#3.%2(1"1#5#1",5(&"1#%2".2("'#%$#,!"#0BE@4H #+%))"+,"1#+&5--"-@#
■# 9%))"+,"1#+&5--"-Q#5&-%#O)%')#5-#3.%2(1".#+&5--"-Q#5."#."-3%)-(7&"#$%.#=%2"="),#%$#
15,5#7",'"")#,!"#15,5#-,%."#5)1#,!"#1(-+%))"+,"1#+&5--"-@#0#25&(1#()-,5)+"#%$#5#+&5--#
1".(2"1#$.%=# >G%33)("+%3#(-#."b/(."1#,%#/-"#=%-,#%$#,!"#3.(=5.?#3.%2(1".#+&5--"-@
■# 9%))"+,(%)#-,.()*-#+5)#7"#-,%."1#()#,!"#033@+%)8*#8&"#%.Q#$%.#a"7#533&(+5,(%)-Q#,!"#
a"7@+%)8*#8&"@
■# a!")#'%.O()*#'(,!#a"7#533&(+5,(%)-Q#?%/#+5)#")+.?3,#,!"#+%))"+,(%)#-,.()*-#-,%."1#()#
,!"#a"7@+%)8*#8&"#7?#/-()*#,!"#5-3)",h."*((-@"L"#,%%&@
■# 9%))"+,(%)-#+5)#7"#3%%&"1#,%#3.%2(1"#$5-,".#525(&57(&(,?#5)1#7",,".#."/-"@
+/66!"(A/8'/=(g%/#+5)#/-"#,!"#$%&&%'()*#b/"-,(%)-#,%#,"-,#?%/.#O)%'&"1*"#%$#,!"#()$%.=5,(%)#()#G"--%)#KQ#
^9%))"+,()*#,%#,!"#B5,5#C,%."@_# !"#b/"-,(%)-#5."#5&-%#525(&57&"#%)#,!"#+%=35)(%)#9B#($#?%/#
3."$".#,%#."2("'#,!"=#()#"&"+,.%)(+#$%.=@
()% ' "641%&4
9"6=/&6(1!(1:/6/(U%/61'!"6()"B(/>45)")1'!"6(!C(=:G(/)0:()"6=/&(0:!'0/('6(0!&&/01(!&('"0!&V
&/01()&/(5!0)1/B('"(1:/(W9"6=/&6X(6/01'!"()1(1:/(/"B(!C(1:/(;!!IJ(
()% "641%&4
9"6=/&6(1!(1:/6/(U%/61'!"6()"B(/>45)")1'!"6(!C(=:G(/)0:()"6=/&(0:!'0/('6(0!&&/01(!&('"0!&V
&/01()&/(5!0)1/B('"(1:/(W9"6=/&6X(6/01'!"()1(1:/(/"B(!C(1:/(;!!IJ(
G"--%)#S:#F"51()*#5)1#a.(,()*#B5,5 !"#$%&'(' <;
,KNNBF'(U'&KMYEFG'MFY'1CEIEFG'3MIM
%#"L"+/,"#+%==5)1-#,%#,!"#15,575-"Q#?%/#=/-,#!52"#5)#%3")#+%))"+,(%)#5)1#5#+%==5)1#
%7R"+,@# !"#3."2(%/-#&"--%)#+%2"."1#+%))"+,(2(,?Q#5)1#,!(-#&"--%)#1"-+.(7"-#!%'#,%#+."5,"#5)1#
/-"#5#+%==5)1#%7R"+,@
9C1/&(1:'6(5/66!"F(G!%(='55(;/();5/(1!Y
■ V1"),($?#,!"#'5?-#,%#"L"+/,"#5#+%==5)1#,%#5#15,5#-,%."@
■ HL"+/,"#5#+%==5)1#,%#5#15,5#-,%."@
■ C")1#/315,"-#75+O#,%#,!"#15,5#-,%."@
■ `-"#,!"# >/'%5+6)'*!("%'161".(2"1#+&5--"-#,%#+."5,"#3.%2(1".65*)%-,(+#+%1"@
■ k5)1&"#"L+"3,(%)-#'(,!#5#,.?c+5,+!#7&%+O@
,61'3)1/B(5/66!"(1'3/Y(Z[(3'"%1/6
<)'44!*.(*;H/01g%/#/-"#,!"# >G%..!36#%7R"+,#,%#-")1#5#C,./+,/."1#P/".?#G5)*/5*"#ACPGD#+%==5)1#,%#,!"#
15,5#-,%."@# >G%..!36#+5)#7"#5#B5,5#M5)(3/&5,(%)#G5)*/5*"#ABMGD#+%==5)1#,%#.",.("2"Q#
()-".,Q#/315,"Q#%.#1"&","#15,5@# !"# >G%..!36#%7R"+,#+5)#5&-%#7"#5#B5,5#B"8)(,(%)#G5)6
*/5*"#ABBGD#+%==5)1Q#'!(+!#")57&"-#?%/#,%#+."5,"#,57&"-#5)1#=%1($?#-+!"=5#()$%.=5,(%)#
5,#,!"#15,575-"@# !"# >G%..!36#%7R"+,#."b/(."-#5#25&(1#%3")#+%))"+,(%)#,%#(--/"#,!"#+%=6
=5)1#,%#,!"#15,5#-,%."@#0# >G%33)("+%3#%7R"+,#+5)#7"#35--"1#(),%#,!"# >G%..!36#%7R"+,]-#
+%)-,./+,%.#%.#5,,5+!"1#,%#,!"# >G%..!36#%7R"+,]-#G%33)("+%3#3.%3".,?#5$,".# >G%..!36#
(-#+."5,"1Q#7/,#,!"#7"-,#'5?#,%#+."5,"#5# >G%..!36#%7R"+,#(-#,%#/-"#,!"#G')!")G%..!36#
=",!%1#%)#,!"# >G%33)("+%3#%7R"+,#-%#,!5,#3.%2(1".6-3"+(8+#+%1"#(-#&(=(,"1#,%#,!"#+."5,(%)#
%$#,!"# >G%33)("+%3#%7R"+,Q#5)1#,!"# >G%33)("+%3#%7R"+,#5/,%=5,(+5&&?#+."5,"-#,!"#533.%3.(6
5,"#3.%2(1".6-3"+(8+#+%==5)1#%7R"+,#7"!()1#,!"#-+")"@#
>G%..!36#5&-%#."b/(."-#5#25&(1#25&/"#$%.#(,-#G%..!36H)?"#5)1#G%..!36H1;)#3.%3".6
,("-@# !"#$%&&%'()*#+%1"#-5=3&"#-!%'-#!%'#,%#+."5,"#5)1#()(,(5&(f"#5# >G%..!36#%7R"+,@
2)345/(!C(D'6%)5(.)6'0( !B/
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "CustOrderHist"
'don't forget to close the connection!
2)345/(!C( E( !B/
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection(nw.ConnectionString);
var cmd = connection.CreateCommand();
9C1/&(1:'6(5/66!"F(G!%(='55(;/();5/(1!Y
■ V1"),($?#,!"#'5?-#,%#"L"+/,"#5#+%==5)1#,%#5#15,5#-,%."@
■ HL"+/,"#5#+%==5)1#,%#5#15,5#-,%."@
■ C")1#/315,"-#75+O#,%#,!"#15,5#-,%."@
■ `-"#,!"# >/'%5+6)'*!("%'161".(2"1#+&5--"-#,%#+."5,"#3.%2(1".65*)%-,(+#+%1"@
■ k5)1&"#"L+"3,(%)-#'(,!#5#,.?c+5,+!#7&%+O@
,61'3)1/B(5/66!"(1'3/Y(Z[(3'"%1/6
'<) !"#$%&'( 0BE@4H #9%))"+,"1#9&5--"-
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "CustOrderHist";
//don't forget to close the connection!
!(-#+%1"#+."5,"-#5# >G%33)("+%3 !"#$%& &'(& )* (+ )+*&(+%$ !, !"#$%%&'()$%- .'$
*+#$%%&'()$% !"#$%& )* &'$+ /*$0 &! %1$(&$ ( !"#$,,-%. !"#$%&2 3')%' )* (**)4+$0 &! ',.-
.'$ *+#$%%&'()$% !"#$%& 5/*& "$ !6$+$0 "$,!1$ (+7 %!55(+0 %(+ "$ */"5)&&$0- 8, )&
$9$%/&$* ( *&!1$0 61!%$0/1$2 &'$ #$,,-%./&0( 61!6$1&7 %!+&()+* &'$ +(5$ !, &'$ *&!1$0
61!%$0/1$2 3'$1$(* #$,,-%./12& )+0)%(&$* &'(& &')* )* ( %(:: &! ( *&!1$0 61!%$0/1$-
!"#$#%&'&$ !"#$%&'
;&!1$0 61!%$0/1$* &76)%(::7 1$</)1$ 6(1(5$&$1 =(:/$* &! "$ 6(**$0 &! &'$5 &! $9$%/&$- >!1
$9(56:$2 ( *&!1$0 61!%$0/1$ %(::$0 ?/*&@10$1A)*&35)4'& 1$</)1$ ( %/*&!5$1 )0$+&)B%(&)!+ &!
1$&1)$=$ )+,!15(&)!+ ("!/& &'$ (661!61)(&$ %/*&!5$1- C!/ %(+ %1$(&$ 14(&,5*-(-53#$,,$%
5*+6-7-,&(&7 !"#$%&* "7 /*)+4 &'$ 6-7-,&(&7458.. 5$&'!0 !+ &'$ #$,,-%. !"#$%&2 (*
*'!3+ '$1$-
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "CustOrderHist"
Dim parm = cmd.CreateParameter()
parm.ParameterName = "@Id"
parm.Value = "ANATR"
cmd.Parameters.Add(parm)
Dim id = cmd.Parameters("@Id").Value
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection();
connection.ConnectionString = nw.ConnectionString;
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "CustOrderHist";
DbParameter parm = cmd.CreateParameter();
parm.ParameterName = "@Id";
parm.Value = "ANATR";
cmd.Parameters.Add(parm);
.')* %!0$ %1$(&$* ( *+#$%%&'()$% !"#$%& (+0 ( *+#$,,-%. !"#$%&- 8& (:*! %!+B4/1$*
&'$ *+#$,,-%. !"#$%& &! $9$%/&$ ( *&!1$0 61!%$0/1$ %(::$0 /*6D$&?/*&!5$1E7802 3')%'
1$</)1$* ( *)+4:$ 6(1(5$&$1 %(::$0 9:. &'(& )* (**)4+$0 &'$ =(:/$ ;8<8/=5>
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' )*
!"#' #"&"+%$%&,'"&%'-.//%&%0$'1",%-'20'$!%'#&23.-%&
67$ (89 +:-;04$: :$<10:$' &7$ +):)*$&$: =)*$' &- *)&%7 &7$ +):)*$&$: =)*$' 4$>=$4 0=
&7$ '&-:$4 +:-%$41:$? 67$ %:$)&0-= -. &7$ +):)*$&$:' 0' &7$:$.-:$ =-& -:4$: 4$+$=4$=&?
67$ ()& ! +:-;04$:@ 7-A$;$:@ :$<10:$' &7$ +):)*$&$:' &- "$ 4$>=$4 0= &7$ ')*$ -:4$: )'
&7$B ):$ 0= &7$ '&-:$4 +:-%$41:$? 670' *$)=' &7$ =)*$ )''0C=$4 &- &7$ +):)*$&$: =$$4 =-&
*)&%7 &7$ =)*$ 4$>=$4 0= &7$ '&-:$4 +:-%$41:$?
C!/ %(+ /*$ &'$ +(5$ (**)4+$0 &! &'$ *+6-7-,&(&7 !"#$%& &! (%%$** &'$ 6(1(5$&$1
&'1!/4' %!0$- >!1 $9(56:$2 &! 1$&1)$=$ &'$ =(:/$ %/11$+&:7 )+ &'$ 9:. ;LF 6(1(5$&$12 /*$ &'$
,!::!3)+4 %!0$H
()*+,$ -. /0'1), 2)'0% 3-4$
Dim id = cmd.Parameters("@Id").Value
()*+,$ -. 35 3-4$
var id = (string)cmd.Parameters["@Id"].Value;
*+&,-'&./01-&$2 D$&7-4
C!/ $9$%/&$ ( *+#$,,-%. !"#$%& 0),,$1$+&:7 0$6$+0)+4 !+ &'$ 0(&( "$)+4 1$&1)$=$0
!1 5!0)B$0 !1 &'$ 0(&("(*$ !"#$%& 7!/ (1$ %1$(&)+42 (:&$1)+42 !1 01!66)+4- C!/ /*$ &'$
?0&'@(&<$%A@&71 5$&'!0 3'$+ 7!/ 0!+M& $96$%& ( %!55(+0 &! 1$&/1+ (+7 1!3*N(+ )+*$1&2
/60(&$2 !1 0$:$&$ </$172 ,!1 $9(56:$- .')* 5$&'!0 1$&/1+* (+ )+&$4$1 &'(& 1$61$*$+&* &'$
+/5"$1 !, 1!3* (,,$%&$0 "7 &'$ !6$1(&)!+- .'$ ,!::!3)+4 $9(56:$ $9$%/&$* ( ;LF %!55(+0
&! (00 OPQ &! &'$ /+)& 61)%$ !, &'$ 61!0/%& 3'!*$ R1!0/%&8K )* OP2 (+0 )& 1$&/1+* &'$ +/5"$1
!, 1!3* &'(& 3$1$ /60(&$0-
()*+,$ -. /0'1), 2)'0% 3-4$
Private Sub menuExecuteNonQuery_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles ExecuteNonQueryToolStripMenuItem.Click
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim count As Integer = 0
Using connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = _
"UPDATE Products SET UnitPrice = UnitPrice * 1.1 WHERE ProductID = 10"
connection.Open()
count = cmd.ExecuteNonQuery()
End Using
MessageBox.Show(count.ToString())
End Sub
()*+,$ -. 35 3-4$
private void menuExecuteNonQuery_Click(object sender, EventArgs e)
{
!"# #"&"+%$%&,'"&%'-.//%&%0$'1",%-'20'$!%'#&23.-%&
67$ (89 +:-;04$: :$<10:$' &7$ +):)*$&$: =)*$' &- *)&%7 &7$ +):)*$&$: =)*$' 4$>=$4 0=
&7$ '&-:$4 +:-%$41:$? 67$ %:$)&0-= -. &7$ +):)*$&$:' 0' &7$:$.-:$ =-& -:4$: 4$+$=4$=&?
67$ ()& ! +:-;04$:@ 7-A$;$:@ :$<10:$' &7$ +):)*$&$:' &- "$ 4$>=$4 0= &7$ ')*$ -:4$: )'
&7$B ):$ 0= &7$ '&-:$4 +:-%$41:$? 670' *$)=' &7$ =)*$ )''0C=$4 &- &7$ +):)*$&$: =$$4 =-&
*)&%7 &7$ =)*$ 4$>=$4 0= &7$ '&-:$4 +:-%$41:$?
')) !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
var nw = ConfigurationManager.ConnectionStrings["nw"];
int count = 0;
using (var connection = new SqlConnection())
{
connection.ConnectionString = nw.ConnectionString;
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"UPDATE Products SET UnitPrice = UnitPrice * 1.1 WHERE ProductID =
connection.Open();
count = cmd.ExecuteNonQuery();
}
MessageBox.Show(count.ToString());
}
*+&,-'&3&$ D$&7-4
.'$ ?0&'@(&=&-.&7 5$&'!0 1$&/1+* ( *+*-(-=&-.&7 )+*&(+%$- V*+*-(-=&-.&7 )* %!=$1$0
)+ 5!1$ 0$&(): )+ &'$ +$9& *$%&)!+-W .'$ *+*-(-=&-.&7 !"#$%& )* ( ,!13(10X!+:72 1$(0X
!+:72 *$1=$1X*)0$ %/1*!1- *+*-(-=&-.&7 !"#$%&* %(+ "$ %1$(&$0 !+:7 "7 $9$%/&)+4 !+$ !,
&'$ ?0&'@(&=&-.&7 5$&'!0* !+ &'$ *+#$,,-%. !"#$%&- .'$ ,!::!3)+4 $9(56:$ /*$* &'$
?0&'@(&=&-.&7 5$&'!0 &! %1$(&$ ( *+*-(-=&-.&7 !"#$%& 3)&' &'$ *$:$%&)!+ 1$*/:&* (+0 &'$+
%!+&)+/!/*:7 :!!6* &'1!/4' &'$ 1$*/:&* /+&): &'$ $+0 !, 0(&( '(* "$$+ 1$(%'$0 V3'$+ &'$ =&-.
5$&'!0 1$&/1+* B-"4&W-
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT ProductID, UnitPrice FROM Products"
connection.Open()
Dim rdr = cmd.ExecuteReader()
While (rdr.Read())
MessageBox.Show(rdr("ProductID") & ": " & rdr("UnitPrice"))
End While
connection.Close()
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection();
connection.ConnectionString = nw.ConnectionString;
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT ProductID, UnitPrice FROM Products";
connection.Open();
DbDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
MessageBox.Show(rdr["ProductID"] + ": " + rdr["UnitPrice"]);
}
connection.Close();
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' )4
*+&,-'&5,#)#$ D$&7-4
L/$1)$* (1$ !,&$+ $96$%&$0 &! 1$&/1+ ( *)+4:$ 1!3 3)&' ( *)+4:$ %!:/5+- 8+ &'$*$ *)&/(&)!+*2
&'$ 1$*/:&* %(+ "$ &1$(&$0 (* ( *)+4:$ 1$&/1+ =(:/$- >!1 $9(56:$2 &'$ ,!::!3)+4 ;LF 1$&/1+* (
1$*/:& &'(& %!+*)*&* !, ( *)+4:$ 1!3 3)&' ( *)+4:$ %!:/5+-
()*+,$ (89 (&)&$*$=&
SELECT COUNT(*) FROM Products
8, 7!/ /*$ &'$ ?0&'@(& '-"-7 5$&'!02 &'$ -TU. >1(5$3!1Y 1/+ &)5$ 3):: +!& )+%/1 &'$ !=$1X
'$(0 &! 61!0/%$ !"#$%&* &'(& 1$(0 &'$ 1$*/:& *&1$(52 3')%' 5$(+* :$** 1$*!/1%$ /*(4$ (+0
"$&&$1 6$1,!15(+%$- .'$ ,!::!3)+4 %!0$ *'!3* '!3 &! /*$ &'$ ?0&'@(& '-"-7 5$&'!0 &! $(*):7
1$&1)$=$ &'$ +/5"$1 !, 1!3* )+ &'$ ;(:$* &(":$ 0)1$%&:7 )+&! ( =(1)(":$ %(::$0 '$@%(-
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT COUNT(*) FROM Products"
connection.Open()
Dim count = cmd.ExecuteScalar()
connection.Close()
MessageBox.Show(count.ToString())
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection();
connection.ConnectionString = nw.ConnectionString;
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT COUNT(*) FROM Products";
connection.Open();
int count = (int)cmd.ExecuteScalar();
connection.Close();
MessageBox.Show(count.ToString());
T!&)%$ '!3 5/%' *)56:$1 &')* )* &! )56:$5$+& &'(+ &'$ 61$=)!/* $9(56:$2 3')%' /*$0
?0&'@(&=&-.&7- 8, 7!/ %(+ /*$ &')* (661!(%'2 7!/ *'!/:0-
! #'#3&$ !"#$%&S *+*-(-=&-.&7 !"#$%& 61!=)0$* ( ')4'X6$1,!15(+%$ 5$&'!0 !, 1$&1)$=)+4 0(&( ,1!5
&'$ 0(&( *&!1$- 8& 0$:)=$1* ( ,!13(10X!+:72 1$(0X!+:72 *$1=$1X*)0$ %/1*!1- .')* 5(Y$* &'$
*+*-(-=&-.&7 !"#$%& (+ )0$(: %'!)%$ ,!1 6!6/:(&)+4 C)4(D$0 !"#$%&* (+0 *7$2*$E%C)4( !"X
#$%&*- J'$+ 7!/ 1/+ 1$6!1&*2 7!/ %(+ /*$ &'$ *+*-(-=&-.&7 !"#$%& &! 1$&1)$=$ &'$ 0(&( ,1!5
&'$ 0(&( *&!1$2 "/& )& 5)4'& +!& "$ ( 4!!0 %'!)%$ 3'$+ 7!/ (1$ %!0)+4 (+ !6$1(&)!+ &'(&
5!0)B$* 0(&( (+0 +$$0* &! *$+0 &'$ %'(+4$* "(%Y &! &'$ 0(&("(*$- >!1 0(&( 5!0)B%(&)!+*2
&'$ *+*-(-8.-2(&7 !"#$%&2 3')%' )* %!=$1$0 )+ &'$ +$9& *$%&)!+2 5)4'& "$ ( "$&&$1 %'!)%$-
'45 !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
.'$ *+*-(-=&-.&7 !"#$%& %!+&()+* ( =&-. 5$&'!0 &'(& 1$&1)$=$* 0(&( )+&! )&* "/,,$1- @+:7
!+$ 1!3 !, 0(&( )* $=$1 (=():(":$ (& ( &)5$2 3')%' 5$(+* &'(& (:: &'$ 0(&( ,1!5 &'$ 0(&("(*$
0!$* +!& +$$0 &! "$ %!56:$&$:7 1$(0 )+&! &'$ (66:)%(&)!+ "$,!1$ )& )* 61!%$**$0- >!1 $9(56:$2
&'$ *(56:$ %!0$ )+ &'$ 61$=)!/* *$%&)!+ %1$(&$0 ( *+*-(-=&-.&7 (+0 :!!6$0 &'1!/4' &'$
0(&(2 /*)+4 ( EF)"& :!!6 &'(& %!/:0 '(=$ $9)&$0 ,1!5 &'$ :!!62 6$+0)+4 *!5$ %!+0)&)!+ "$X
)+4 5$&- .')* $9(56:$2 '!3$=$12 6!6/:(&$* ( +$3 *-(-/-+"& !"#$%& 0)1$%&:7 3)&' &'$ :)*& !,
R1!0/%&* ,1!5 &'$ T!1&'3)+0 0(&("(*$- .'$ &(":$ )* &'$+ "!/+0 &! ( #$,+$D$0 !"#$%& %(::$0
',+67$.@'(4-
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT ProductID, ProductName FROM Products"
connection.Open()
Dim rdr = cmd.ExecuteReader()
Dim products As New DataTable()
products.Load(rdr, LoadOption.Upsert)
connection.Close()
cmbProducts.DataSource = products
cmbProducts.DisplayMember = "ProductName"
cmbProducts.ValueMember = "ProductID"
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection();
connection.ConnectionString = nw.ConnectionString;
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT ProductID, ProductName FROM Products";
connection.Open();
var rdr = cmd.ExecuteReader();
var products = new DataTable();
products.Load(rdr, LoadOption.Upsert);
connection.Close();
cmbProducts.DataSource = products;
cmbProducts.DisplayMember = "ProductName";
cmbProducts.ValueMember = "ProductID";
.'$ *-(-/-+"& !"#$%&M* C$-. 5$&'!0 '(* ( C$-.G2()$% 6(1(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 (+ :%I-").G2&7-()$%?0'&2()$%2
*&(&)+42 ].'$1$ )* (:1$(07 (+ !6$+ K(&(I$(0$1 (**!%)(&$0 3)&' &')* ?!++$%&)!+ 3')%' 5/*& "$
%:!*$0 B1*&- C!/ %(+ (=!)0 &')* $9%$6&)!+ "7 *$&&)+4 &'$ N@"()2"&8'()I&=&4@"( &(4 %!++$%&)!+
*&1)+4 !6&)!+ &! (7@& 3'$+ %!++$%&)+4 &! [/:&)6:$ S%&)=$ I$*/:& ;$&* V[SI;W_$+(":$0 '!*&*
*/%' (* ;LF ;$1=$1 GPPZ (+0 :(&$1- >!1 $9(56:$2 &'$ ,!::!3)+4 %!++$%&)!+ *&1)+4 *'!3* '!3
&')* *$&&)+4 )* (00$0 )+&! ( +$3 %!++$%&)!+ *&1)+4 %(::$0 %EN-74-
LD9 F++,0%)&0-= 3-=.0C1:)&0-= M0,$
<connectionStrings>
<clear />
<add name="nw"
providerName="System.Data.SqlClient"
connectionString=
"Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|Northwind.MDF;
Integrated Security=True;
User Instance=True"/>
<add name="nwMars"
'4( !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
providerName="System.Data.SqlClient"
connectionString=
"Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|Northwind.MDF;
Integrated Security=True;
User Instance=True;
MultipleActiveResultSets=True"/>
</connectionStrings>
[SI; 0!$* +!& 61!=)0$ (+7 6$1,!15(+%$ 4()+*2 "/& )& 0!$* *)56:),7 7!/1 %!0)+4 $,,!1&*-
.')+Y !, ( *%$+(1)! )+ 3')%' 7!/ $9$%/&$ ( </$17 &! 4$& ( :)*& !, *&!1$*2 (+02 3'):$ 7!/ :!!6
&'1!/4' ( :)*& !, *&!1$* &'(& (1$ 1$&/1+$02 7!/ 3(+& &! $9$%/&$ ( *$%!+0 </$17 &! 4$& &'$ &!&(:
</(+&)&7 !, "!!Y* *!:0-
!"#' 1%' "&%/:7'"12:$':,.0;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$ 0(&("(*$- J)&'!/& [SI;2 7!/ 3!/:0 '(=$ &!
!6$+ ( *$6(1(&$ %!++$%&)!+ &! &'$ 0(&("(*$ ,!1 $(%' %!55(+0 &'(& +$$0* &! 1/+ (& &'$ *(5$
&)5$2 3')%' 5$(+* &'(& 7!/ 5)4'& +$$0 &! 6/1%'(*$ 5!1$ %:)$+& :)%$+*$*-
.'$ ,!::!3)+4 %!0$ *(56:$ *'!3* '!3 [SI; %(+ 6$1,!15 &'$ +$*&$0 </$1)$*2 /*)+4 &'$
?/*&!5$1* &(":$ &! 1$&1)$=$ &'$ %!/+& !, @10$1* 6:(%$0 ,!1 $(%' %/*&!5$1-
()*+,$ -. /0'1), 2)'0% 3-4$
Private Sub menuMars_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MARSToolStripMenuItem.Click
Dim nw = ConfigurationManager.ConnectionStrings("nwMars")
Using connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT CustomerID, CompanyName FROM Customers"
connection.Open()
Dim rdr = cmd.ExecuteReader()
!"# 1%' "&%/:7'"12:$':,.0;'+"&,
DFG( 0' =-& +$:.-:*)=&N 0& 0' ) .$)&1:$ &7)& %)= '0*+,0.B &7$ %-4$ A70,$ *0=0*0O0=C &7$
<1)=&0&B -. %-==$%&0-=' &- &7$ '$:;$:?
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' 4<
While rdr.Read()
Dim OrdersCmd = connection.CreateCommand()
OrdersCmd.CommandType = CommandType.Text
OrdersCmd.CommandText = _
"SELECT COUNT(OrderID) FROM Orders WHERE (CustomerID = @CustId)"
Dim parm = OrdersCmd.CreateParameter()
parm.ParameterName = "@CustId"
parm.Value = rdr("CustomerID")
OrdersCmd.Parameters.Add(parm)
Dim qtyOrders = OrdersCmd.ExecuteScalar()
MessageBox.Show( _
rdr("CompanyName").ToString() + ": " + qtyOrders.ToString())
End While
End Using
End Sub
()*+,$ -. 35 3-4$
private void menuMars_Click(object sender, EventArgs e)
{
var nw = ConfigurationManager.ConnectionStrings["nwMars"];
using(var connection = new SqlConnection())
{
connection.ConnectionString = nw.ConnectionString;
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
connection.Open();
var rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var ordersCmd = connection.CreateCommand();
ordersCmd.CommandType = CommandType.Text;
ordersCmd.CommandText =
"SELECT COUNT(OrderID) FROM Orders WHERE (CustomerID = @CustId)";
var parm = ordersCmd.CreateParameter();
parm.ParameterName = "@CustId";
parm.Value = rdr["CustomerID"];
ordersCmd.Parameters.Add(parm);
var qtyOrders = ordersCmd.ExecuteScalar();
MessageBox.Show(rdr["CompanyName"].ToString() + ": "
+ qtyOrders.ToString());
}
}
}
P$:.-:*0=C 21,Q 3-+B !+$:)&0-=' A0&7 ) 56)7-)89/:2 !"#$%& @,&$+2 7!/ +$$0 &! %!67 :(14$ (5!/+&* !, 0(&( ,1!5 !+$ :!%(&)!+ &! (+!&'$1- [!*& !, &'$ 0(X
&("(*$ *$1=$1* 61!=)0$ ( 5$(+* &! %!67 ,1!5 !+$ 0(&("(*$ &! (+!&'$12 $)&'$1 "7 ( J)+0!3*
D\8 )+&$1,(%$ */%' (* &'$ ;LF ;$1=$1 U+&$161)*$ [(+(4$1 !1 "7 ( %!55(+0X:)+$ &!!: */%' (*
&'$ ;LF ;$1=$1 E/:Y ?!67 R1!41(5 VE?R-$9$W- 8+ (00)&)!+ &! /*)+4 &'$ &!!:* 61!=)0$0 "7 &'$
'4= !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
0(&("(*$ =$+0!12 7!/ (:*! %(+ 31)&$ 7!/1 !3+ "/:Y %!67 61!41(52 /*)+4 &'$ !"D@"Q#$21
%:(**-
.'$ !"D@"Q#$21 %:(** 61!=)0$* ( ')4'X6$1,!15(+%$ 5$&'!0 ,!1 %!67)+4 0(&( &! ( &(":$
)+ ( ;LF ;$1=$1 0(&("(*$- .'$ *!/1%$ !, &'$ %!67 )* %!+*&1()+$0 "7 &'$ !=$1:!(0* !, &'$
R7)(&/$ &7I&7 5$&'!02 3')%' %(+ (%%$6& (+ (11(7 !, *-(-=$E !"#$%&*2 (+ !"#$%& &'(& )56:$X
5$+&* &'$ :*-(-=&-.&7 )+&$1,(%$2 ( *-(-/-+"& !"#$%&2 !1 *-(-/-+"& (+0 *-(-=$E (-(&2 (*
*'!3+ )+ >)4/1$ GXG- .')* =(1)$&7 !, 6(1(5$&$1* 5$(+* 7!/ %(+ 1$&1)$=$ 0(&( ,1!5 5!*&
:!%(&)!+*-
WriteToServer( )
SqlBulkCopy Class
DataRow ArrayDataTable
IDataReaderDataTable, DataRowState
DatabaseServer
XMLDocument
SQL Server
/.;:&%'(8(' .'$ !"D@"Q#$21 !"#$%& %(+ %!67 ,1!5 ( =(1)$&7 !, *!/1%$* &! ,):: /6 ( ;LF ;$1=$1 &(":$-
.'$ ,!::!3)+4 %!0$ *'!3* '!3 7!/ %(+ /*$ ( !"D@"Q#$21 !"#$%& &! %!67 0(&( ,1!5 &'$
?/*&!5$1* &(":$ )+ &'$ T!1&'3)+0 0(&("(*$ &! &'$ ?/*&!5$1F)*& &(":$ )+ ( ;LF ;$1=$1 0(&(X
"(*$ %(::$0 D@"Q#$21-
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim nwConnection = New SqlConnection()
nwConnection.ConnectionString = nw.ConnectionString
Dim bulkCopy = ConfigurationManager.ConnectionStrings("BulkCopy")
Dim bulkConnection = New SqlConnection()
bulkConnection.ConnectionString = bulkCopy.ConnectionString
Dim cmd = nwConnection.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT CustomerID, CompanyName FROM Customers"
nwConnection.Open()
bulkConnection.Open()
Dim rdr = cmd.ExecuteReader()
Dim bc As New SqlBulkCopy(bulkConnection)
bc.DestinationTableName = "StoreList"
bc.WriteToServer(rdr)
nwConnection.Close()
bulkConnection.Close()
MessageBox.Show("Done with bulk copy")
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var nwConnection = new SqlConnection();
nwConnection.ConnectionString = nw.ConnectionString;
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' 49
var bulkCopy = ConfigurationManager.ConnectionStrings["BulkCopy"];
var bulkConnection = new SqlConnection();
bulkConnection.ConnectionString = bulkCopy.ConnectionString;
var cmd = nwConnection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
nwConnection.Open();
bulkConnection.Open();
var rdr = cmd.ExecuteReader();
var bc = new SqlBulkCopy(bulkConnection);
bc.DestinationTableName = "CustomerList";
bc.WriteToServer(rdr);
nwConnection.Close();
bulkConnection.Close();
MessageBox.Show("Done with bulk copy");
?!+*)0$1 /*)+4 &'$ :*-(-=&-.&7 !=$1:!(0 3'$+$=$1 6!**)":$ &! 4$& &'$ "$*& 6$1,!15(+%$
/*)+4 &'$ :$(*& 1$*!/1%$*- C!/ %(+ 0$%)0$ '!3 5/%' 0(&( *'!/:0 "$ %!6)$0 "(*$0 !+ &'$
</$17 7!/ /*$- >!1 $9(56:$2 &'$ 61$%$0)+4 %!0$ *(56:$ 1$&1)$=$0 !+:7 &'$ *&!1$ +(5$* (+0
%!/:0 '(=$ '(0 ( JAUIU %:(/*$ &! :)5)& &'$ 0(&( ,/1&'$1-
! #'#;4#:'&$ !"#$%&C!/ /*$ &'$ *+*-(-8.-2(&7 !"#$%& &! 1$&1)$=$ (+0 /60(&$ 0(&( "$&3$$+ ( 0(&( &(":$ (+0 (
0(&( *&!1$- *+*-(-8.-2(&7 )* 0$1)=$0 ,1!5 &'$ *-(-8.-2(&7 %:(** (+0 )* &'$ "(*$ %:(** !, &'$
61!=)0$1X*6$%)B% *+*-(-8.-2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*$* &'$ !6$+ %!++$%&)!+ (+0 :$(=$*
&'$ %!++$%&)!+ !6$+- 8, &'$ %!++$%&)!+ )* %:!*$02 *+*-(-8.-2(&7 !6$+* &'$ %!++$%&)!+2 /*$*
)&2 (+0 &'$+ %:!*$* )& (/&!5(&)%(::7- 8, 7!/ +$=$1 !6$+ &'$ %!++$%&)!+2 7!/ 0!+M& '(=$ &! %:!*$
&'$ %!++$%&)!+- A!3$=$12 ), 7!/ '(=$ 5(+7 0(&( (0(6&$1* &'(& 3):: "$ /*$0 )+ !+$ !6$1(&)!+2
7!/ %(+ 4$& "$&&$1 6$1,!15(+%$ "7 5(+/(::7 !6$+)+4 &'$ %!++$%&)!+ "$,!1$ 7!/ %(:: (:: &'$
0(&( (0(6&$1*` #/*& "$ */1$ &! %:!*$ &'$ %!++$%&)!+ 3'$+ 7!/M1$ 0!+$-
E'0=C &7$ <=)) D$&7-4
.'$ S)"" 5$&'!0 5!=$* 0(&( ,1!5 &'$ 0(&( *&!1$ &! &'$ *-(-/-+"& !"#$%& 7!/ 6(** )+&! &')*
5$&'!0- .'$ S)"" 5$&'!0 '(* *$=$1(: !=$1:!(0*2 *!5$ !, 3')%' (%%$6& !+:7 ( 0(&( *$& (* (
6(1(5$&$1- J'$+ ( 0(&( *$& )* 6(**$0 &! &'$ S)"" 5$&'!02 ( +$3 *-(-/-+"& !"#$%& )* %1$(&$0 )+
&'$ 0(&( *$& ), ( *!/1%$ *-(-/-+"& !"#$%& )* +!& *6$%)B$0-
.'$ ,!::!3)+4 %!0$ *(56:$ *'!3* '!3 ( 0(&( &(":$ %(+ "$ :!(0$0 /*)+4 &'$ S)"" 5$&'!0-
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = CType(connection.CreateCommand(), SqlCommand)
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT CustomerID, CompanyName FROM Customers"
Dim nwSet As New DataSet("nw")
Dim da As New SqlDataAdapter(cmd)
da.Fill(nwSet, "Customers")
MessageBox.Show("DataSet Filled")
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection();
connection.ConnectionString = nw.ConnectionString;
var cmd = (SqlCommand)connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
var da = new SqlDataAdapter(cmd);
var nwSet = new DataSet("nw");
da.Fill(nwSet, "Customers");
MessageBox.Show("DataSet Filled");
[(+7 0$=$:!6$1* (&&$56& &! /*$ ( *)+4:$ *+*-(-8.-2(&7 %:(** ,!1 (:: &'$)1 </$1)$* !1
&17 &! /*$ ( *)+4:$ *+*-(-8.-2(&7 %:(** &! $9$%/&$ ( ;LF *&(&$5$+& &'(& 1$&/1+* ( 1$*/:&
*$& ,1!5 5/:&)6:$ &(":$* &'(& (1$ #!)+$0 &!4$&'$1 3)&')+ &'$ ;LF </$17- 8, 7!/ +$$0 &! *&!1$
&'$ 0(&( %'(+4$*2 %!+*)0$1 /*)+4 ( *$6(1(&$ *+*-(-8.-2(&7 %:(** ,!1 $(%' 0(&( &(":$ "$)+4
:!(0$02 (* *'!3+ )+ >)4/1$ GXb- 8, (:: 7!/ +$$0 )* ( 1$(0X!+:7 0(&( &(":$2 7!/ %(+ *)56:7 /*$ (
*+#$,,-%. !"#$%& (+0 *+*-(-=&-.&7 !"#$%& &! :!(0 &'$ 0(&( &(":$-
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' 4*
CustomersDataTable
SalesDataTable
DbDataAdapter
SelectCommand
InsertCommand
UpdateCommand
DeleteCommand
DbDataAdapter
SelectCommand
InsertCommand
UpdateCommand
DeleteCommand
DbConnection
Data Store
/.;:&%'(8=' .'$ *+*-(-8.-2(&7 %:(**2 3')%' '(* ,!/1 *+#$,,-%. !"#$%&*2 *'!/:0 "$ /*$0 &! 6!6/:(&$ $(%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%1$(&$* &'$ :%4&7(#$,,-%.2 J2.-(&#$,,-%.2
(+0 *&"&(&#$,,-%. 61!6$1&)$* (* :!+4 (* ( =(:)0 &"&'(#$,,-%. 61!6$1&7 $9)*&*-
*+*-(-8.-2(&7 )* 41$(& ,!1 (0 '!% %'(+4$* (+0 0$5!*2 "/& )&M* 4$+$1(::7 "$&&$1 &! /*$ *&!1$0
61!%$0/1$* ,!1 (:: 0(&("(*$ (%%$** "$%(/*$2 )+ ;LF ;$1=$12 )&M* $(*)$1 &! *$& 6$15)**)!+* !+
*&!1$0 61!%$0/1$* &'(+ )& )* &! *$& 6$15)**)!+* !+ &(":$*- .'$ ,!::!3)+4 %!0$ 0$5!+*&1(&$* (
*)56:$ /60(&$ &! &'$ 0(&("(*$2 /*)+4 !"*-(-8.-2(&72 3')%' )* &'$ ;LF ;$1=$1_*6$%)B% =$1*)!+
!, *+*-(-8.-2(&7- S,&$1 &'$ %'(+4$* (1$ *(=$02 &'$ 1$*/:&* (1$ 0)*6:(7$0 !+ &'$ *-(-T7).H)&E
!"#$%&2 %(::$0 *-(-T7).H)&EU-
'4) !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM Customers"
Dim nwSet As New DataSet("nw")
Dim da As New SqlDataAdapter(cmd)
Dim bldr As New SqlCommandBuilder(da)
da.Fill(nwSet, "Customers")
'Modify existing row
Dim customersTable = nwSet.Tables("Customers")
Dim updRow = customersTable.Select("CustomerID='WOLZA'")(0)
updRow("CompanyName") = "New Wolza Company"
'Add new row
customersTable.Rows.Add( _
"AAAAA", "Five A Company")
'Delete a row, note that you cannot delete a
'customer who has orders
Dim delRow = customersTable.Select("CustomerID='PARIS'")(0)
delRow.Delete()
'send changes to database
da.Update(nwSet, "Customers")
DataGridView2.DataSource = nwSet
DataGridView2.DataMember = "Customers"
MessageBox.Show("Update Complete")
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection();
connection.ConnectionString = nw.ConnectionString;
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Customers";
var da = new SqlDataAdapter(cmd);
var nwSet = new DataSet("nw");
var bldr = new SqlCommandBuilder(da);
da.Fill(nwSet, "Customers");
//Modify existing row
var customersTable = nwSet.Tables["Customers"];
var updRow = customersTable.Select("CustomerID='WOLZA'")[0];
updRow["CompanyName"] = "New Wolza Company";
//Add new row
customersTable.Rows.Add(
"AAAAA", "Five A Company");
//Delete a row, note that you cannot delete a
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' 44
//customer who has orders
var delRow = customersTable.Select("CustomerID='PARIS'")[0];
delRow.Delete();
//send changes to database
da.Update(nwSet, "Customers");
dataGridView2.DataSource = nwSet;
dataGridView2.DataMember = "Customers";
MessageBox.Show("Update Complete");
!"#' -20?$'%@% :$%'$A. %B
S. B-1 $K$%1&$ &70' %-4$ &A0%$@ )= $K%$+&0-= A0,, "$ &7:-A= 0=40%)&0=C &7)& B-1 ):$ &:B0=C &-
0='$:& 41+,0%)&$ :-A'? S. B-1 '&-+ :1==0=C &7$ )++,0%)&0-= )=4 &7$= :1= 0& )C)0=@ B-1 A0,, "$
)",$ &- $K$%1&$ )C)0= "$%)1'$ &7$ T-:&7A0=4 4)&)")'$ 7)' &7$ 9/:2?@/?(-':-'? =$&,'/$2
+:-+$:&B '$& &- 9/:2?;)A#2B@ A70%7 *$)=' &7)& B-1 C$& ) =$A %,$)= %-+B -. &7$ 4)&)")'$
$;$:B &0*$ B-1 "10,4 &7$ +:-#$%&?
();0=C 37)=C$' &- &7$ R)&)")'$ 0= 2)&%7$'
8, 7!/ '(=$ &'$ ;LF R1!B:$1 &!!: &'(& )* (=():(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'$ =$EJ2.-(&. $=$+& !, &'$ *+*-(-8.-2(&7X0$1)=$0 %:(** )+X
*&(+%$*- .'$ $=$+& '(+0:$1 5$&'!0 1$%$)=$* &'$ +/5"$1 !, 1!3* (,,$%&$0 )+ &'$ :(*& "(&%'-
J'$+ J2.-(&D-('F )V& )* *$& &! W2 &'$ =&'$7.48BB&'(&. 61!6$1&7 )* (:3(7* W- 8+ &'$ ,!::!3X
)+4 %!0$ *(56:$2 &'$ ?/*&!5$1* &(":$ %!+&()+* dO 1!3*- %E*-(- &( )* B::$02 (+0 &'$+ &'$
?/*&!5$1T(5$ B$:0 )* 5!0)B$0 !+ (:: dO 1!3*- E$,!1$ &'$ J2.-(& 5$&'!0 )* $9$%/&$02
J2.-(&D-('F )V& )* %'(+4$0 &! YX- J'$+ &'$ J2.-(& 5$&'!0 )* $9$%/&$02 &'$ %'(+4$* (1$
*$+& &! &'$ 0(&("(*$ (* ( "(&%' !, bP %'(+4$*2 (+!&'$1 "(&%' !, bP %'(+4$*2 (+02 B+(::72 (
!"# -20?$'%@% :$%'$A. %B
S. B-1 $K$%1&$ &70' %-4$ &A0%$@ )= $K%$+&0-= A0,, "$ &7:-A= 0=40%)&0=C &7)& B-1 ):$ &:B0=C &-
0='$:& 41+,0%)&$ :-A'? S. B-1 '&-+ :1==0=C &7$ )++,0%)&0-= )=4 &7$= :1= 0& )C)0=@ B-1 A0,, "$
)",$ &- $K$%1&$ )C)0= "$%)1'$ &7$ T-:&7A0=4 4)&)")'$ 7)' &7$ 9/:2?@/?(-':-'? =$&,'/$2
+:-+$:&B '$& &- 9/:2?;)A#2B@ A70%7 *$)=' &7)& B-1 C$& ) =$A %,$)= %-+B -. &7$ 4)&)")'$
$;$:B &0*$ B-1 "10,4 &7$ +:-#$%&?
!"# /&%%'#%&/2&+"0 %':#;&"-%B
($&&0=C >:4#'&7#',C5=D& &- E 0' ) <10%Q A)B &- "--'& &7$ 1+4)&$ +$:.-:*)=%$ -. &7$
! #'#;4#:'&$ -"#$%&?$
'655 !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
"(&%' !, OO %'(+4$*- .')* %!0$ %!+&()+* ( =$EJ2.-(&. $=$+& '(+0:$1 &! %!::$%& "(&%' )+,!1X
5(&)!+2 3')%' )* 0)*6:(7$0 (,&$1 &'$ J2.-(& 5$&'!0 )* $9$%/&$0- 8+ &')* %!0$2 !"*-(-8.-2(&7
)* /*$0 "$%(/*$ &')* $=$+& 0!$* +!& $9)*& !+ &'$ *+*-(-8.-2(&7 "(*$ %:(**-
()*+,$ -. /0'1), 2)'0% 3-4$
Private WithEvents da As New SqlDataAdapter()
Private sb as New System.Text.StringBuilder()
private sub rowUpdated(byval sender as Object, _
byval e as SqlRowUpdatedEventArgs) handles da.RowUpdated
sb.Append("Rows: " & e.RecordsAffected.ToString() & vbCrLf)
End Sub
Private Sub menuUpdateBatch_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles UpdateBatchToolStripMenuItem.Click
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim connection = New SqlConnection()
connection.ConnectionString = nw.ConnectionString
Dim cmd = connection.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM Customers"
Dim nwSet As New DataSet("nw")
da.SelectCommand = cmd
Dim bldr As New SqlCommandBuilder(da)
da.Fill(nwSet, "Customers")
'Modify data here
For Each dr As DataRow In nwSet.Tables("Customers").Rows
dr("CompanyName") = dr("CompanyName").ToString().ToUpper()
Next
sb.Clear()
da.UpdateBatchSize = 40
da.Update(nwSet, "Customers")
MessageBox.Show(sb.ToString())
End Sub
()*+,$ -. 35 3-4$
private SqlDataAdapter da = new SqlDataAdapter();
private System.Text.StringBuilder sb = new System.Text.StringBuilder();
private void rowUpdated(object sender, SqlRowUpdatedEventArgs e )
{
sb.Append("Rows: " + e.RecordsAffected.ToString() + "\r\n");
}
private void menuUpdateBatch_Click(object sender, EventArgs e)
{
//event subscription is normally placed in constructor but is here
//to encapsulate the sample
da.RowUpdated += rowUpdated;
var nw = ConfigurationManager.ConnectionStrings["nw"];
var connection = new SqlConnection();
connection.ConnectionString = nw.ConnectionString;
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' 656
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM Customers";
da.SelectCommand = cmd;
var nwSet = new DataSet("nw");
var bldr = new SqlCommandBuilder(da);
da.Fill(nwSet, "Customers");
//Modify data here
foreach (DataRow dr in nwSet.Tables["Customers"].Rows)
{
dr["CompanyName"] = dr["CompanyName"].ToString().ToUpper();
}
sb.Clear();
da.UpdateBatchSize = 40;
da.Update(nwSet, "Customers");
//if event subscription is in the contructor, no need to
//remove it here....
da.RowUpdated -= rowUpdated;
MessageBox.Show(sb.ToString());
}
!"$/F=4&$<#,'/$2 3,)''$'.'$1$ (1$ 5(+7 1$(*!+* ,!1 31)&)+4 (+ (66:)%(&)!+ &'(& 0!$* +!& 1$</)1$ 0(&("(*$ 61!=)0$1_
*6$%)B% %!0$- S %!56(+7 5)4'& 3(+& &'$ e$9)"):)&7 &! /641(0$ ,1!5 !+$ 0(&("(*$ 61!0/%& &!
(+!&'$12 */%' (* ,!1 5!=)+4 ,1!5 [)%1!*!,& S%%$** &! ;LF ;$1=$1- @1 ( %!56(+7 5)4'& '(=$
( 1$&(): (66:)%(&)!+ &'(& 5/*& (::!3 %!++$%&)=)&7 &! (+7 0(&( *!/1%$- J)&' $(1:)$1 =$1*)!+* !,
SK@-TU.2 7!/ %(+ 31)&$ ( 61!=)0$1X)+0$6$+0$+& (66:)%(&)!+ "7 /*)+4 4$+$1)% )+&$1,(%$*- .'$
&76)%(: %!0)+4 5)4'& :!!Y *!5$&')+4 :)Y$ &'$ ,!::!3)+4H
()*+,$ -. /0'1), 2)'0% 3-4$
Public Enum DbProvider
SqlClient
OleDb
Odbc
End Enum
Public Function GetConnection() As IDbConnection
'Get the provider from the config file
Dim provider As DbProvider = [Enum].Parse( _
GetType(DbProvider), _
ConfigurationSettings.AppSettings("provider").ToString())
Dim connection As IDbConnection = Nothing
Select Case (provider)
Case DbProvider.SqlClient
connection = New System.Data.SqlClient.SqlConnection()
Case DbProvider.OleDb
connection = New System.Data.OleDb.OleDbConnection()
Case DbProvider.Odbc
'65( !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
connection = New System.Data.Odbc.OdbcConnection()
Case DbProvider.Oracle
connection = New System.Data.OracleClient.OracleConnection()
End Select
Return connection
End Function
()*+,$ -. 35 3-4$
public IDbConnection GetConnection()
{
// Get the provider from the config file
DbProvider provider = (DbProvider)Enum.Parse(
typeof(DbProvider),
(string)ConfigurationManager.AppSettings["provider"]);
IDbConnection connection = null;
switch (provider)
{
case DbProvider.SqlClient:
connection = new System.Data.SqlClient.SqlConnection();
break;
case DbProvider.OleDb:
connection = new System.Data.OleDb.OleDbConnection();
break;
case DbProvider.Odbc:
connection = new System.Data.Odbc.OdbcConnection();
break;
case DbProvider.Oracle:
connection = new System.Data.OracleClient.OracleConnection();
break;
}
return connection;
}
public enum DbProvider
{ SqlClient, OleDb, Odbc, Oracle };
LD9 F++,0%)&0-= 3-=.0C1:)&0-= M0,$
<configuration>
<appSettings>
<add key="provider" value="SqlClient" />
</appSettings>
</configuration>
@+$ 61!":$5 3)&' &')* (661!(%' )* &'(& 7!/ %(+M& %1$(&$ )+&$1,(%$ )+*&(+%$* 0)1$%&:72 *!
61!=)0$1X*6$%)B% %!0$ $9)*&* &! 0$&$15)+$ 3')%' &76$ !, %!++$%&)!+ &! %1$(&$- S+!&'$1
61!":$5 )* &'(& )+&$1,(%$* (1$ )55/&(":$ "7 0$B+)&)!+2 *! +$3 ,$(&/1$* %(+M& "$ $(*):7 (00$0
3)&'!/& (00)+4 ( +$3 )+&$1,(%$-
SK@-TU. 61!=)0$* "(*$ %:(**$* ,1!5 3')%' &'$ 61!=)0$1X*6$%)B% %:(**$* )+'$1)&2 (* *'!3+
$(1:)$1 )+ .(":$ GXO- .'$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,)4/1$ *'!3* &'$ *+67$I).&7S-'($71 (+0 !"#")&%(S-'($71 %:(**$*-
.'$ 61!=)0$1 ,(%&!17 %:(**$* (1$ )56:$5$+&$0 (* *)+4:$&!+*2 )+ 3')%' $(%' %:(** 61!X
=)0$* (+ :%4(-%'& 61!6$1&7 &'(& $+(":$* 7!/ &! (%%$** &'$ 5$&'!0* (+0 61!6$1&)$* *'!3+ )+
>)4/1$ GXZ- >!1 $9(56:$2 7!/ %(+ /*$ &'$ ,!::!3)+4 %!0$ &! %1$(&$ ( +$3 %!++$%&)!+ "7 /*)+4
&'$ !"#")&%(S-'($71 %:(**-
()*+,$ -. /0'1), 2)'0% 3-4$
'Get the singleton instance
Dim factory As DbProviderFactory = SqlClientFactory.Instance
Public Function GetProviderConnection() As DbConnection
Dim connection = factory.CreateConnection()
connection.ConnectionString = "Data Source=.\SQLEXPRESS;" _
& "AttachDbFilename=|DataDirectory|PUBS.MDF;" _
& "Integrated Security=True;User Instance=True"
Return connection
End Function
()*+,$ -. 35 3-4$
//Get the singleton instance
DbProviderFactory factory = SqlClientFactory.Instance;
public DbConnection GetProviderConnection()
{
'65= !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
var connection = factory.CreateConnection();
connection.ConnectionString = @"Data Source=.\SQLEXPRESS;"
+ "AttachDbFilename=|DataDirectory|Northwind.MDF;"
+ "Integrated Security=True;User Instance=True";
return connection;
}
C!/ %(+ /*$ &'$ ,(%&!17 =(1)(":$ &! %1$(&$ (+7 !, &'$ !&'$1 ;LF ;$1=$1_*6$%)B% !"#$%&*-
T!&$ &'(& !"*-(-=&-.&7 )* %1$(&$0 )+0)1$%&:7 "7 %1$(&)+4 ( ;LF %!55(+0 (+0 &'$+ /*)+4 &'$
?0&'@(&=&-.&7 5$&'!02 (* *'!3+ )+ &'$ ,!::!3)+4 %!0$ *(56:$H
()*+,$ -. /0'1), 2)'0% 3-4$
Private Function GetData(ByVal commandText As String, _
ByVal commandType As CommandType) As DataTable
'get SqlDbCommand
Dim command = factory.CreateCommand()
command.Connection = GetProviderConnection()
If (command.Connection Is Nothing) Then
Return Nothing
End If
command.CommandText = commandText
command.CommandType = commandType
command.Connection.Open()
Dim dataTable = New DataTable()
'Get SqlDataReader and populate data table
dataTable.Load(command.ExecuteReader())
command.Connection.Close()
Return dataTable
End Function
()*+,$ -. 35 3-4$
private DataTable GetData(string commandText, CommandType commandType)
{
//get SqlDbCommand
var command = factory.CreateCommand();
command.Connection = GetProviderConnection();
if (command.Connection == null) return null;
command.CommandText = commandText;
command.CommandType = commandType;
command.Connection.Open();
var dataTable = new DataTable();
//Get SqlDataReader and populate data table
dataTable.Load(command.ExecuteReader());
command.Connection.Close();
return dataTable;
}
.')* %!0$ *(56:$ /*$* &'$ ,(%&!17 =(1)(":$ &! %1$(&$ ( *+#$,,-%. %:(**2 3')%' )* &'$+
/*$0 &! %1$(&$ &'$ *+*-(-=&-.&7 !"#$%&-
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' 659
E'0=C !*+,&:'=/0 &- 3)&%7 P:-;04$: JK%$+&0-='S:: 61!=)0$1X*6$%)B% $9%$6&)!+* )+'$1)& ,1!5 ( %!55!+ "(*$ %:(** %(::$0 *+?0'&2()$%-
J'$+ 3!1Y)+4 3)&' ( 61!=)0$1X+$/&1(: %!0)+4 5!0$:2 7!/1 (71f'-('F ":!%Y %(+ *)56:7 %(&%'
*+?0'&2()$% 4$+$1)%(::7 )+*&$(0 !, &17)+4 &! %(&%' $(%' 61!=)0$1X*6$%)B% $9%$6&)!+-
U-:Q0=C A0&7 (89 ($:;$: E'$:VR$>=$4 6B+$' HER6'I;LF ;$1=$1 GPPZ (+0 :(&$1 61!=)0$* '!*&)+4 */66!1& ,!1 &'$ -TU. >1(5$3!1Y %!55!+ :(+X
4/(4$ 1/+&)5$ V;LF?FIW2 *! 7!/ %(+ /*$ g)*/(: E(*)% GPOP !1 ?h &! 31)&$ %!0$ &'(& 3):: 1/+
)+ ;LF ;$1=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&'$ \K.2 !+:7 &'$ 1(3 "7&$* !, &'$ \K. 1$&/1+$0 ,1!5 ;LF ;$1=$12
7!/ 0!+M& +$$0 &! *$& ( 1$,$1$+%$ &! &'$ (**$5":7- .')* %!/:0 "$ /*$0 3'$+ 7!/ Y+!3 &'$
6'7*)%(: *&1/%&/1$ !, &'$ 0(&(2 (+0 7!/M1$ 4!)+4 &! 6(1*$ &'$ 0(&( (+0 (**)4+ )& &! ( 0),,$1$+&
!"#$%&-
.'$ ,!::!3)+4 $9(56:$ %!0$ 0$5!+*&1(&$* &'$ %1$(&)!+ !, ( &(":$ %(::$0 F!%(&)!+* )+ ;LF
;$1=$1- E$,!1$ %1$(&)+4 &'$ &(":$2 ( %!55(+0 )* $9$%/&$0 &! *$$ 3'$&'$1 &'$ &(":$ (:1$(07 $9X
)*&*- 8, &'$ &(":$ $9)*&*2 )&M* 01!66$0- S,&$1 &'(&2 &'$ F!%(&)!+* &(":$ )* %1$(&$0-
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim nwConnection = New SqlConnection(nw.ConnectionString)
Dim cmd = nwConnection.CreateCommand()
cmd.CommandText =
"IF EXISTS (SELECT * FROM sys.Tables WHERE Name='Locations') " _
& " DROP TABLE Locations"
nwConnection.Open()
cmd.ExecuteNonQuery()
cmd.CommandText =
"CREATE TABLE Locations(" _
& " ZipCode char(5) PRIMARY KEY NOT NULL, Location Geography)"
cmd.ExecuteNonQuery()
nwConnection.Close()
MessageBox.Show("Location table created")
'65> !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var nwConnection = new SqlConnection(nw.ConnectionString);
var cmd = nwConnection.CreateCommand();
cmd.CommandText =
"IF EXISTS (SELECT * FROM sys.Tables WHERE Name='Locations') "
+ " DROP TABLE Locations";
nwConnection.Open();
cmd.ExecuteNonQuery();
cmd.CommandText =
"CREATE TABLE Locations("
+ " ZipCode char(5) PRIMARY KEY NOT NULL, Location Geography)";
cmd.ExecuteNonQuery();
nwConnection.Close();
MessageBox.Show("Location table created");
!"#' A2&C.0;'A.$!'"' 7%"0' 2#D'2/'$!%'-"$"1",%
S. B-1: 3-+B 6- !1&+1& R0:$%&-:B '$&&0=C' -= B-1: 4)&)")'$ >,$ ):$ &- 3-+B F,A)B'@ $;$:B
&0*$ B-1 '&):& &7$ )++,0%)&0-= B-1 A0,, C$& ) =$A@ %,$)= 4)&)")'$? W-1 A0,, =$$4 &- :$V%:$)&$
&7$ &)",$ )=4 &7$= :$V+-+1,)&$ 0&? 67$= B-1 %)= :1= -&7$: &$'&'?
T!3 &'(& &'$ &(":$ )* %1$(&$02 7!/ 5)4'& 3(+& &! 6!6/:(&$ &'$ &(":$ 3)&' *!5$ 0(&(- .'$
61!":$5 )* &'(& &'$ F!%(&)!+ %!:/5+ )* ( \K.- .! )+*$1& ( T&$K7-2F1 !"#$%&2 7!/ 5/*& (00 (
1$,$1$+%$ &! &'$ [)%1!*!,&-;<:;$1=$1-.76$*-0:: (**$5":7- 8, 7!/ '(=$ ;LF ;$1=$1 GPPi )+*&(::$0
!+ 7!/1 %!56/&$12 &')* (**$5":7 )* )+ &'$ DS?2 "/& 7!/ %(+M& (00 1$,$1$+%$* 0)1$%&:7 &! DS?
(**$5":)$*- C!/ 5/*& :!%(&$ &'$ (**$5":72 3')%' *'!/:0 "$ (& &'$ ,!::!3)+4 :!%(&)!+H
C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies
.')* )* &'$ :!%(&)!+ ), 7!/ '(=$ ( jbX")& !6$1(&)+4 *7*&$52 "/& 7!/ *'!/:0 "$ (":$ &! B+0 )&
)+ &'$ R1!41(5 >):$* ,!:0$1 !+ ( aGX")& !6$1(&)+4 *7*&$5-
.'$ ,!::!3)+4 %!0$ (00* &'1$$ k8R !1 6!*&(: %!0$* 3)&' &'$ %!11$*6!+0)+4 T&$K7-2F1
!"#$%&*- T!&)%$ &'$ 5(4)% +/5"$1 baGj )+ &'$ $9(56:$- .')* )* &'$ D$!%!0$ ,!1 JD;ib 1!/+0
$(1&' 5!0$: &'(& 5!*& 6$!6:$ /*$-
()*+,$ -. /0'1), 2)'0% 3-4$
'add reference to Microsoft.SqlServer.Types.dll
'add imports to the top of this file:
'Imports Microsoft.SqlServer.Types
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim nwConnection = New SqlConnection(nw.ConnectionString)
Dim cmd = nwConnection.CreateCommand()
cmd.CommandText = "INSERT Locations VALUES(@zip, @loc)"
Dim zip = New SqlParameter("@zip", "14710") 'Ashville NY
Dim loc = New SqlParameter("@loc", SqlDbType.Udt)
loc.UdtTypeName = "geography"
loc.Value = SqlGeography.STGeomFromText( _
New SqlChars("POINT(42.1018 79.4144)"), 4326)
!"# A2&C.0;'A.$!'"' 7%"0' 2#D'2/'$!%'-"$"1",%
S. B-1: 3-+B 6- !1&+1& R0:$%&-:B '$&&0=C' -= B-1: 4)&)")'$ >,$ ):$ &- 3-+B F,A)B'@ $;$:B
&0*$ B-1 '&):& &7$ )++,0%)&0-= B-1 A0,, C$& ) =$A@ %,$)= 4)&)")'$? W-1 A0,, =$$4 &- :$V%:$)&$
&7$ &)",$ )=4 &7$= :$V+-+1,)&$ 0&? 67$= B-1 %)= :1= -&7$: &$'&'?
F$**!+ GH I$(0)+4 (+0 J1)&)+4 K(&( !"#$%&'(' 65*
cmd.Parameters.Add(zip)
cmd.Parameters.Add(loc)
nwConnection.Open()
cmd.ExecuteNonQuery()
zip.Value = "44011"
loc.Value = SqlGeography.STGeomFromText( _
New SqlChars("POINT(41.4484 82.0190)"), 4326)
cmd.ExecuteNonQuery()
zip.Value = "60609"
loc.Value = SqlGeography.STGeomFromText( _
New SqlChars("POINT(41.8121 87.6542)"), 4326)
cmd.ExecuteNonQuery()
nwConnection.Close()
MessageBox.Show("Entries added")
()*+,$ -. 35 3-4$
//add reference to Microsoft.SqlServer.Types.dll
//'add imports to the top of this file:
//using Microsoft.SqlServer.Types;
//using System.Data.SqlTypes;
var nw = ConfigurationManager.ConnectionStrings["nw"];
var nwConnection = new SqlConnection(nw.ConnectionString);
var cmd = nwConnection.CreateCommand();
cmd.CommandText = "INSERT Locations VALUES(@zip, @loc)";
var zip = new SqlParameter("@zip", "14710"); // Ashville NY
var loc = new SqlParameter("@loc", SqlDbType.Udt);
loc.UdtTypeName = "geography";
loc.Value = SqlGeography.STGeomFromText(
new SqlChars("POINT(42.1018 79.4144)"), 4326);
cmd.Parameters.Add(zip);
cmd.Parameters.Add(loc);
nwConnection.Open();
cmd.ExecuteNonQuery();
zip.Value = "44011";
loc.Value = SqlGeography.STGeomFromText(
new SqlChars("POINT(41.4484 82.0190)"), 4326);
cmd.ExecuteNonQuery();
zip.Value = "60609";
loc.Value = SqlGeography.STGeomFromText(
new SqlChars("POINT(41.8121 87.6542)"), 4326);
cmd.ExecuteNonQuery();
nwConnection.Close();
MessageBox.Show("Entries added");
'65) !"#$%&'( SK@-TU. ?!++$%&$0 ?:(**$*
S,&$1 &'$ 1!3* (1$ )+*$1&$0 )+&! &'$ &(":$2 7!/ %(+ </$17 ,!1 &'$*$ 1!3* (+0 /*$ &'$5 &!
6$1,!15 &(*Y* */%' (* %(:%/:(&)+4 &'$ 0)*&(+%$ "$&3$$+ &3! :!%(&)!+*- A$1$ )* (+ $9(56:$H
()*+,$ -. /0'1), 2)'0% 3-4$
Dim nw = ConfigurationManager.ConnectionStrings("nw")
Dim nwConnection = New SqlConnection()
nwConnection.ConnectionString = nw.ConnectionString
Dim cmd = nwConnection.CreateCommand()
cmd.CommandText = "SELECT Location FROM Locations WHERE ZipCode='14710'"
nwConnection.Open()
Dim ashvilleNY = cmd.ExecuteScalar()
cmd.CommandText = "SELECT Location FROM Locations WHERE ZipCode='44011'"
Dim avonOH = cmd.ExecuteScalar()
cmd.CommandText = "SELECT Location FROM Locations WHERE ZipCode='60609'"
Dim chicagoIL = cmd.ExecuteScalar()
nwConnection.Close()
MessageBox.Show(String.Format("Ashville to Chicago: {0}",
ashvilleNY.STDistance(chicagoIL) / 1609.344)) '1609.344 meters/mile
MessageBox.Show(String.Format("Ashville to Avon: {0}",
ashvilleNY.STDistance(avonOH) / 1609.344)) '1609.344 meters/mile
()*+,$ -. 35 3-4$
var nw = ConfigurationManager.ConnectionStrings["nw"];
var nwConnection = new SqlConnection(nw.ConnectionString);
var cmd = nwConnection.CreateCommand();
cmd.CommandText = "SELECT Location FROM Locations WHERE ZipCode='14710'";
nwConnection.Open();
var ashvilleNY = (SqlGeography)cmd.ExecuteScalar();
cmd.CommandText = "SELECT Location FROM Locations WHERE ZipCode='44011'";
var avonOH = (SqlGeography)cmd.ExecuteScalar();
cmd.CommandText = "SELECT Location FROM Locations WHERE ZipCode='60609'";
var chicagoIL = (SqlGeography)cmd.ExecuteScalar();
nwConnection.Close();
MessageBox.Show(string.Format("Ashville to Chicago: {0}",
ashvilleNY.STDistance(chicagoIL) / 1609.344)); //1609.344 meters/mile
MessageBox.Show(string.Format("Ashville to Avon: {0}",
ashvilleNY.STDistance(avonOH) / 1609.344)); //1609.344 meters/mile
8+ &')* $9(56:$2 &'$ !"T&$K7-2F1 !"#$%& 3(* 1$&1)$=$0 ,1!5 &'$ 0(&("(*$2 (+0 &'$+ &'$
%:)$+& (66:)%(&)!+ 3(* (":$ &! $9$%/&$ 5$&'!0* !+ &'$ \K.-
!"#$%&$' &EFGHIJ'FIG'AKHLHIJ'-FLF
8+ &')* 61(%&)%$2 7!/ %(+ %!+&)+/$ &'$ 61(%&)%$ 7!/ "$4(+ )+ &'$ 61$=)!/* :$**!+ !1 /*$ &'$
"$4)++)+4 ?'(6&$1 G2 F$**!+ G2 *!:/&)!+ )+%:/0$0 !+ &'$ %!56(+)!+ ?K- 8, 7!/M1$ /*)+4 &'$
#F&'Q#$%%&'()I)(1 5$&'!0 ,1!5 &'$ 61$=)!/* :$**!+2 ), ( %!++$%&)!+ %(+ "$ 5(0$2 7!/ (00
%!0$ &! %1$(&$ &'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! 6!)+& &! &'$ 1$5!&$ 0(&("(*$ *$1=$1-W
.+ 8+ ;!:/&)!+ U96:!1$12 1)4'&X%:)%Y &'$ 61!#$%& +!0$2 %:)%Y S00 l T$3 8&$5 l K(&( l
;$1=)%$X"(*$0 K(&("(*$2 (+0 +(5$ &'$ B:$ +FHILEIFIMENOGPN ?:)%Y S00-
.')* 3):: (00 &'$ B:$2 "/& )& 3):: (:*! *&(1& ( 3)c(10 &! %1$(&$ ( &76$0 0(&( *$&-
/+ ?:)%Y ?(+%$: !+ &'$ 3)c(10 6(4$-
0+ ;$:$%& &'$ +$3:7 %1$(&$0 [()+&$+(+%$-[K> B:$ )+ ;!:/&)!+ U96:!1$1 (+0 &'$+2 )+ &'$
R1!6$1&)$* 3)+0!32 *$& &'$ #$213/$3G@(2@(3*)7 61!6$1&7 &! #$213:B3<&E&7-
1+ [!0),7 &'$ %!++$%&)!+ *&1)+4 )+ &'$ %!+B4 B:$ &! %!++$%& &! 7!/1 +$3 0(&("(*$- 8+ &'$
m !"#$%&'()!" !"#"$"%&'!$()*+,!&-"!.(%%".&*(%!/&0*%1!&(!#((2!#*2"!&-"!+(##(3*%14
!!"#$%&'()#$%%*+,'$%
<connectionStrings>
<add name="db" connectionString=
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Maintenance.MDF;
Integrated Security=True;User Instance=True" />
</connectionStrings>
!"! 5))!&-"!+(##(3*%1!.#6//7#"8"#!860*69#"/!&(!&-"!&(:!(+!,(;0!<*%)(3/!+(0$!&-6&!3*##!0"+"07
"%."!&-"!)6&6!6)6:&"0/!,(;!3*##!;/"!&(!$(8"!)6&6!9"&3""%!,(;0!6::#*.6&*(%!6%)!&-"!
)6&696/"4
-./!0*)$&)1'23.0)4.2'+)#$5*
Private daVehicles As SqlDataAdapter
Private daRepairs As SqlDataAdapter
-./!0*)$&)#6)#$5*
private SqlDataAdapter daVehicles;
private SqlDataAdapter daRepairs;
!!" #$%&'() * 5=>4?@A!B(%%".&")!B#6//"/
#"! 5&!&-"!&(:!(+!&-"!*!&+,-.!'/!"8"%&!-6%)#"0!$"&-()'!.-6%1"!&-"!012 30!""2 ()4)(5!
$"&-()!.6##!&(!.6##!&-"!6")()'7)829'(':/';(2&<!$"&-()!,(;!3*##!.0"6&"!*%!&-"!%"C&!/&":4!
A-"!.($:#"&")!*!&+,-.!'/!/-(;#)!#((2!#*2"!&-"!+(##(3*%1D
-./!0*)$&)1'23.0)4.2'+)#$5*
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
cnString = ConfigurationManager _
.ConnectionStrings("db") _
.ConnectionString
InitializeDataAdapters()
PopulateDataSet()
dgVehicles.DataSource = ds
dgVehicles.DataMember = "Vehicles"
dgRepairs.DataSource = ds
dgRepairs.DataMember = "Vehicles.vehicles_repairs"
End Sub
-./!0*)$&)#6)#$5*
private void Form1_Load(object sender, EventArgs e)
{
cnString = ConfigurationManager
.ConnectionStrings["db"]
.ConnectionString;
InitializeDataAdapters();
PopulateDataSet();
dgVehicles.DataSource = ds;
dgVehicles.DataMember = "Vehicles";
dgRepairs.DataSource = ds;
dgRepairs.DataMember = "Vehicles.vehicles_repairs";
}
A-"!6")()'7)829'(':/';(2&<!$"&-()!3*##!*%*&*6#*E"!6!)6&6!6)6:&"0!+(0!&-"!F"-*.#"/!&69#"!
6%)!6!)6&6!6)6:&"0!+(0!&-"!G":6*0/!&69#"4!H(0!&-"!F"-*.#"/!&69#"'!&-"!)6&6!6)6:&"0!*/!
*%*&*6#*E")!&-"!"6/,!36,'!;/*%1!6!=>70!++'"/?%)7/2&!(9I".&!&(!.0"6&"!&-"!6"<2&('!@;/'(2'!
6%)!9272(2!.($$6%)/4!H(0!&-"!G":6*0/!&69#"'!&-"!)6&6!6)6:&"0!*/!*%*&*6#*E")!9,!.0"6&*%1!
"6.-!.($$6%)!(9I".&!$6%;6##,!6%)!"C:#*.*&#,!/"&&*%1!&-"!%"."//60,!:0(:"0&*"/4!A-"!
+(##(3*%1!.()"!/-(3/!&-"!6")()'7)829'(':/';(2&<!$"&-()4
-./!0*)$&)1'23.0)4.2'+)#$5*
Public Sub InitializeDataAdapters()
'do vehicles with the SQL Command Builder
daVehicles = New SqlDataAdapter("SELECT * FROM Vehicles", cnString)
Dim bldVehicles As New SqlCommandBuilder(daVehicles)
'do repairs by creating all commands
Dim cn As New SqlConnection(cnString)
Dim cmdSelectRepairs = cn.CreateCommand()
Dim cmdUpdateRepairs = cn.CreateCommand()
Dim cmdDeleteRepairs = cn.CreateCommand()
Dim cmdInsertRepairs = cn.CreateCommand()
cmdSelectRepairs.CommandText = _
! J"//(%!KD!G"6)*%1!6%)!<0*&*%1!=6&6! #$%&'() * !!!
"SELECT * FROM Repairs"
cmdInsertRepairs.CommandText = _
"INSERT Repairs(VIN,Description, Cost) " _
& " OUTPUT inserted.* " _
& " VALUES( @VIN, @Description, @Cost); "
cmdInsertRepairs.Parameters.Add("@VIN", SqlDbType.VarChar, 20, "VIN")
cmdInsertRepairs.Parameters.Add("@Description", SqlDbType.VarChar, _
60, "Description")
cmdInsertRepairs.Parameters.Add("@Cost", SqlDbType.Money, 0, "Cost")
cmdUpdateRepairs.CommandText = _
"UPDATE Repairs SET " _
& " VIN=@VIN, Description=@Description, Cost=@Cost " _
& " WHERE ID=@OriginalID " _
& " AND VIN=@OriginalVIN " _
& " AND Description=@OriginalDescription " _
& " AND Cost=@OriginalCost"
cmdUpdateRepairs.Parameters.Add("@OriginalID", SqlDbType.Int, 0, "ID") _
.SourceVersion = DataRowVersion.Original
cmdUpdateRepairs.Parameters.Add("@VIN", SqlDbType.VarChar, 20, "VIN")
cmdUpdateRepairs.Parameters.Add("@OriginalVIN", SqlDbType.VarChar, _
20, "VIN").SourceVersion = DataRowVersion.Original
cmdUpdateRepairs.Parameters.Add("@Description", SqlDbType.VarChar, _
60, "Description")
cmdUpdateRepairs.Parameters.Add("@OriginalDescription", _
SqlDbType.VarChar, 20, "Description") _
.SourceVersion = DataRowVersion.Original
cmdUpdateRepairs.Parameters.Add("@Cost", SqlDbType.Money, 0, "Cost")
cmdUpdateRepairs.Parameters.Add("@OriginalCost", SqlDbType.Money, _
0, "Cost").SourceVersion = DataRowVersion.Original
cmdDeleteRepairs.CommandText = _
"DELETE Repairs " _
& " WHERE ID=@OriginalID " _
& " AND VIN=@OriginalVIN " _
& " AND Description=@OriginalDescription " _
& " AND Cost=@OriginalCost"
cmdDeleteRepairs.Parameters.Add("@OriginalID", SqlDbType.Int, 0, "ID") _
.SourceVersion = DataRowVersion.Original
cmdDeleteRepairs.Parameters.Add("@OriginalVIN", SqlDbType.VarChar, _
20, "VIN").SourceVersion = DataRowVersion.Original
!!* #$%&'() * 5=>4?@A!B(%%".&")!B#6//"/
cmdDeleteRepairs.Parameters.Add("@OriginalDescription", _
SqlDbType.VarChar, 20, "Description") _
.SourceVersion = DataRowVersion.Original
cmdDeleteRepairs.Parameters.Add("@OriginalCost", SqlDbType.Money, _
0, "Cost").SourceVersion = DataRowVersion.Original
daRepairs = New SqlDataAdapter(cmdSelectRepairs)
daRepairs.InsertCommand = cmdInsertRepairs
daRepairs.UpdateCommand = cmdUpdateRepairs
daRepairs.DeleteCommand = cmdDeleteRepairs
End Sub
-./!0*)$&)#6)#$5*
public void InitializeDataAdapters()
{
cnString = ConfigurationManager.ConnectionStrings["db"].ConnectionString;
//do vehicles with the SQL Command Builder;
daVehicles = new SqlDataAdapter("SELECT * FROM Vehicles", cnString);
var bldVehicles = new SqlCommandBuilder(daVehicles);
//do repairs by creating all commands
var cn = new SqlConnection(cnString);
var cmdSelectRepairs = cn.CreateCommand();
var cmdUpdateRepairs = cn.CreateCommand();
var cmdDeleteRepairs = cn.CreateCommand();
var cmdInsertRepairs = cn.CreateCommand();
cmdSelectRepairs.CommandText =
"SELECT * FROM Repairs";
cmdInsertRepairs.CommandText =
"INSERT Repairs(VIN,Description, Cost) "
+ " OUTPUT inserted.* "
+ " VALUES( @VIN, @Description, @Cost); ";
cmdInsertRepairs.Parameters.Add("@VIN", SqlDbType.VarChar, 20, "VIN");
cmdInsertRepairs.Parameters.Add("@Description", SqlDbType.VarChar,
60, "Description");
cmdInsertRepairs.Parameters.Add("@Cost", SqlDbType.Money, 0, "Cost");
cmdUpdateRepairs.CommandText =
"UPDATE Repairs SET "
+ " VIN=@VIN, Description=@Description, Cost=@Cost "
+ " WHERE ID=@OriginalID "
+ " AND VIN=@OriginalVIN "
+ " AND Description=@OriginalDescription "
+ " AND Cost=@OriginalCost";
cmdUpdateRepairs.Parameters.Add("@OriginalID", SqlDbType.Int, 0, "ID")
.SourceVersion = DataRowVersion.Original;
! J"//(%!KD!G"6)*%1!6%)!<0*&*%1!=6&6! #$%&'() * !!+
cmdUpdateRepairs.Parameters.Add("@VIN", SqlDbType.VarChar, 20, "VIN");
cmdUpdateRepairs.Parameters.Add("@OriginalVIN", SqlDbType.VarChar,
20, "VIN").SourceVersion = DataRowVersion.Original;
cmdUpdateRepairs.Parameters.Add("@Description", SqlDbType.VarChar,
60, "Description");
cmdUpdateRepairs.Parameters.Add("@OriginalDescription",
SqlDbType.VarChar, 20, "Description")
.SourceVersion = DataRowVersion.Original;
cmdUpdateRepairs.Parameters.Add("@Cost", SqlDbType.Money, 0, "Cost");
cmdUpdateRepairs.Parameters.Add("@OriginalCost", SqlDbType.Money,
0, "Cost").SourceVersion = DataRowVersion.Original;
cmdDeleteRepairs.CommandText =
"DELETE Repairs "
+ " WHERE ID=@OriginalID "
+ " AND VIN=@OriginalVIN "
+ " AND Description=@OriginalDescription "
+ " AND Cost=@OriginalCost";
cmdDeleteRepairs.Parameters.Add("@OriginalID", SqlDbType.Int, 0, "ID")
.SourceVersion = DataRowVersion.Original;
cmdDeleteRepairs.Parameters.Add("@OriginalVIN", SqlDbType.VarChar,
20, "VIN").SourceVersion = DataRowVersion.Original;
cmdDeleteRepairs.Parameters.Add("@OriginalDescription",
SqlDbType.VarChar, 20, "Description")
.SourceVersion = DataRowVersion.Original;
cmdDeleteRepairs.Parameters.Add("@OriginalCost", SqlDbType.Money,
0, "Cost").SourceVersion = DataRowVersion.Original;
daRepairs = new SqlDataAdapter(cmdSelectRepairs);
daRepairs.InsertCommand = cmdInsertRepairs;
daRepairs.UpdateCommand = cmdUpdateRepairs;
daRepairs.DeleteCommand = cmdDeleteRepairs;
}
L%!&-*/!$"&-()'!*&!&((2!(%#,!6!.(;:#"!#*%"/!(+!.()"!&(!*%*&*6#*E"!&-"!F"-*.#"/!)6&6!
6)6:&"04!=>70!++'"/?%)7/2&!/*$:#*M"/!&-"!*%*&*6#*E6&*(%!9;&!)("/%N&!-68"!&-"!/6$"!
+"6&;0"/!&-6&!60"!686*#69#"!3-"%!30*&*%1!6##!&-"!.()"4!A-*/!9".($"/!6::60"%&!3-"%!*%*7
&*6#*E*%1!&-"!G":6*0/!)6&6!6)6:&"04!A-"!G":6*0/!&69#"!-6/!6%!*)"%&*&,!.(#;$%!&-6&!$;/&!
9"!;:)6&")!6+&"0!*%/"0&/!60"!)(%"4!A-"!>OAPOA!2",3(0)!*%!&-"!QRJ!*%/"0&!/&6&"$"%&!
*/!&-"!"S;*86#"%&!(+!"C".;&*%1!6!Q@J@BA!/&6&"$"%&!(%!&-"!0(3!&-6&!36/!*%/"0&")'!3-*.-!
;:)6&"/!&-"!*)"%&*&,!.(#;$%!*%!&-"!.#*"%&!6::#*.6&*(%4!A-"!L=!.(#;$%!-6)!%"16&*8"!86#7
;"/!6%)!%"")")!&(!9"!;:106)")!&(!&-"!6.&;6#!86#;"/!&-6&!60"!1"%"06&")!*%!QRJ!Q"08"0!
3-"%!&-"!*%/"0&!&62"/!:#6."4
!!, #$%&'() * 5=>4?@A!B(%%".&")!B#6//"/
$%"! 5))!.()"!*%&(!&-"!A!;%7'(29'('=2(!$"&-()!&-6&!3*##!.6##!&(!&-"!=5" 1&!")82!$"&-()!
,(;!3*##!6))!*%!&-"!%"C&!/&":4!T(;0!.($:#"&")!A!;%7'(29'('=2(!$"&-()!3*##!#((2!#*2"!
&-"!+(##(3*%14
-./!0*)$&)1'23.0)4.2'+)#$5*
Private Sub PopulateDataSet()
If File.Exists(xsdFile) Then
ds = New DataSet()
ds.ReadXmlSchema(xsdFile)
Else
CreateSchema()
End If
If File.Exists(xmlFile) Then
ds.ReadXml(xmlFile, XmlReadMode.IgnoreSchema)
End If
Synchronize()
End Sub
-./!0*)$&)#6)#$5*
private void PopulateDataSet()
{
if( File.Exists(xsdFile))
{
ds = new DataSet();
ds.ReadXmlSchema(xsdFile);
}
else
{
CreateSchema();
}
if( File.Exists(xmlFile))
{
ds.ReadXml(xmlFile, XmlReadMode.IgnoreSchema);
}
Synchronize();
}
$$"! 5))!&-"!=5" 1&!")82!$"&-()'!3-*.-!3*##!9"!.6##")!3-"%!&-"!6::#*.6&*(%!/&60&/!6%)!
3-"%!*&!"%)/4!
A-*/!$"&-()!3*##!M0/&!.-".2!3-"&-"0!6!.(%%".&*(%!.6%!9"!$6)"!&(!&-"!)6&696/"!/"08"04!
L+!6!.(%%".&*(%!.6%!9"!$6)"'!&-"!.()"!8"0*M"/!3-"&-"0!&-"!&69#"/!"C*/&U!*+!&-",!)(!%(&!
"C*/&'!&-"!&69#"/!60"!.0"6&")4!A-"!.()"!&-"%!.6##/!&-"!=5" 9'('!$"&-()!.0"6&")!*%!&-"!
%"C&!/&":!&(!:"0+(0$!&-"!/,%.-0(%*E6&*(%4!T(;0!.()"!/-(;#)!#((2!#*2"!&-"!+(##(3*%1D
-./!0*)$&)1'23.0)4.2'+)#$5*
Private Sub Synchronize()
If CheckConnectivity() Then
CreateTablesIfNotExisting()
SyncData()
End If
End Sub
! J"//(%!KD!G"6)*%1!6%)!<0*&*%1!=6&6! #$%&'() * !!-
-./!0*)$&)#6)#$5*
private void Synchronize()
{
if( CheckConnectivity())
{
CreateTablesIfNotExisting();
SyncData();
}
}
$&"! V()*+,!&-"!012 30!""2 ()4)(5!$"&-()'!3-*.-!3*##!/*$:#,!6&&"$:&!&(!0"&0*"8"!&-"!8"07
/*(%!(+!QRJ!Q"08"0!6%)!0"&;0%!(&%2!(0!B'7<2'!96/")!(%!3-"&-"0!&-"!6&&"$:&!36/!/;.."//7
+;#4!A-"!$"//61"/!-68"!9""%!0"$(8")!/(!&-*/!$"&-()!/*#"%&#,!.-".2/!.(%%".&*8*&,4
-./!0*)$&)1'23.0)4.2'+)#$5*
Private Function CheckConnectivity() As Boolean
Try
Using cn = New SqlConnection(cnString)
cn.Open()
Dim version = cn.ServerVersion
End Using
Catch ex As Exception
Return False
End Try
Return True
End Function
-./!0*)$&)#6)#$5*
private bool CheckConnectivity()
{
try
{
using(var cn = new SqlConnection(cnString))
{
cn.Open();
var version = cn.ServerVersion;
}
}
catch
{
return false;
}
return true;
}
$'"! 5))!&-"!.()"!+(0!&-"!0&2'(2C'D72<6BE!(FG)<()"$!$"&-()4!A-*/!$"&-()!.-".2/!3-"&-"0!
&-"!F"-*.#"/!6%)!G":6*0/!&69#"/!"C*/&!(%!QRJ!Q"08"0!6%)'!*+!%(&'!&-"!&69#"/!60"!.0"6&")4
-./!0*)$&)1'23.0)4.2'+)#$5*
Private Sub CreateTablesIfNotExisting()
Try
Using cn = New SqlConnection(cnString)
Using cmd = cn.CreateCommand()
cn.Open()
!!. #$%&'() * 5=>4?@A!B(%%".&")!B#6//"/
cmd.CommandText = _
"IF NOT EXISTS ( " _
& " SELECT * FROM sys.Tables WHERE NAME='Vehicles') " _
& " CREATE TABLE Vehicles( " _
& " VIN varchar(20) PRIMARY KEY, " _
& " Make varchar(20), " _
& " Model varchar(20), Year int)"
cmd.ExecuteNonQuery()
cmd.CommandText = _
"IF NOT EXISTS ( " _
& " SELECT * FROM sys.Tables WHERE NAME='Repairs') " _
& " CREATE TABLE Repairs( " _
& " ID int IDENTITY PRIMARY KEY, " _
& " VIN varchar(20), " _
& " Description varchar(60), " _
& " Cost money)"
cmd.ExecuteNonQuery()
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
-./!0*)$&)#6)#$5*
private void CreateTablesIfNotExisting()
{
try
{
using( var cn = new SqlConnection(cnString))
using( var cmd = cn.CreateCommand())
{
cn.Open();
cmd.CommandText =
"IF NOT EXISTS ( "
+ " SELECT * FROM sys.Tables WHERE NAME='Vehicles') "
+ " CREATE TABLE Vehicles( "
+ " VIN varchar(20) PRIMARY KEY, "
+ " Make varchar(20), "
+ " Model varchar(20), Year int)";
cmd.ExecuteNonQuery();
cmd.CommandText =
"IF NOT EXISTS ( "
+ " SELECT * FROM sys.Tables WHERE NAME='Repairs') "
+ " CREATE TABLE Repairs( "
+ " ID int IDENTITY PRIMARY KEY, "
+ " VIN varchar(20), "
+ " Description varchar(60), "
+ " Cost money)";
cmd.ExecuteNonQuery();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
! J"//(%!KD!G"6)*%1!6%)!<0*&*%1!=6&6! #$%&'() * !!/
}
}
$("! 5))!&-"!=5" 9'('!$"&-()!&-6&!:"0+(0$/!&-"!6.&;6#!)6&6!/,%.-0(%*E6&*(%4!A-*/!$"&-()!
%"")/!&(!/"%)!.#*"%&7/*)"!.-6%1"/!&(!&-"!)6&696/"!6%)!&-"%!0"."*8"!6##!/"08"07/*)"!
.-6%1"/4
-./!0*)$&)1'23.0)4.2'+)#$5*
Private Sub SyncData()
'send changes
Try
daVehicles.Update(ds, "Vehicles")
daRepairs.Update(ds, "Repairs")
ds.AcceptChanges()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
'retrieve updates
Dim tempVehicles As New DataTable()
daVehicles.Fill(tempVehicles)
ds.Tables("Vehicles").Merge(tempVehicles)
'merge changes
Dim tempRepairs As New DataTable()
daRepairs.Fill(tempRepairs)
ds.Tables("Repairs").Merge(tempRepairs)
End Sub
-./!0*)$&)#6)#$5*
private void SyncData()
{
//send changes
try
{
daVehicles.Update(ds, "Vehicles");
daRepairs.Update(ds, "Repairs");
ds.AcceptChanges();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
//retrieve updates
var tempVehicles = new DataTable();
daVehicles.Fill(tempVehicles);
ds.Tables["Vehicles"].Merge(tempVehicles);
//merge changes
var tempRepairs = new DataTable();
daRepairs.Fill(tempRepairs);
ds.Tables["Repairs"].Merge(tempRepairs);
}
!!0 #$%&'() * 5=>4?@A!B(%%".&")!B#6//"/
$)"! 5))!.()"!&(!&-"!*!&+,-07!<)"$!"8"%&!&(!/,%.-0(%*E"!&-"!)6&6!3-"%!&-"!6::#*.6&*(%!*/!
"%)*%14!T(;0!.($:#"&")!*!&+,-07!<)"$!$"&-()!/-(;#)!9"!6/!+(##(3/D
-./!0*)$&)1'23.0)4.2'+)#$5*
Private Sub Form1_FormClosing(ByVal sender As System.Object, _
ByVal e As FormClosingEventArgs) _
Handles MyBase.FormClosing
Synchronize()
ds.WriteXml(xmlFile, XmlWriteMode.DiffGram)
End Sub
-./!0*)$&)#6)#$5*
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Synchronize();
ds.WriteXml(xmlFile, XmlWriteMode.DiffGram);
}
$*"! W;*#)!&-"!6::#*.6&*(%!6%)!.(00".&!6%,!"00(0/4
$+"! A"/&!&-"!6::#*.6&*(%4!P0"//!HX!&(!0;%!&-"!6::#*.6&*(%!3*&-!&-"!)"9;11"04!
<-"%!&-"!6::#*.6&*(%!/&60&/'!*&!#(6)/!&-"!(+Y*%"!ZVJ!M#"!*+!*&!"C*/&/4!L&!&-"%!.-".2/!
3-"&-"0!*&!.6%!.(%%".&!&(!QRJ!Q"08"04!L+!6!.(%%".&*(%!.6%!9"!$6)"'!&-"!6::#*.6&*(%!
&-"%!.0"6&"/!&-"!&69#"/!*+!&-",!)(%N&!"C*/&!6%)!6&&"$:&/!&(!/,%.-0(%*E"!&-"!.#*"%&7/*)"!
)6&6!3*&-!&-"!/"08"07/*)"!)6&64
<-"%!,(;!.#(/"!&-"!6::#*.6&*(%'!6!.6##!*/!$6)"!&(!/,%.-0(%*E"!&-"!)6&6'!6%)!&-"%!&-"!
)6&6!/"&!*/!/"0*6#*E")!&(!&-"!(+Y*%"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#C$%-$%0<!%
;,!E-#+"%0C#%!R/6;:!"'
?14@)#%*!%A'(.1)%:1('B%9*5#
Dim aBinding As New Binding()
aBinding.ElementName = "Slider1"
aBinding.Path = New System.Windows.PropertyPath("Value")
' In the previous two examples, the Name property of the Label was not set.
' In this example, a name is required so it is assumed to be Label1.
Label1.SetBinding(ContentProperty, aBinding)
?14@)#%*!%9C%9*5#
Binding aBinding = new Binding();
aBinding.ElementName = "Slider1";
aBinding.Path = new System.Windows.PropertyPath("Value");
// In the previous two examples, the Name property of the Label was not set.
// In this example, a name is required so it is assumed to be Label1.
Label1.SetBinding(ContentProperty, aBinding);
F#%,!6#E!%/%9-$2-$*%28$/6->/::8?%8#+%>/::%0<!% !"#!"$<)'.*+!&"0DE4'*. !"#!"$%6!0<#2?%/"%
"<#C$%<!,!'
?14@)#%*!%A'(.1)%:1('B%9*5#
BindingOperations.ClearBinding(Me.Label1, ContentProperty)
www.it-ebooks.info
')DE !"#$%&'( 3#,7-$*%C-0<%./0/%1-$2-$*
?14@)#%*!%9C%9*5#
BindingOperations.ClearBinding(this.Label1, ContentProperty);
:'+5'+;%"*%1+%D0E#B"3<!$%9-$2-$*%0#%/$%#9=!>0%0</0%-"%$#0%/%345%!:!6!$0?%8#+%+"!%0<!%7&1.2'%;,#;!,08%0#%";!>-D8%
0<!%7&1.2'%#9=!>0@%F<-"%>/$%9!%/$8%#9=!>0%8#+%/,!%/9:!%0#%/>>!""%D,#6%0<!%TJG %E-!C@%3<!$%
9-$2-$*%0#%/%$#$H345%#9=!>0?%/%>#66#$%">!$/,-#%-"%0#%9-$2%0#%"0/0->%#9=!>0"%"+><%/"%"8"0!6%
>#:#,"%/$2%D#$0"@%F<!%D#::#C-$*%!R/6;:!%2!6#$"0,/0!"%<#C%0#%+"!%0<!%7&1.2'%;,#;!,08%0#%
9-$2%0<!% *29$.&1"#%;,#;!,08%#D%/%9+00#$%0#%0<!%7/0+'5E&4&.0DF!"#&GE&4&.%"0/0->%#9=!>0'
<Button Background="{Binding Source={x:Static SystemColors.WindowColor}}"
Height="23" Width="75">Button</Button>
A$%0<-"%!R/6;:!?%9!>/+"!%0<!% *29$.&1"#%;,#;!,08%-"%9#+$2%0#%0<!%9,+"<%!R;#"!2%98%
%7/0+'5E&4&.0DF!"#&GE&4&.?%8#+%>/$%#6-0%0<!%>*+?%;,#;!,08@
J$#0<!,%>#66#$%">!$/,-#%-"%0#%9-$2%0#%/%:#*->/:%,!"#+,>!@%S #*->/:%,!"#+,>!"%/,!%2-">+""!2%
-$%2!0/-:%-$%(</;0!,%&?%W1+-:2-$*%/%X"!,%A$0!,D/>!@YU%F<!%D#::#C-$*%>#2!%S"<#C$%-$%9#:2U%2!6H
#$"0,/0!"%9-$2-$*%0#%/%:#*->/:%,!"#+,>!@%A0%"<#C"%-6;#,0-$*%/%$/6!";/>!%D,#6%0<!%/;;:->/0-#$?%
>,!/0-$*%/$%-$"0/$>!%#D%/%>:/""%D,#6%0</0%$/6!";/>!%-$%0<!%F!"#&GD@'0&1.2'0%0/*?%/$2%0<!$%
9-$2-$*%0#%/%;,#;!,08%#D%0</0%-$"0/$>!'
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<local:aClass x:Key="theObject" />
</Window.Resources>
<Grid>
<Button Content="{Binding Source={StaticResource theObject},
Path=myProperty}" />
</Grid>
</Window>
F('+;%"&#%%&'&()"'*+'%=$*@#$"-
A0%-"%$#0%/>0+/::8%$!>!""/,8%0#%"!0%0<!%7&1.2'%;,#;!,08%/0%/::%0#%>,!/0!%/%2/0/%9-$2-$*@%B#+%
>/$%-$"0!/2%"!0%0<!%H*+*E&"+'I+%;,#;!,08%D#,%/$%!:!6!$0%#,%/%>#$0/-$!,%-$%0<!%E-"+/:%0,!!@%
AD%0<!%7&1.2'?%@'4*+!A'7&1.2'?%#,%34'5'"+%;,#;!,08%#D%/% !"#!"$%>:/""%-"%$#0%"!0?%345%:##7"%
D#,%/%%H*+*E&"+'I+%"!00-$*?%"0/,0-$*%C-0<%0<!%!:!6!$0%0</0%-"%9#+$2%98%0<!%9-$2-$*%/$2%0<!$%
6#E-$*%+;%0<!%E-"+/:%0,!!%+$0-:%/$%!:!6!$0%-"%D#+$2%D#,%C<-><%0<!%H*+*E&"+'I+%;,#;!,08%-"%
$#0%$+::@%F<!%#9=!>0%";!>-)!2%98%0<!%H*+*E&"+'I+%;,#;!,08%0<!$%"!,E!"%/"%0<!%"#+,>!%#9=!>0%
D#,%/::%9-$2-$*"%-$%0</0%!:!6!$0Z"%E-"+/:%0,!!%0</0%2#%$#0%/:,!/28%</E!%0<!%7&1.2'?%34'5'"+?%#,%
%@'4*+!A'7&1.2'%;,#;!,08%"!0@%F<-"%-"%+"!D+:%D#,%9-$2-$*%6+:0-;:!%!:!6!$0"%-$%/%"-$*:!%>#$0/-$!,%
www.it-ebooks.info
% !""#$%&'%(#$)*+,-$*%./0/%1-$2-$*% !"#$%&'(' )D*
0#%0<!%"/6!%2/0/%"#+,>!@%F<!%:-$!"%#D%>#2!%"<#C$%-$%9#:2%-$%0<!%D#::#C-$*%!R/6;:!%2!6#$H
"0,/0!%0<!%H*+*E&"+'I+%;,#;!,08@%F<!%H*+*E&"+'I+%;,#;!,08%#D%0<!%*,-2%-"%"!0%0#%/%,!"#+,>!%
#9=!>0%>/::!2%*H*+*<-J'2+?%/$2%0<!$%0<!%E&"+'"+%;,#;!,08%#D%0<!%>#$0/-$!2%C*-'4%!:!6!$0%-"%
9#+$2%0#%/%6!69!,%#D%5/H*+*<-J'2+%$/6!2%5/=!+4'D%
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<local:myDataObject x:Key="aDataObject" />
</Window.Resources>
<Grid DataContext="{StaticResource aDataObject}">
<Label Content="{Binding Path=myTitle}" />
</Grid>
</Window>
J%>#66#$%">!$/,-#%C<!$%+"-$*%H*+*E&"+'I+%-"%0#%"!0%-0%-$%>#2!@%5#,%!R/6;:!?%0<-"%-"%
,!Q+-,!2%D,!Q+!$0:8%C<!$%+"-$*%J.K@LMF%#9=!>0"%0</0%6+"0%9!%-$-0-/:-[!2%-$%>#2!%/$2%>/$$#0%
9!%)::!2%2!>:/,/0-E!:8@%A$%0<-"%>/"!?%8#+%"0-::%>/$%>,!/0!%0<!%9-$2-$*"%2!>:/,/0-E!:8?%#6-00-$*%0<!%
7&1.2'%;,#;!,08?%/"%"<#C$%-$%9#:2%<!,!'
<Grid Name="Grid1">
<Label Content="{Binding Path=myTitle}" />
</Grid>
F<!$%"!0%0<!%H*+*E&"+'I+%;,#;!,08%-$%>#2!?%/"%"<#C$%<!,!'
?14@)#%*!%A'(.1)%:1('B%9*5#
Dim aDataObject As New myDataObject()
Grid1.DataContext = aDataObject
?14@)#%*!%9C%9*5#
myDataObject aDataObject = new myDataObject();
Grid1.DataContext = aDataObject;
3<!$%0<!%H*+*E&"+'I+%;,#;!,08%-"%"!0%-$%>#2!?%0<!%9#+$2%>#$0,#:"%/DD!>0!2%98%-0%C-::%$#0%
2-";:/8%/$8%9#+$2%2/0/%+$0-:%0<!%>#2!%"!00-$*%0<!%;,#;!,08%-"%!R!>+0!2@
:'+5'+;%"*% +B#("*$%=$*@#$"'#(%/'"&%"&#%,*-&'!.*/)012*%=$*@#$"-
F<!%@'4*+!A'7&1.2'%;,#;!,08%!$/9:!"%8#+%0#%>,!/0!%9-$2-$*"%0</0%";!>-D8%/%"#+,>!%!:!6!$0%-$%/%
;#"-0-#$%-$%0<!%E-"+/:%0,!!%,!:/0-E!%0#%0<!%0/,*!0%!:!6!$0@%F<!%08;!%#D%@'4*+!A'7&1.2'%9-$2-$*%-"%
2!0!,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(</;0!,%_?%W3#,7-$*%C-0<%X"!,H
.!)$!2%(#$0,#:"@Y
3<!$%9-$2-$*%0#%/$%/$>!"0#,%"#+,>!%#9=!>0?%8#+%6+"0%"!0%9#0<%0<!%K"2'0+&.=/)'%/$2%0<!%
%K"2'0+&.C'A'4%;,#;!,0-!"@%F<!%K"2'0+&.=/)'%;,#;!,08%";!>-)!"%0<!%08;!%#D%"#+,>!%#9=!>0%0#%
9-$2%0#?%/$2%0<!%K"2'0+&.C'A'4%;,#;!,08%-$2->/0!"%<#C%6/$8%:!E!:"%+;%-$%:!01*4=.''%0<!%/$>!"H
0#,%-"%:#>/0!2@%F<!%D#::#C-$*%!R/6;:!%2!6#$"0,/0!"%9-$2-$*%0<!%E&"+'"+%;,#;!,08%#D%/%9+00#$%
0#%0<!%=*$%;,#;!,08%#D%0<!%*,-2%0</0%>#$0/-$"%0<!%9+00#$'
<Grid Tag="Button Text">
<Button Content="{Binding Path=Tag, RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Grid, AncestorLevel=1}}"
Height="23" Width="75">
</Button>
</Grid>
1!>/+"!%"!00-$*%"#%6/$8%;,#;!,0-!"%-$:-$!%>/$%9!%>+69!,"#6!?%8#+%6-*<0%)$2%-0%6#,!%
+"!D+:%0#%+"!%0<!%6#,!%D#,6/:%"8$0/R?%/"%"<#C$%<!,!'
<Grid Tag="Button Text">
<Button Height="23" Name="Button1" VerticalAlignment="Bottom">
<Button.Content>
<Binding Path="Tag">
<Binding.RelativeSource>
<RelativeSource Mode="FindAncestor" AncestorType="Grid"
AncestorLevel="1" />
</Binding.RelativeSource>
</Binding>
</Button.Content>
</Button>
</Grid>
www.it-ebooks.info
% !""#$%&'%(#$)*+,-$*%./0/%1-$2-$*% !"#$%&'(' )D)
?#""'+;%"&#%:'+5'+;%G*5#F<!% !"#!"$D%&#'%;,#;!,08%2!0!,6-$!"%<#C%9#+$2%>#$0,#:"%9!</E!%-$%,!";#$"!%0#%></$*H
!"%-$%!-0<!,%0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*/D%
J%E/:+!%#D%<"'F*/%-"%08;->/::8%+"!2%-$%/;;:->/0-#$"%0</0%2-";:/8%2/0/%9+0%2#%$#0%/::#C%2/0/%0#%
9!%!2-0!2@%J%E/:+!%#D%=G&F*/%-"%6#,!%>#66#$:8%+"!2%-$%2/0/H!2-0-$*%/;;:->/0-#$"?%C<!,!%0<!%
2/0/%-$%0<!%"#+,>!%-"%2-";:/8!2%9+0%0<!%+"!,%</"%0<!%#;0-#$%#D%!2-0-$*%0</0%2/0/%/$2%"/E-$*%-0%0#%
0<!%"#+,>!%#9=!>0@
:'+5'+;%"*%1%H.))10)#%A1).#J0%0-6!"%8#+%6-*<0%C/$0%0#%9-$2%0#%/%E/:+!%#D%/%2/0/%08;!%0</0%>/$%9!%$+::@%F#%;,#E-2!%/%
2!D/+:0%E/:+!?%8#+%>/$%"!0%=*.$'+6144:*41'%0#%/%E/:+!%-D%0<!%0/,*!0%E/:+!%-"%$+::@%F<!%D#::#C-$*%
!R/6;:!%2!6#$"0,/0!"%9-$2-$*%0<!%='I+%;,#;!,08%#D%/%0!R0%9#R%0#%0<!%L0E?'29'#%;,#;!,08%#D%
/%><!>7%9#R?%C<-><%>/$%9!%=.1'?%8*40'?%#,%"144@%AD%0<!%E/:+!%#D%0<!%E?'29 &IDL0E?'29'#%E/:+!%-"%
$+::?%0<!%"0,-$*%Y]/:+!%L#0%I!:!>0!2Y%-"%2-";:/8!2%-$%0<!%0!R0%9#R@
<Grid>
<CheckBox Content="CheckBox" Name="CheckBox1" IsChecked="{x:Null}" />
www.it-ebooks.info
')DH !"#$%&'( 3#,7-$*%C-0<%./0/%1-$2-$*
<TextBox Text="{Binding ElementName=CheckBox1, Path=IsChecked,
TargetNullValue='Value Not Selected'}" HorizontalAlignment="Left"
Margin="0,29,0,0" Name="TextBox1" VerticalAlignment="Top" Width="120" />
</Grid>
?#""'+;%"&#%34#&'*/)012*51!$$*1%=$*@#$"-F<!%()#*+'7&1.2'=.!$$'.%;,#;!,08%>#$0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/>!%C-0<%/%@!2?='I+ &I%>#$0,#:%-$%C<-><%8#+%>/$%08;!%0!R0%/$2%#9"!,E!%0<!%
!DD!>0%#D%></$*-$*%8&"+8*5!4/%/$2%8&"+7!O'@%C!0+ &I?%#$%0<!%:!D0%#D%0<!%+"!,%-$0!,D/>!?%-"%
;#;+:/0!2%98%8&"+8*5!4/%$/6!"%/+0#6/0->/::8%C<!$%0<!%/;;:->/0-#$%#;!$"@%B#+%-6;:!H
6!$0%0<!%9-$2-$*"%0</0%6/7!%0<!%/;;:->/0-#$%C#,7@
,+% A$%TJG %E-!C?%/22%0#%0<!%@!2?='I+ &I%2!>:/,/0-#$%/% !"#!"$%#9=!>0%0</0%9-$2"%0<!%
%8&"+8*5!4/%;,#;!,08%0#%0<!%7'4'2+'#L+'5DE&"+'"+%;,#;!,08%#D%C!0+ &IPD%3<!$%)$-"<!2?%
8#+,%>#2!%"<#+:2%,!"!69:!%0<-"?%C-0<%0<!%/22!2%9-$2-$*%"<#C$%-$%9#:2'
<RichTextBox FontFamily="{Binding ElementName=listBox1,
Path=SelectedItem.Content}" Grid.Column="2" Name="richTextBox1" />
-+% J22%/%9-$2-$*%0#%0<!%:#$*!,%#D%0<!%0C#%='I+ &I%>#$0,#:"%-$%0<!%0##:9/,%0#%9-$2%='I+%0#%
0<!%"!:!>0!2%-0!6%-$%C!0+ &ID%B#+,%>#2!%"<#+:2%:##7%:-7!%0<!%D#::#C-$*%C<!$%)$-"<!2'
<TextBox Text="{Binding ElementName=listBox1, Path=SelectedItem.Content}"
BorderBrush="Black" Width="100"></TextBox>
.+% J22%/%9-$2-$*%0#%9-$2%0<!%74!#'.%E/:+!%0#%0<!%8&"+7!O'%;,#;!,08%#D%@!2?='I+ &ID%B#+,%
>#2!%"<#+:2%,!"!69:!%0<!%D#::#C-$*%C<!$%)$-"<!2'
<RichTextBox FontSize="{Binding ElementName=Slider1, Path=Value}"
FontFamily="{Binding ElementName=listBox1, Path=SelectedItem.Content}"
Grid.Column="2"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$'.%;,#;!,08%0#%
>.&)'.+/E?*"$'#%"#%0</0%></$*!"%/,!%;,#;/*/0!2%/"%"##$%/"%/%$!C%E/:+!%-"%!$0!,!2@%
F<!%D#::#C-$*%!R/6;:!%2!6#$"0,/0!"%0<!%>#2!'
<TextBox Text="{Binding ElementName=Slider1, Path=Value, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" BorderBrush="Black"
Width="25"></TextBox>
0+% 4,!""%5_%0#%,+$%/$2%0!"0%8#+,%/;;:->/0-#$@
P#((*+%?.441$-■% F<!% !"#!"$%>:/""%2!)$!"%/%9-$2-$*%9!0C!!$%/%"#+,>!%/$2%/%0/,*!0@%F<!%34'5'"+6*5'%
;,#;!,08%-$2->/0!"%0<!%"#+,>!%C<!$%0<!%"#+,>!%-"%/%345%!:!6!$0@%F<!%@'4*+!A'7&1.2'%
;,#;!,08%-$2->/0!"%0<!%"#+,>!%C<!$%0<!%"#+,>!%#9=!>0%-"%:#>/0!2%-$%0<!%E-"+/:%0,!!%/0%/%
:#>/0-#$%,!:/0-E!%0#%0<!%0/,*!0?%/$2%0<!%7&1.2'%;,#;!,08%-2!$0-)!"%/%"#+,>!%0</0%-"%$#0%/%
345%!:!6!$0@
■% F<!%H*+*E&"+'I+%;,#;!,08%#D%!:!6!$0"%-"%+"!D+:%D#,%>,!/0-$*%0<!%*!$!,/:%2/0/%!$E-,#$H
6!$0%D#,%/%>#$0,#:%#,%>#$0/-$!,%>#$0,#:@%B#+%D,!Q+!$0:8%"!0%H*+*E&"+'I+%-$%>#2!%C<!$%
0<!%9-$2-$*%"#+,>!%6+"0%9!%-$-0-/:-[!2%-$%>#2!@%B#+%>/$%0<!$%>,!/0!% !"#!"$%#9=!>0"%-$%
TJG %0</0%2#%$#0%"!0%0<!%"#+,>!%/$2%-$"0!/2%)$2%0<!%$!/,!"0%"!0%H*+*E&"+'I+%;,#;!,08%
-$%0<!%E-"+/:%0,!!@
■% F<!%%&#'%;,#;!,08%!$/9:!"%8#+%0#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"!%/%>#$E!,0!,%0#%,!0+,$%/$%#9=!>0@
■ 5#,6/0%2/0/%>#$2-0-#$/::8%+"-$*%/%>#$E!,0!,@
■ #>/:-[!%2/0/%+"-$*%/%>#$E!,0!,@
■ A6;:!6!$0%L%14+!:*41'E&"A'.+'.@
3("'41"#5%)#((*+%"'4#2%67%4'+."#(
V4@)#4#+"'+;%:;&-0*()".*1'*1J0%0<!%>!$0!,%#D%>#$E!,"-#$%-"%0<!%L:*41'E&"A'.+'.%-$0!,D/>!?%C<-><%</"%0C#%6!69!,%6!0<#2"'%
E&"A'.+?%C<-><%>#$E!,0"%/$%-$;+0%08;!%0#%/$%#+0;+0%08;!V%/$2%E&"A'.+ *29?%C<-><%,!E!,"!"%0<!%
>#$E!,"-#$@%18%-6;:!6!$0-$*%L:*41'E&"A'.+'.?%8#+%>/$%>,!/0!%";!>-/:-[!2%>:/""!"%D#,%/%E/,-!08%
#D%>#$E!,"-#$%/$2%D#,6/00-$*%2+0-!"@%J$%!6;08%-6;:!6!$0/0-#$%#D%L:*41'E&"A'.+'.%-"%"<#C$%
<!,!'
?14@)#%*!%A'(.1)%:1('B%9*5#
Public Class myConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Throw New NotImplementedException()
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
!"#$%"&'(%)#((*+,%-*.%/'))%0#%10)#%"*2%
■ A6;:!6!$0%L:*41'E&"A'.+'.@L:*41'E&"A'.+'.L:*41'E&"A'.+'.
■ X"!%/%>#$E!,0!,%0#%D#,6/0%2/0/@
■ X"!%/%>#$E!,0!,%0#%,!0+,$%/$%#9=!>0@
■ 5#,6/0%2/0/%>#$2-0-#$/::8%+"-$*%/%>#$E!,0!,@
■ #>/:-[!%2/0/%+"-$*%/%>#$E!,0!,@
■ A6;:!6!$0%L%14+!:*41'E&"A'.+'.@L%14+!:*41'E&"A'.+'.L%14+!:*41'E&"A'.+'.
3("'41"#5%)#((*+%"'4#2%67%4'+."#(
www.it-ebooks.info
% !""#$%\'%(#$E!,0-$*%./0/% !"#$%&'(' )DC
?14@)#%*!%9C%9*5#
public class myConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
F<!%E&"A'.+%6!0<#2%>#$E!,0"%0<!%#9=!>0%,!;,!"!$0!2%98%0<!%E/:+!%;/,/6!0!,%-$0#%0<!%
%#+0;+0%#9=!>0?%/$2%0<!%E&"A'.+ *29%6!0<#2%,!E!,"!"%0<!%>#$E!,"-#$%;!,D#,6!2%98%0<!%
%E&"A'.+%6!0<#2@%A$%"#6!%>/"!"?%/%,!E!,"!%>#$E!,"-#$%-"%$#0%;#""-9:!?%/$2%-$%#0<!,%>/"!"%8#+%
$!E!,%>/::%0<!%E&"A'.+ *29%6!0<#2?%"#%-0%-"%>#66#$%;,/>0->!%$#0%0#%;,#E-2!%/$%!R;:->-0%-6;:!H
6!$0/0-#$%D#,%0<!%E&"A'.+ *29%6!0<#2%-D%-0%C-::%$!E!,%9!%>/::!2@%L#0!?%<#C!E!,?%0</0%D#,%>/"!"%
-$%C<-><%0C#HC/8%9-$2-$*%C-::%9!%-6;:!6!$0!2?%8#+%6+"0%-6;:!6!$0%9#0<%0<!%E&"A'.+%/$2%
E&"A'.+ *29%6!0<#2"@%X$:!""%8#+%/,!%>!,0/-$%0</0%E&"A'.+ *29%C-::%$!E!,%9!%>/::!2?%;,#E-2!%
/$%-6;:!6!$0/0-#$@
A$%/22-0-#$%0#%-6;:!6!$0-$*%L:*41'E&"A'.+'.?%8#+%6+"0%2!>#,/0!%0<!%>:/""%C-0<%0<!%
%:*41'E&"A'.0!&"%/00,-9+0!?%C<-><%";!>-)!"%0<!%"#+,>!%08;!%/$2%0<!%0/,*!0%08;!%D#,%0<!%>#$H
E!,0!,@%J$%!R/6;:!%0</0%";!>-)!"%/%"#+,>!%08;!%#D%L"+'$'.%/$2%/%0/,*!0%08;!%#D%7+.!"$%-"%"<#C$%
<!,!'
?14@)#%*!%A'(.1)%:1('B%9*5#
<ValueConversion(GetType(Integer), GetType(String))> _
?14@)#%*!%9C%9*5#
[ValueConversion(typeof(int), typeof(string))]
F<!%$!R0%!R/6;:!%"<#C"%/%"-6;:!%>#$E!,0!,%0</0%>#$E!,0"%/%$+6!,->%>#2!%,!;,!"!$0-$*%/%
=#9%0-0:!%-$0#%/%"0,-$*%>#$0/-$-$*%0</0%=#9%0-0:!?%/$2%E->!%E!,"/'
?14@)#%*!%A'(.1)%:1('B%9*5#
<ValueConversion(GetType(Integer), GetType(String))> _
Public Class myConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Dim a As Integer = CInt(value)
Select Case a
Case 1
www.it-ebooks.info
'))E !"#$%&'( 3#,7-$*%C-0<%./0/%1-$2-$*
Return "Group Manager"
Case 2
Return "Manager"
Case 3
Return "Programmer"
Case Else
Return "Title not defined"
End Select
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Dim aString As String = value.ToString()
Select Case aString
Case "Group Manager"
Return 1
Case "Manager"
Return 2
Case "Programmer"
Return 3
Case Else
Return 4
End Select
End Function
End Class
?14@)#%*!%9C%9*5#
[ValueConversion(typeof(int), typeof(string))]
public class myConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
int a = int.Parse(value.ToString());
switch (a)
{
case 1:
return "Group Manager";
case 2:
return "Manager";
case 3:
return "Programmer";
default:
return "Title not defined";
}
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
string a = value.ToString();
switch (a)
{
www.it-ebooks.info
% !""#$%\'%(#$E!,0-$*%./0/% !"#$%&'(' ))*
case "Group Manager":
return 1;
case "Manager":
return 2;
case "Programmer":
return 3;
default:
return 4;
}
}
}
F#%+"!%/%>#$E!,0!,%-$%8#+,%TJG %>#2!?%8#+%),"0%6+"0%>,!/0!%/%,!D!,!$>!%0#%0<!%$/6!";/>!%
0</0%>#$0/-$"%-0%-$%0<!%TJG ?%/"%"<#C$%-$%9#:2%<!,!'
<Window x:Class="WpfApplication5.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication5"
Title="Window1" Height="300" Width="300">
B#+%0<!$%6+"0%>,!/0!%/$%#9=!>0%-$"0/$>!?%08;->/::8%98%/22-$*%-0%0#%#$!%#D%0<!%!:!6!$0%
@'0&1.2'%>#::!>0-#$"?%/$2%/""-*$%/%7!8%E/:+!@%^!"#+,>!"%/,!%2-">+""!2%-$%2!;0<%-$%(</;0!,%&?%
W1+-:2-$*%/%X"!,%A$0!,D/>!@Y%J$%!R/6;:!%-"%"<#C$%<!,!'
<Window.Resources>
<local:myConverter x:Key="EmployeeConverter"></local:myConverter>
</Window.Resources>
JD0!,%/$%#9=!>0%-$"0/$>!%-"%>,!/0!2?%8#+%>/$%"!0%0<!%E&"A'.+'.%;,#;!,08%#D%8#+,%9-$2-$*%0#%-0%
98%,!D!,,-$*%0#%0<!%,!"#+,>!?%/"%"<#C$%<!,!'
<Label Content="{Binding Path=EmployeeCode, Converter={StaticResource
EmployeeConverter}}" />
G#"0%#D%0<!%>/"!"%2-">+""!2%-$%0<-"%></;0!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= aDouble.ToString("C")
?14@)#%*!%9C%9*5#
aString = aDouble.ToString("C");
B#+%>/$%-$>#,;#,/0!%0<-"%D+$>0-#$/:-08%-$0#%/%"-6;:!%>#$E!,0!,%0</0%0/7!"%/%H'2!5*4%
E/:+!%/$2%#+0;+0"%/%>+,,!$>8HD#,6/00!2%"0,-$*@%F<!%E&"A'.+%6!0<#2%#D%"+><%/%>#$E!,0!,%-"%
"<#C$%<!,!'
?14@)#%*!%A'(.1)%:1('B%9*5#
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Dim a As Decimal = CDec(value.ToString)
Return a.ToString("C")
End Function
?14@)#%*!%9C%9*5#
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
decimal a = decimal.Parse(value.ToString());
return a.ToString("C");
}
F<!%$!R0%!R/6;:!%"<#C"%0<!%E&"A'.+ *29%6!0<#2%D,#6%0<-"%"/6!%>#$E!,0!,'
?14@)#%*!%A'(.1)%:1('B%9*5#
Public Function ConvertBack(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Dim result As Decimal
Dim a As String = value.ToString()
If Decimal.TryParse(a, System.Globalization.NumberStyles.Any, Nothing, _
result) Then
Return result
Else
' Implement code to determine or return a default value here
Return 0
End If
End Function
?14@)#%*!%9C%9*5#
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
www.it-ebooks.info
% !""#$%\'%(#$E!,0-$*%./0/% !"#$%&'(' )))
decimal result;
string a = value.ToString();
if (decimal.TryParse(a, System.Globalization.NumberStyles.Any, null,
out result))
return result;
else
// Implement code to determine or return a default value here
return 0;
}
(+,,!$>8%D#,6/00-$*%0/7!"%0<!%>+,,!$0%>+:0+,!%"!00-$*%-$0#%/>>#+$0@%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+$2%-$%0<!%]-"+/:%I0+2-#%2#>+6!$0/0-#$@%b#C!E!,?%8#+%
6-*<0%$!!2%0#%>,!/0!%/%>#$E!,0!,%0#%>#$E!,0%0#%/%>+"0#6%"0,-$*%D#,6/0@%A$%0</0%>/"!?%8#+%</E!%
0#%C,-0!%>#2!%0#%;!,D#,6%0<!%>#$E!,"-#$%!R;:->-0:8@%F<!%D#::#C-$*%!R/6;:!%2!6#$"0,/0!"%/%
www.it-ebooks.info
'))H !"#$%&'( 3#,7-$*%C-0<%./0/%1-$2-$*
>#$E!,0!,%0</0%/>>!;0"%/%$-$!H2-*-0%-$0!*!,%/$2%,!0+,$"%/%"0,-$*%,!;,!"!$0/0-#$%#D%0</0%-$0!*!,%
D#,6/00!2%/"%/%I#>-/:%I!>+,-08%$+69!,'
?14@)#%*!%A'(.1)%:1('B%9*5#
<ValueConversion(GetType(Integer), GetType(String))> _
Public Class SSConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Dim a As String = value.ToString()
If Not a.Length = 9 Then
Throw New ArgumentException("Number is in the wrong format")
End If
a = a.Insert(5, "-")
a = a.Insert(3, "-")
Return a
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Dim a As String = value.ToString()
a = a.Remove(6, 1)
a = a.Remove(3, 1)
Return CInt(a)
End Function
End Class
?14@)#%*!%9C%9*5#
[ValueConversion(typeof(int), typeof(string))]
public class SSConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
string a = value.ToString();
if (!(a.Length==9))
throw new ArgumentException("Number is in the wrong format");
a = a.Insert(5, "-");
a = a.Insert(3, "-");
return a;
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
string a = value.ToString();
a = a.Remove(6, 1);
a = a.Remove(3, 1);
www.it-ebooks.info
% !""#$%\'%(#$E!,0-$*%./0/% !"#$%&'(' ))I
return int.Parse(a);
}
}
F('+;%9*+O#$"#$(%"*%Q#".$+%D0E#B"(A$%/22-0-#$%0#%D#,6/00-$*?%8#+%>/$%,!0+,$%#9=!>0"%+"-$*%>#$E!,0!,"@%5#,%!R/6;:!?%8#+%6-*<0%
"0#,!%,!D!,!$>!"%0#%-6/*!"%/"%"0,-$*%;/0<"%-$%8#+,%2/0/9/"!%9+0%C/$0%0#%:#/2%/$2%2-";:/8%0<!%
-6/*!"%C<!$%E-!C-$*%2/0/@%^!0+,$-$*%/$%#9=!>0%-"%/"%"-6;:!%/"%>,!/0-$*%0<!%#9=!>0%-$%>#2!%/$2%
,!0+,$-$*%-0%/"%"<#C$%-$%;,!E-#+"%!R/6;:!"@%F<!%D#::#C-$*%!R/6;:!%0/7!"%/%"0,-$*%D#,6/00!2%/"%
/%;/0<%/$2%,!0+,$"%/% !+5*)L5*$'%#9=!>0%0</0%,!;,!"!$0"%0<!%-6/*!%"0#,!2%/0%0</0%;/0<'
?14@)#%*!%A'(.1)%:1('B%9*5#
<ValueConversion(GetType(String), GetType(BitmapImage))> _
Public Class ImageConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Try
Dim myPath As String = CType(value, String)
Dim myUri As New Uri(myPath)
Dim anImage As New BitmapImage(myUri)
Return anImage
Catch ex As Exception
Return New BitmapImage(New Uri("C:\ImageNotAvailable.jpg"))
End Try
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType _
As System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
Sample of C# Code
[ValueConversion(typeof(string), typeof(BitmapImage))]
public class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
try
{
string myPath = (string)value;
Uri myUri = new Uri(myPath);
BitmapImage anImage = new BitmapImage(myUri);
www.it-ebooks.info
'))( !"#$%&'( 3#,7-$*%C-0<%./0/%1-$2-$*
return anImage;
}
catch
{
return new BitmapImage(new Uri("C:\\ImageNotAvailable.jpg"));
}
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
A$%0<-"%!R/6;:!?%/%"0,-$*%-"%>#$E!,0!2%0#%/%X$-E!,"/:%^!"#+,>!%A2!$0-)!,%SX^AU?%/$2%0<!$%0</0%
X^A%*!$!,/0!"%0<!% !+5*)L5*$'%0</0%-"%,!0+,$!2@%A$%0<!%!E!$0%#D%/$%!,,#,?%/%2!D/+:0%-6/*!%-"%
,!0+,$!2@%L#0!%0</0%9!>/+"!%-0%C#+:2%9!%;,#9:!6/0->%0#%>#$E!,0%/$%-6/*!%9/>7%0#%/%;/0<?%
0<!%E&"A'.+ *29%6!0<#2%-"%$#0%-6;:!6!$0!2@%L!E!,0<!:!""?%-0%-"%/%9!"0%;,/>0->!%0#%-6;:!6!$0%
E&"A'.+ *29%C<!$!E!,%;#""-9:!@
P*B1)'X'+;%W1"1%/'"&%9*+O#$"#$((#$E!,0!,"%>/$%9!%+"!D+:%D#,%:#>/:-[-$*%2/0/@%J:0<#+*<%"#6!%9+-:0H-$%>#$E!,"-#$"%S"+><%/"%0<!%
"0,-$*%>+,,!$>8%>#$E!,"-#$U%0/7!%0<!%>+,,!$0%>+:0+,!%-$0#%/>>#+$0?%0<!,!%/,!%"!E!,/:%>/"!"%-$%
C<-><%8#+%$!!2%0#%;,#E-2!%8#+,%#C$%:#>/:-[/0-#$%>#2!@
F<!%;/,/6!0!,"%D#,%0<!%E&"A'.+%/$2%E&"A'.+ *29%6!0<#2"%>#$0/-$%/%,!D!,!$>!%0#%0<!%
E14+1.'%#9=!>0%0#%9!%+"!2%D#,%0<!%>#$E!,"-#$@%B#+%>/$%!R/6-$!%0<!%E/:+!%#D%0<-"%;/,/6!0!,%
/$2%+"!%0</0%-$D#,6/0-#$%0#%,!0+,$%:#>/:-[!2%2/0/@%F<!%D#::#C-$*%!R/6;:!%2!6#$"0,/0!"%/%
>#$E!,0!,%0</0%,!/2"%0<!%E14+1.'%#9=!>0%;,#E-2!2%/$2%-$E#7!"%/%6!0<#2%#$%/%0,/$":/0-#$%>:/""%
0</0%,!0+,$"%0<!%/;;,#;,-/0!%"0,-$*%D#,%0<!%>+:0+,!@%F<-"%!R/6;:!%/""+6!"%0</0%0<-"%/;;:->/H
0-#$%6-*<0%9!%,+$%-$%0<!%X$-0!2%I0/0!"?%5,/$>!?%#,%O!,6/$8%/$2%;,#E-2!"%6!0<#2"%0#%>#$E!,0%
M$*:-"<%"0,-$*"%0#%O!,6/$%/$2%5,!$><%"0,-$*"?%/$2%E->!%E!,"/'
?14@)#%*!%A'(.1)%:1('B%9*5#
<ValueConversion(GetType(String), GetType(String))> _
Public Class DateBrushConverter
Implements IValueConverter
' Note: the Translator class is assumed to be a class that contains a
' dictionary used to translate the provided strings.
Dim myTranslator As New Translator
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Dim astring As String = CType(value, String)
Select Case culture.ToString
Case "fr-FR"
Return myTranslator.EnglishToFrench(astring)
Case "de-DE"
www.it-ebooks.info
% !""#$%\'%(#$E!,0-$*%./0/% !"#$%&'(' ))+
Return myTranslator.FrenchToEnglish(astring)
Case Else
Return astring
End Select
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType _
As System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Dim astring As String = CType(value, String)
Select Case culture.ToString
Case "fr-FR"
Return myTranslator.FrenchToEnglish(astring)
Case "de-DE"
Return myTranslator.GermanToEnglish(astring)
Case Else
Return astring
End Select
End Function
End Class
?14@)#%*!%9C%9*5#
[ValueConversion(typeof(string), typeof(string))]
public class LanguageConverter : IValueConverter
{
// Note: the Translator class is assumed to be a class that contains a
// dictionary used to translate the provided strings.
Translator myTranslator = new Translator();
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
string aString = (string)value;
switch(culture.ToString())
{
case "de-DE":
return myTranslator.EnglishToGerman(aString);
case "fr-FR":
return myTranslator.EnglishToFrench(aString);
default:
return aString;
}
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
string aString = (string)value;
switch(culture.ToString())
{
case "de-DE":
return myTranslator.GermanToEnglish(aString);
case "fr-FR":
return myTranslator.FrenchToEnglish(aString);
default:
www.it-ebooks.info
'))B !"#$%&'( 3#,7-$*%C-0<%./0/%1-$2-$*
return aString;
}
}
}
J46KL' M-KL
■% W#(B$'0#%"&#%;#+#$1)%@$*B#((%!*$%.('+;%1%B*+O#$"#$%"*%1@@)-%B*+5'"'*+1)%!*$K
41""'+;%!*$%0*.+5%51"1L
J46KL' M-KL'"0.N-5
■% >'$(",%-*.%4.("%'4@)#4#+"%1%B*+O#$"#$%"&1"%@#$!*$4(%"&#%1@@$*@$'1"#%B*+O#$K
('*+L%>*$%#J14@)#,%'!%-*.%/1+"#5%"*%&';&)';&"%$#B*$5(%/'"&%1%%&'*%@$*@#$"-%
O1).#%*)5#$%"&1+%67%51-(,%-*.%/*.)5%'4@)#4#+"%1%B*+O#$"#$%"&1"%B&1+;#5%1%
%&'*5!7*%O1).#%'+"*%1%()-)1%O1).#%01(#5%*+%"&#%O1).#%*!%"&#%%&'*5!7*%@$*@K
#$"-L% !"#$%"&#%B*+O#$"#$%&1(%0##+%'4@)#4#+"#5,%-*.%(&*.)5%0'+5%"&#%1@@$*K
@$'1"#%O1).#%'+%"&#%51"1%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J'2+%/,,/8%/$2%0/7!"%/%=/)'%/,,/8%/"%#$!%#D%0<!%;/,/6H
!0!,"@%J$%+$-6;:!6!$0!2%!R/6;:!%-"%"<#C$%<!,!'
?14@)#%*!%A'(.1)%:1('B%9*5#
Public Class myMultiConverter
Implements IMultiValueConverter
Public Function Convert(ByVal values As Object(), ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IMultiValueConverter.Convert
Throw New NotImplementedException()
End Function
J46KL' M-KL
■ W#(B$'0#%"&#%;#+#$1)%@$*B#((%!*$%.('+;%1%B*+O#$"#$%"*%1@@)-%B*+5'"'*+1)%!*$K
41""'+;%!*$%0*.+5%51"1L
J46KL' M-KL'"0.N-5
■ >'$(",%-*.%4.("%'4@)#4#+"%1%B*+O#$"#$%"&1"%@#$!*$4(%"&#%1@@$*@$'1"#%B*+O#$K
('*+L%>*$%#J14@)#,%'!%-*.%/1+"#5%"*%&';&)';&"%$#B*$5(%/'"&%1%%&'*%@$*@#$"-%
O1).#%*)5#$%"&1+%67%51-(,%-*.%/*.)5%'4@)#4#+"%1%B*+O#$"#$%"&1"%B&1+;#5%1%
%&'*5!7*%O1).#%'+"*%1%()-)1%O1).#%01(#5%*+%"&#%O1).#%*!%"&#%()-)1 %&'*5!7*%@$*@K
#$"-L% !"#$%"&#%B*+O#$"#$%&1(%0##+%'4@)#4#+"#5,%-*.%(&*.)5%0'+5%"&#%1@@$*K
@$'1"#%O1).#%'+%"&#%51"1%"#4@)1"#%"*%"&#%@$*@#$"-%"&1"%'(%B*+O#$"#5%1+5%(.@@)-%
1%$#!#$#+B#%"*%"&#%B*+O#$"#$%'+%"&#% !"#!"$%*0E#B"L%V+%"&'(%#J14@)#,%-*.%/*.)5%
0'+5%"&#% &2<$1)0"#%@$*@#$"-%*!%"&#%B*+"$*)%'+%"&#%51"1%"#4@)1"#,%/&'B&%'(% &2<$1)0"#
.(#5%"*%@$#(#+"%"&#%51"1,%"*%"&#%%&'*%@$*@#$"-%1+5%$#!#$#+B#%1+%'+("1+B#%*!%
"&#%B*+O#$"#$%'+%"&1"%0'+5'+;L%
www.it-ebooks.info
% !""#$%\'%(#$E!,0-$*%./0/% !"#$%&'(' ))C
Public Function ConvertBack(ByVal value As Object, ByVal targetTypes() _
As System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object() Implements _
System.Windows.Data.IMultiValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
!"#$%&'(&)*&)'+%
public class myMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
public object[] ConvertBack(object value, Type[] targetTypes, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
!"#$%&&%'()*#"+,-.&"#/"-%)012,1"0#!%'#1%#(-.&"-")1# !"#$%&'#"()*+,(-$(-.# !(0#"+,-3
.&"#1,4"0#,)# +$(/(-#%56"71#,)/#,#0(1%2'##%56"71#1!,1#2".2"0")1#8)(10#%2/"2"/#,)/#8)(1#.2(7"9#
2"0."71(:"&;9#,)/#2"182)0#,#7822")7;3$%2-,11"/#012()*#1!,1#2".2"0")10#1!"#1%1,&#.2(7"<
!"#$%&'(&,-./!$&0!.-1&)'+%
Public Class TotalCostConverter
Implements IMultiValueConverter
Public Function Convert(ByVal values() As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IMultiValueConverter.Convert
Dim UnitsOrdered As Integer = CType(values(0), Integer)
Dim UnitCost As Decimal = CType(values(1), Decimal)
Dim TotalCost As Decimal = UnitsOrdered * UnitCost
Return TotalCost.ToString("C")
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetTypes() _
As System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object() Implements _
System.Windows.Data.IMultiValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
!"#$%&'(&)*&)'+%
public class TotalCostConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object
www.it-ebooks.info
!"# $%&'()* + =%24()*#'(1!#>,1,#?()/()*
parameter, System.Globalization.CultureInfo culture)
{
int UnitsOrdered = (int)values[0];
decimal UnitCost = (decimal)values[1];
decimal TotalCost = UnitsOrdered * UnitCost;
return TotalCost.ToString("C");
}
public object[] ConvertBack(object value, Type[] targetTypes, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
%#5()/#,#.2%."21;#1%#,#:,&8"#2"182)"/#5;#,#-8&1(3:,&8"#7%):"21"29#;%8#-801#72",1"#,#2"$"23
")7"#1%#1!"#,00"-5&;#1!,1#7%)1,()0#1!"#-8&1(3:,&8"#7%):"21"2#,)/#1!")#,//#,)#()01,)7"#1%#,)#
,:,(&,5&"#2"0%827"#7%&&"71(%)9#,0#;%8#0,'#",2&("2#()#1!(0#&"00%)@# %#,718,&&;#72",1"#1!"#5()/3
()*9#!%'":"29#;%8#-801#80"#,#7&,00#7,&&"/#!"#$%3%+4%+/.# !"#!"#$%3%+4%+/#7&,00#(0#"00")1(,&&;#
,#7%&&"71(%)#%$#5()/()*0#1!,1#0."7(A"0#,#7%):"21"2#1!,1#1,4"0#1!"#:,&8"#%$#1!%0"#5()/()*0#()1%#
,77%8)1@#B%8#7,)#0"1#,#.2%."21;#1%#,#!"#$%3%+4%+/#%56"71#()#1!"#0,-"#-,))"2#1!,1#;%8#'%8&/#
0"1#(1#1%#,#3%+4%+/#%56"71@# !"#$%&&%'()*#"+,-.&"#/"-%)012,1"0#0"11()*#1!"#)*+$(+$#.2%."21;#
%$#,#5'6(##"&"-")1#1%#1!"#:,&8"#2"182)"/#5;#,)#()01,)7"#%$#1!"#7*$'#)*8$)*+,(-$(-#7&,00#80"/#
()#1!"#.2":(%80#"+,-.&"@# !(0#"+,-.&"#,008-"0#1!,1#;%8#!,:"#72",1"/#,)#()01,)7"#%$#1!(0#
7%):"21"2#()#1!"#9%+4*:.;(8*"-1(8#7%&&"71(%)#'(1!#,#4";#:,&8"#%$#2<7*$'#)*8$)*+,(-$(-#,)/#
1!,1#1!"#0'$')*+$(=$#.2%."21;#%$#9%+4*:#!,0#5"")#0"1#1%#,)#%56"71#'(1!#.2%."21("0#),-"/#
>+%$8?@-4(-(4#,)/#>+%$)*8$<
<Label>
<Label.Content>
<MultiBinding Converter="{StaticResource myTotalCostConverter}">
<Binding Path=UnitsOrdered />
<Binding Path=UnitCost />
</MultiBinding>
</Label.Content>
</Label>
!"#$%&$' &,,-./01 234/01 5647833/01 809 $609/3/608- 5647833/01
C)#1!(0#.2,71(7"9#;%8#80"#7801%-#7%):"21"20#1%#.2%:(/"#012()*#$%2-,11()*#,)/#7%)/(1(%),&#$%23
-,11()*#()#;%82#,..&(7,1(%)@
'('"$&)' * 2.-34&!&)'35%67%6&7'&8##$9& 76-34&:'6"!77-34
*+# D.")#1!"#.,21(,�%&81(%)#$%2#1!(0#&"00%)@#E2"00#FG#1%#7%-.(&"#,)/#28)#1!"#,..&(7,1(%)@#
H%1"#1!,1#7801%-"2#2"7%2/0#,2"#/(0.&,;"/#()#1!"#8.."23&"$1#I%)1,71#H,-"#&(01#5%+9#
,)/#'!")#;%8#7&(74#,#7801%-"2#2"7%2/9#/,1"0#()/(7,1()*#%2/"2#/,1"0#,2"#/(0.&,;"/#()#
1!"#8.."232(*!1#&(01#5%+@#C)#1!(0#&"00%)9#;%8#'(&&#,//#7%&%2#7%/()*#1%#1!"0"#/,1"0#5,0"/#
www.it-ebooks.info
# J"00%)#K<#I%):"21()*#>,1,# $%&'()* + !":
%)#1!"#;",2@#C)#1!"#)"+1#7!,.1"29#;%8#'(&&#/2(&&#/""."2#()1%#1!"#$8)71(%),&(1;#5"!()/#1!(0#
,..&(7,1(%)@
,+# C)#1!"#7%/"#'()/%'9#5")",1!#1!"#)*"+$-<A-*"B(-#7&,009#,//#1!"#$%&&%'()*#7&,00#1%#
7%):"21#,#0(1%2'##:,&8"#1%#,#7822")7;3$%2-,11"/#012()*<
!"#$%&'(&,-./!$&0!.-1&)'+%
<ValueConversion(GetType(Decimal), GetType(String))> _
Public Class CurrencyConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Dim aDec As Decimal
aDec = CDec(value)
Return aDec.ToString("C")
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Throw (New NotImplementedException)
End Function
End Class
!"#$%&'(&)*&)'+%
[ValueConversion(typeof(Decimal), typeof(String))]
public class CurrencyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
decimal aDec;
aDec = (decimal)value;
return aDec.ToString("C");
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
-+# C)#1!"#C'2(8B'1(8#0"71(%)#%$#LMNJ#:("'9#,//#1!"#$%&&%'()*#&()"#1%#(-.%21#1!"#&%3
7,&#),-"0.,7"#()1%#LMNJ#:("'9#'!"2"#O#*1'#D+'2(8B'1(D+'2(P#2".2"0")10#1!"#
),-"0.,7"#%$#;%82#&%7,&#.2%6"719#$%2#"+,-.&"9#;<==60>?<
xmlns:local="clr-namespace:<local namespace name>”
www.it-ebooks.info
!"? $%&'()* + =%24()*#'(1!#>,1,#?()/()*
.+# Q801#5"$%2"#1!"#A-%4#/"7&,2,1(%)#()#LMNJ#:("'9#,//#1!"#$%&&%'()*#9%+4*:8.;(8*"-1(8#
0"71(%)#1%#72",1"#,)#()01,)7"#%$#)"--(+1<)*+,(-$(-<
<Window.Resources>
<local:CurrencyConverter x:Key="myCurrencyConverter" />
</Window.Resources>
/+# F2%-#1!"#?8(&/#-")89#7!%%0"#?8(&/#R%&81(%)@
0+# C)#1!"#LMNJ#:("'9#()#0'$'7(2B#'$(#$%2##%8$3*=EF#7!,)*"#1!"#&,01#5'6(##/"7&,2,1(%)#1%#
2",/#,0#0!%')#()#5%&/#!"2"<
<Label Background="Red" Content="{Binding Path=ExtendedPrice,
Converter={StaticResource myCurrencyConverter}}" Width="60" />
1+# E2"00#FG#1%#58(&/#,)/#28)#;%82#,..&(7,1(%)@#H%1"#1!,1#1!"#A"&/#2".2"0")1()*#1%1,&#.2(7"#
$%2#%2/"20#)%'#(0#$%2-,11"/#,0#7822")7;@
'('"$&)' , 2.-34&!&)'35%67%6&7'&8##$9&)'3+-7-'3!$&:'6"!77-34
*+# C)#7%/"#:("'9#5")",1!#1!"#7%/"#$%2#)"--(+1<)*+,(-$(-9#,//#1!"#$%&&%'()*#7&,00<
!"#$%&'(&,-./!$&0!.-1&)'+%
<ValueConversion(GetType(DateTime), GetType(Brush))> _
Public Class YearConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Dim aDate As DateTime
aDate = CDate(value)
Select Case aDate.Year.ToString
Case "1994"
Return New SolidColorBrush(Colors.Purple)
Case "1995"
Return New SolidColorBrush(Colors.Green)
Case "1996"
Return New SolidColorBrush(Colors.Red)
Case Else
Return New SolidColorBrush(Colors.Yellow)
End Select
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Throw New NotImplementedException
End Function
End Class
!"#$%&'(&)*&)'+%
[ValueConversion(typeof(DateTime), typeof(Brush))]
www.it-ebooks.info
# J"00%)#K<#I%):"21()*#>,1,# $%&'()* + !"!
public class YearConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
DateTime aDate;
aDate = (DateTime)value;
switch (aDate.Year.ToString())
{
case "1994":
return new SolidColorBrush(Colors.Purple);
case "1995":
return new SolidColorBrush(Colors.Green);
case "1996":
return new SolidColorBrush(Colors.Red);
default:
return new SolidColorBrush(Colors.Yellow);
}
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
,+# C)#LMNJ#:("'9#,//#1!"#$%&&%'()*#&()"#1%#1!"#9%+4*:8.;(8*"-1(8#0"71(%)<
<local:YearConverter x:Key="myYearConverter" />
-+# C)#1!"#LMNJ#/"7&,2,1(%)#$%2##%8$3*=G9#/"&"1"#1!"#$%&&%'()*<
DisplayMemberPath="OrderDate"
!")#,//#1!"#$%&&%'()*#/,1,#1"-.&,1"<
<ListBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding OrderDate}" Background="{Binding
Path=OrderDate, Converter={StaticResource myYearConverter}}" />
</DataTemplate>
</ListBox.ItemTemplate>
.+# E2"00#FG#1%#58(&/#,)/#28)#;%82#,..&(7,1(%)@#H%1"#1!,1#1!"#%2/"2#/,1"0#)%'#,2"#7%&%2#
7%/"/#5;#;",2@
;%..'3& /""!69■# &'#"()*+,(-$(-#(0#1!"#()1"2$,7"#;%8#-801#(-.&"-")1#()#;%82#7%):"21"20@#B%8#7,)#80"#
7801%-#7%):"21"20#1%#.2%:(/"#012()*#$%2-,11()*9#,..&;#7%)/(1(%),&#$%2-,11()*#()#/,1,#
1"-.&,1"09#2"182)#%56"7109#%2#&%7,&(S"#/,1,@#
www.it-ebooks.info
!"" $%&'()* + =%24()*#'(1!#>,1,#?()/()*
■# &'#"()*+,(-$(-#7%)1,()0#1'%#-"-5"20#;%8#-801#(-.&"-")1<#)*+,(-$#,)/#
)*+,(-$3'1H@# !"#)*+,(-$#-"1!%/#,77".10#,#:,&8"#,)/#7%):"210#(1#1%#1!"#2"182)#:,&8"@#
)*+,(-$3'1H#."2$%2-0#1!(0#%."2,1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/#,)#
()01,)7"#%$#1!(0#7%):"21"2#,0#,#01,1(7#2"0%827"#()#1!"#9%+4*:8.;(8*"-1(8#7%&&"71(%)#'(1!#
1!"#2<)*+,(-$(-#4";9#,)/#1!,1#;%8#,2"#5()/()*#1%#,#A"&/#7,&&"/#0'$(9#'!(7!#%$#1!"#$%&3
&%'()*#LMNJ#0)(.."10#0!%'0#1!"#7%22"71#',;#1%#5()/#,#5'6(##7%)12%�%#1!,1#(1#/(0.&,;0#
1!"#/,1"#'(1!#,#5,74*2%8)/#7%&%2#2"182)"/#5;#1!"#7%):"21"2W
#+#
<Label Content="{Binding Path=Date}" Background="{Binding Path=Date,
Converter={StaticResource myConverter}} />
2+#
<Label Content="{Binding Path=Date}" Background="{Binding Path=Date}" />
$+#
<Label Content="{Binding Path=Date}" Background="{Binding Path=Date}" >
<Label.Resources>
<local:DateBrushConverter x:Key="myConverter" />
</Label.Resources>
</Label>
3+#
<Label Content="{Binding Path=Date}" Background="{Binding Path=Date,
Converter=myConverter} />
!"# &@2A)*2
83.=%6.&7'&7>%.%&?/%.7-'3.&!3+&%@#$!3!7-'3.&'(&=>9&%!1>&!3.=%6&1>'-1%&-.&1'66%17&'6&-31'6A
6%17&!6%&$'1!7%+&-3&7>%&B83.=%6.C&.%17-'3&!7&7>%&%3+&'(&7>%&D''EF
www.it-ebooks.info
# J"00%)#K<#I%):"21()*#>,1,# $%&'()* + !"B
,+# B%8#!,:"#(-.&"-")1"/#,#-8&1(3:,&8"#7%):"21"2#),-"/#JI'B()*+,(-$(-#1!,1#1,4"0#,#
012()*#,)/#,)#()1"*"2#,0#,2*8-")10#,)/#%81.810#,#JI'B(#%56"71@#B%8#!,:"#,//"/#,)#
()01,)7"#%$#JI'B()*+,(-$(-#,0#,#2"0%827"#1%#1!"#9%+4*:8.;(8*"-1(8#7%&&"71(%)#'(1!#1!"#
2<)*+,(-$(-#4";@#M008-()*#1!,1#;%8#,2"#5()/()*#1%#.2%."21("0#7,&&"/#JI'B(C'2(#,)/#
JI'B(J%K(#X012()*#,)/#()1"*"2#/,1,#1;."09#2"0."71(:"&;Y9#'!(7!#%$#1!"#$%&&%'()*#LMNJ#
0,-.&"0#2")/"20#1!"#2"182)"/#0!,."#7%22"71&;#,0#1!"#7%)1")1#%$#,#&,5"%)12%&W
#+#
<Label Content={Binding Source=ShapeName Path=ShapeSize,
Converter={StaticResource myConverter}}">
2+#
<Label Content={Binding Path=ShapeName/ShapeSize,
Converter={StaticResource myConverter}}">
$+#
<Label>
<Label.Content>
<MultiBinding Converter="{StaticResource myConverter}">
<Binding Path=ShapeName />
<Binding Path=ShapeSize />
</MultiBinding>
</Label>
</Label>
3+#
<Label>
<Label.Content>
<MultiBinding Converter="{StaticResource myConverter}">
<Binding Path=ShapeSize />
<Binding Path=ShapeName />
</MultiBinding>
</Label>
</Label>
www.it-ebooks.info
!"+ $%&'()* + =%24()*#'(1!#>,1,#?()/()*
;<==60 !C D8-/983/01 E838 809 $60F1G4/01 $H801< @63/FI83/60
!(0#&"00%)#/",&0#'(1!#:,&(/,1()*#/,1,#,)/#7%)A*82()*#7!,)*"#)%1(A7,1(%)#$%2#7801%-#/,1,#
%56"710@#M&1!%8*!#0""-()*&;#8)2"&,1"/9#5%1!#%$#1!"0"#1%.(70#,2"#"00")1(,&#$%2#")082()*#1!,1#1!"#
/,1,#.2"0")1"/#5;#;%82#,..&(7,1(%)0#(0#,&',;0#,7782,1"9#7822")19#,)/#8)7%228.1"/@#C)#1!(0#&"03
0%)9#;%8#&",2)#!%'#1%#:,&(/,1"#;%82#/,1,#5;#80()*#:,&(/,1(%)#28&"09#1%#72",1"#7801%-#:,&(/,1(%)#
28&"09#,)/#1%#7%)A*82"#/,1,#7!,)*"#)%1(A7,1(%)#5;#(-.&"-")1()*# C*$%L<M-*B(-$<)I'+/(4#
,)/#()!"2(1()*#$2%-#@68(-,'6#()*##(1$%*+@#
8(7%6&7>-.&$%..'3G&9'/&=-$$&D%&!D$%&7'H&
■ M..&;#N=1(B$%*+&'#%4'$%*+;"#(@
■ I2",1"#7801%-#:,&(/,1(%)#28&"0@
■ Z,)/&"#,)/#2"0.%)/#1%#:,&(/,1(%)#"22%20@
■ C-.&"-")1# C*$%L<M-*B(-$<)I'+/(4@
■ [0"#@68(-,'6#()*##(1$%*+#1%#72",1"#5()/,5&"#7%&&"71(%)0@
I.7-"!7%+&$%..'3&7-"%H&JK&"-3/7%.
,!$-+!7-34&L!7! %#5"#80"$8&9#/,1,#-801#5"#:,&(/@# !"#,71#%$#:,&(/,1()*#/,1,#():%&:"0#")082()*#1!,1#/,1,#
7%)$%2-0#1%#1!"#01,)/,2/0#%$#(10#1;."@#F%2#"+,-.&"9#,#/,1,#A"&/#1!,1#2".2"0")10#,)#(1"-#.2(7"#
)":"2#0!%8&/#7%)1,()#,#)"*,1(:"#)8-5"2@#=EF#"),5&"0#;%8#1%#72",1"#:,&(/,1(%)#28&"0#,)/#,.3
.&;#1!"-#1%#;%82#3%+4%+/#%56"710#0%#1!,1#/,1,#,//"/#(0#,&',;0#:,&(/@
0-3+-34&,!$-+!7-'3&</$%.
=EF#"),5&"0#;%8#1%#0"1#:,&(/,1(%)#28&"0#1!,1#/"A)"#!%'#;%82#,..&(7,1(%)#:,&(/,1"0#(10#
/,1,@#\,7!#3%+4%+/#%56"71#"+.%0"0#,#&'#%4'$%*+;"#(8#7%&&"71(%)@#B%8#7,)#,//#)"'#28&"0#1%#
&'#%4'$%*+)*##(1$%*+9#,0#0!%')#()#5%&/#()#1!(0#"+,-.&"<
<TextBox>
<TextBox.Text>
<Binding Path="CandyBars">
<Binding.ValidationRules>
<local:CandyBarValidationRule />
<local:SweetTreatsValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
8(7%6&7>-.&$%..'3G&9'/&=-$$&D%&!D$%&7'H&
■ M..&;#N=1(B$%*+&'#%4'$%*+;"#(@
■ I2",1"#7801%-#:,&(/,1(%)#28&"0@
■ Z,)/&"#,)/#2"0.%)/#1%#:,&(/,1(%)#"22%20@
■ C-.&"-")1# C*$%L<M-*B(-$<)I'+/(4@
■ [0"#@68(-,'6#()*##(1$%*+#1%#72",1"#5()/,5&"#7%&&"71(%)0@
I.7-"!7%+&$%..'3&7-"%H&JK&"-3/7%.
www.it-ebooks.info
# J"00%)#]<#^,&(/,1()*#>,1,#,)/#I%)A*82()*#I!,)*"#H%1(A7,1(%)# $%&'()* + !"J
C)#1!(0#"+,-.&"9#1!"#)'+4<3'-&'#%4'$%*+;"#(#,)/#J:(($7-('$8&'#%4'$%*+;"#(#/"7&,2,1(%)0#
2".2"0")1#1'%#7801%-#:,&(/,1(%)#28&"0#1!,1#!,:"#5"")#/"A)"/#()#;%82#,..&(7,1(%)@#=!")#
,#)"'#:,&8"#(0#5%8)/9#",7!#%$#1!"#:,&(/,1(%)#28&"0#(0#":,&8,1"/#()#1!"#%2/"2#()#'!(7!#1!"#
28&"0#,2"#/"7&,2"/@#C)#1!(0#"+,-.&"9#)'+4<3'-&'#%4'$%*+;"#(#(0#":,&8,1"/#A2019#$%&&%'"/#5;#
#J:(($7-('$8&'#%4'$%*+;"#(@#C$#1!"2"#,2"#)%#:,&(/,1(%)#.2%5&"-09#1!"#,..&(7,1(%)#.2%7""/0#)%23
-,&&;@#C$#,#.2%5&"-#:(%&,1"0#,#:,&(/,1(%)#28&"9#!%'":"29#1!"#$%&&%'()*#1!()*0#!,..")<
■# !"#"&"-")1#'(1!#1!"#:,&(/,1(%)#"22%2#(0#%81&()"/#()#2"/@
■# !"#,11,7!"/#.2%."21;#&'#%4'$%*+.O'8N--*-#(0#0"1#1%#7-"(@
■# M#)"'#&'#%4'$%*+N--*-#%56"71#(0#72",1"/#,)/#,//"/#1%#1!"#,11,7!"/#&'#%4'$%*+.N--*-8#
7%&&"71(%)@
■# C$#1!"#3%+4%+/.C*$%L<@+&'#%4'$%*+N--*-#.2%."21;#(0#0"1#1%#7-"(9#1!"#&'#%4'$%*+.N--*-#,13
1,7!"/#":")1#(0#2,(0"/@
■# !"#/,1,35()/()*#0%827"#(0#)%1#8./,1"/#'(1!#1!"#():,&(/#:,&8"#,)/#()01",/#2"-,()0#
8)7!,)*"/@
%77-34& !"#$%&'()*+&,*%&'(-.+#
B%8#-(*!1#!,:"#)%1(7"/#'!")#'%24()*#'(1!#/,1,#1!,1#"+7".1(%)0#,2"#)%1#1!2%')#$2%-#/,1,#
5()/()*@# !(0#(0#.2(-,2(&;#1%#.2"0"2:"#,..&(7,1(%)#_%'#,)/#.2":")1#,..&(7,1(%)#72,0!"0#1!,1#2"3
08&1#$2%-#/,1,#"22%20@#Z%'":"29#;%8#7,)#2".%21#/,1,#"22%20#5;#0"11()*#N=1(B$%*+&'#%4'$%*+;"#(9#
'!(7!#7,80"0#,&&#"+7".1(%)0#1!2%')#()#1!"#/,1,35()/()*#.2%7"00#1%#5"#2".%21"/#,0#:,&(/,1(%)#
"22%20@#H%1"#1!,1#1!(0#01(&&#/%"0#)%1#!,&1#,..&(7,1(%)#"+"781(%)#,0#,)#8)!,)/&"/#"+7".1(%)#
'%8&/@#`,1!"29#(1#72",1"0#,#:,&(/,1(%)#"22%2#,0#/"072(5"/#.2":(%80&;@# !"#$%&&%'()*#"+,-.&"#
/"-%)012,1"0#!%'#1%#0"1#N=1(B$%*+&'#%4'$%*+;"#(<#
<Binding Path="CandyBars">
<Binding.ValidationRules>
<ExceptionValidationRule />
</Binding.ValidationRules>
</Binding>
M"#$%"%37-34&)/.7'"&,!$-+!7-'3&</$%.
B%8#7,)#72",1"#0."7(A7#:,&(/,1(%)#28&"0#5;#72",1()*#7&,00"0#1!,1#()!"2(1#1!"#,5012,71#
#&'#%4'$%*+;"#(#7&,009#'!(7!#!,0#%)"#:(218,&#-"1!%/#1!,1#-801#5"#%:"22(//")<#1!"#&'#%4'$(#
-"1!%/@# !"#&'#%4'$(#-"1!%/#2"7"(:"0#,)#%56"71#.,2,-"1"29#'!(7!#2".2"0")10#1!"#:,&8"#5"3
()*#":,&8,1"/9#,)/#2"182)0#,#&'#%4'$%*+;(8"#$#%56"719#'!(7!#7%)1,()0#,)# 8&'#%4#.2%."21;#,)/#
,)##N--*-)*+4%$%*+#.2%."21;@# !"# 8&'#%4#.2%."21;#2".2"0")10#,#?%%&",)#:,&8"#1!,1#()/(7,1"0#
'!"1!"2#1!"#:,&8"#(0#:,&(/9#,)/#1!"#N--*-)*+4%$%*+#.2%."21;#(0#1"+1#1!,1#7,)#5"#0"1#1%#.2%3
:(/"#,#/"072(.1(:"#"22%2#7%)/(1(%)@#C$#,#&'#%4'$%*+;(8"#$#%56"71#'(1!#,)# 8&'#%4#:,&8"#%$#7-"(#(0#
2"182)"/9#1!"#:,&8"#(0#7%)0(/"2"/#1%#5"#:,&(/#,)/#,..&(7,1(%)#"+"781(%)#.2%7""/0#)%2-,&&;@#C$#
,#&'#%4'$%*+;(8"#$#%56"71#'(1!#,)# 8&'#%4#2"08&1#%$#P'#8(#(0#2"182)"/9#,#&'#%4'$%*+N--*-#%56"71#(0#
72",1"/#,0#/"072(5"/#.2":(%80&;@
www.it-ebooks.info
!"K $%&'()* + =%24()*#'(1!#>,1,#?()/()*
!"#$%&&%'()*#"+,-.&"#/"-%)012,1"0#,#0(-.&"#(-.&"-")1,1(%)#%$#1!"#,5012,71#
#&'#%4'$%*+;"#(#7&,00<
!"#$%&'(&,-./!$&0!.-1&)'+%
Public Class NoNullStringsValidator
Inherits ValidationRule
Public Overrides Function Validate(ByVal value As Object, ByVal _
cultureInfo As System.Globalization.CultureInfo) As _
System.Windows.Controls.ValidationResult
Dim astring As String = value.ToString
If astring = "" Then
Return New ValidationResult(False, "String cannot be empty")
Else
Return New ValidationResult(True, Nothing)
End If
End Function
End Class
!"#$%&'(&)*&)'+%
public class NoNullStringsValidator : ValidationRule
{
public override ValidationResult Validate(object value,
System.Globalization.CultureInfo cultureinfo)
{
string aString = value.ToString();
if (aString == "")
return new ValidationResult(false, "String cannot be empty");
return new ValidationResult(true, null);
}
}
C)#1!(0#"+,-.&"9#1!"#012()*#7%)1,()"/#()#1!"#,'#"(#%56"71#(0#":,&8,1"/@#C$#(1#(0#,#S"2%3&")*1!#
012()*9#1!"#:,&(/,1(%)#$,(&0a#%1!"2'(0"9#1!"#:,&(/,1(%)#0877""/0@
N!3+$-34&,!$-+!7-'3&I66'6.
=!")#:,&(/,1(%)#"22%20#,2"#2,(0"/9#;%8#-801#/"7(/"#!%'#1%#2"0.%)/#1%#1!"-@#C)#0%-"#7,0"09#
1!"#:(08,N"0#.2%:(/"/#5;#1!"#:,&(/,1(%)#"22%2#,2"#")%8*!a#1!"#80"2#7,)#0""#1!,1#1!"#"&"-")1#
(0#0822%8)/"/#5;#,#2"/#%81&()"#,)/#7,)#/"1"71#,)/#A+#1!"#.2%5&"-@#C)#%1!"2#7,0"09#!%'":"29#
;%8#-(*!1#)""/#1%#.2%:(/"#$""/5,74#1%#1!"#80"2#2"*,2/()*#1!"#),182"#%$#1!"#:,&(/,1(%)#.2%53
&"-@
=!")#:,&(/,1(%)#(0#"),5&"/#$%2#,#5()/()*9#1!"#&'#%4'$%*+.N--*-#":")1#(0#,11,7!"/#1%#1!"#
5%8)/#"&"-")1@#&'#%4'$%*+.N--*-#()7&8/"0#,)#()01,)7"#%$#&'#%4'$%*+N--*-N,(+$Q-/89#'!(7!#7%)3
1,()0#1'%#(-.%21,)1#.2%."21("09#,0#/"072(5"/#()# ,5&"#b3b@
www.it-ebooks.info
# J"00%)#]<#^,&(/,1()*#>,1,#,)/#I%)A*82()*#I!,)*"#H%1(A7,1(%)# $%&'()* + !"L
(&M;) +N+ C-.%21,)1#E2%."21("0#%$#&'#%4'$%*+N--*-N,(+$Q-/8
'*O')*(P E)2$*Q'(QO@
Q1$%*) >"072(5"0#'!"1!"2#1!"#"22%2#()#T8"01(%)#(0#,#)"'#"22%2#%2#,)#
%&/#"22%2#1!,1#(0#5"()*#7&",2"/
N--*2 I%)1,()0#()$%2-,1(%)#,5%81#1!"#"22%2#1!,1#%77822"/9#1!"#
/"1,(&0#%$#'!(7!#,2"#/"072(5"/#()#$821!"2#/"1,(&#()# ,5&"#b3c
!"#N--*-#%56"71#%$#&'#%4'$%*+N--*-N,(+$Q-/8#7%)1,()0#,#!%01#%$#80"$8&#()$%2-,1(%)#2"3
*,2/()*#1!"#"22%2#1!,1#%77822"/@#C-.%21,)1#.2%."21("0#%$#1!"#N--*-#%56"71#,2"#/"072(5"/#()#
,5&"#b3c@
(&M;) +NJ C-.%21,)1#E2%."21("0#%$#1!"#N--*-#D56"71
'*O')*(P E)2$*Q'(QO@
3%+4%+/ +N--*2 I%)1,()0#,#2"$"2")7"#1%#1!"#3%+4%+/#%56"71#1!,1#7,80"/#1!"#
:,&(/,1(%)#"22%2
N--*-)*+$(+1 I%)1,()0#1!"#012()*#0"1#5;#1!"#&'#%4'$%*+;"#(#%56"71#1!,1#
2"182)"/#1!"#:,&(/,1(%)#"22%2
N=1(B$%*) I%)1,()0#,#2"$"2")7"#1%#1!"#"+7".1(%)9#($#,);9#1!,1#7,80"/#
1!"#:,&(/,1(%)#"22%2
;"#( +N--*2 I%)1,()0#,#2"$"2")7"#1%#1!"#&'#%4'$%*+;"#(#"+7".1(%)#1!,1#
7,80"/#1!"#:,&(/,1(%)#"22%2
!"#&'#%4'$%*+.N--*-#":")1#(0#)%1#A2"/#8)&"00#1!"#C*$%L<@+&'#%4'$%*+N--*-#.2%."21;#%$#1!"#
3%+4%+/#%56"71#(0#0."7(A7,&&;#0"1#1%#7-"(FD,0#0!%')#()#5%&/#!"2"<
<Binding NotifyOnValidationError="True" Mode="TwoWay"
Source="{StaticResource StringCollection}" Path="name">
<Binding.ValidationRules>
<local:NoNullStringsValidator/>
</Binding.ValidationRules>
</Binding>
=!")#1!(0#.2%."21;#(0#0"1#1%#7-"(9#1!"#&'#%4'$%*+.N--*-#":")1#(0#2,(0"/#,);1(-"#,);#
#&'#%4'$%*+;"#(#()#1!"#&'#%4'$%*+;"#(8#7%&&"71(%)#%$#1!"#3%+4%+/#%56"71#/"1"710#,#:,&(/,1(%)#"23
2%2@# !"#&'#%4'$%*+.N--*-#":")1#(0#,#5855&()*#":")1@#C1#(0#2,(0"/#A201#()#1!"#"&"-")1#'!"2"#1!"#
:,&(/,1(%)#"22%2#%77820#,)/#1!")#()#",7!#!(*!"23&":"&#"&"-")1#()#1!"#:(08,""@# !809#;%8#7,)#
72",1"#,#&%7,&#"22%23!,)/&()*#-"1!%/#1!,1#0."7(A7,&&;#!,)/&"0#:,&(/,1(%)#"22%20#$2%-#,#0()*&"#
"&"-")19#,0#0!%')#()#5%&/#!"2"<
<TextBox Validation.Error="TextBox1_Error" Height="21" Width="100"
Name="TextBox1" >
www.it-ebooks.info
!B# $%&'()* + =%24()*#'(1!#>,1,#?()/()*
M&1"2),1(:"&;9#;%8#7,)#72",1"#,)#"22%23!,)/&()*#2%81()"#1!,1#(0#"+"781"/#!(*!"2#()#1!"#:(08,&#
12""#1%#72",1"#,#-%2"#*")"2,&(S"/#:,&(/,1(%)#"22%2#!,)/&"29#,0#0!%')#()#5%&/#!"2"<
<Grid Validation.Error="Grid_Error">
!"#&'#%4'$%*+.N--*-#":")1#(0#A2"/#5%1!#'!")#,#)"'#:,&(/,1(%)#"22%2#(0#/"1"71"/#,)/#'!")#
,)#%&/#:,&(/,1(%)#"22%2#(0#7&",2"/@# !809#(1#(0#(-.%21,)1#1%#7!"74#1!"#(.Q1$%*+#.2%."21;#1%#/"3
1"2-()"#'!"1!"2#1!"#"22%2#(0#5"()*#7&",2"/#%2#(0#,#)"'#"22%2@# !"#$%&&%'()*#"+,-.&"#/"-%)3
012,1"0#,#0,-.&"#:,&(/,1(%)#"22%2#!,)/&"2#1!,1#/(0.&,;0#1!"#"22%2#-"00,*"#1%#1!"#80"2#'!")#,#
)"'#"22%2#%77820#,)/#'2(1"0#()$%2-,1(%)#1%#7-'1(#'!")#,#:,&(/,1(%)#"22%2#(0#7&",2"/<
!"#$%&'(&,-./!$&0!.-1&)'+%
Private Sub Grid_Error(ByVal _
sender As System.Object, ByVal e As _
System.Windows.Controls.ValidationErrorEventArgs)
If e.Action = ValidationErrorEventAction.Added Then
MessageBox.Show(e.Error.ErrorContent.ToString)
Else
Trace.WriteLine("Validation error cleared")
End If
End Sub
!"#$%&'(&)*&)'+%
private void Grid_Error(object sender, ValidationErrorEventArgs e)
{
if (e.Action == ValidationErrorEventAction.Added)
MessageBox.Show(e.Error.ErrorContent.ToString());
else
System.Diagnostics.Trace.WriteLine("Validation error cleared");
}
#$%&'"()
L!7!&5!$-+!7-'3&-.&!3&-"#'67!37&(%!7/6%&7>!7&-.&1'3.-+%6!D$9&+-((%6%37&-3&OP:&7>!3&-7&-.&-3&
O-3+'=.&:'6".F&M7'"-.%.&7'&Q4/6%'"-3%37$9&'3&7>%&%@!"G&.'&D%&1%67!-3&9'/&4%7&$'7.&
'(!17-1%&=-7>&5!$-+!7-34&+!7!F&M3&#!67-1/$!6G&3'7%&7>!7&7>%&,!$-+!7-'3FI66'6&%5%37&-.&6!-.%+&
D'7>&=>%3&!3&%66'6&-.&+%7%17%+&!3+&=>%3&!3&%66'6&-.&1$%!6%+F&)'+%&7>!7&>!3+$%.&7>-.&%5%37&
.>'/$+&7%.7&7'&+%7%6"-3%&=>%7>%6&!3&%66'6&>!.&D%%3&!++%+&'6&1$%!6%+F
)'3Q4/6-34&L!7!&)>!34%&R'7-Q1!7-'3B%8#0,'#",2&("2#()#1!(0#7!,.1"2#!%'#/,1,#5()/()*#()#=EF#(0#:(218,&&;#8)&(-(1"/@#H",2&;#,);#
%56"71#7,)#,71#,0#,#/,1,#0%827"9#,);#7%&&"71(%)#7,)#5"#5%8)/#,0#,#&(019#,)/#)",2&;#,);#.2%."21;#
7,)#5"#5%8)/@#Z%'":"29#1!"2"#,2"#0%-"#&(-(10@#B%82#%')#7801%-#/,1,#%56"710#7,)#5"#5%8)/#
()#1!"#0,-"#-,))"2#,0#,);#%1!"2#%56"719#581#($#7!,)*"0#%7782#1%#.2%."21("0#%$#;%82#/,1,#%53
6"7109#%2#($#-%2"#-"-5"20#,2"#,//"/#1%#;%82#/,1,#7%&&"71(%)09#1!"0"#7!,)*"0#,2"#)%1#/"1"71"/#
5;#=EF#/,1,#5()/()*#8)&"00#;%8#(-.&"-")1#/,1,#7!,)*"#)%1(A7,1(%)@
www.it-ebooks.info
# J"00%)#]<#^,&(/,1()*#>,1,#,)/#I%)A*82()*#I!,)*"#H%1(A7,1(%)# $%&'()* + !B:
F%218),1"&;9#/,1,#7!,)*"#)%1(A7,1(%)#(0#$,(2&;#",0;#1%#(-.&"-")1#()#7801%-#7&,00"0@#F%2#
7801%-#/,1,#%56"7109#;%8#7,)#(-.&"-")1#1!"# C*$%L<M-*B(-$<)I'+/(4#()1"2$,7"9#'!(7!#.2%3
:(/"0#)%1(A7,1(%)#$%2#7!,)*"/#.2%."21("0#()#;%82#/,1,#%56"710@#F%2#7801%-#7%&&"71(%)09#;%8#7,)#
/"2(:"#$2%-#@68(-,'6#()*##(1$%*+9#'!(7!#!,0#7!,)*"#)%1(A7,1(%)#58(&1#()@
M"#$%"%37-34&/0'%&1234'$#4%256*(7#,
!"# C*$%L<M-*B(-$<)I'+/(4#()1"2$,7"#!,0#%)"#-"-5"2<#1!"#M-*B(-$<)I'+/(4#":")1@# !(0#
":")1#7%)1,()0#,)#()01,)7"#%$#M-*B(-$<)I'+/(4N,(+$Q-/89#'!(7!#()/(7,1"0#1!"#.2%."21;#1!,1#
(0#7!,)*()*@#=!")#;%8#(-.&"-")1# C*$%L<M-*B(-$<)I'+/(49#2,(0"#1!"#M-*B(-$<)I'+/(4#":")1#
$2%-#":"2;#.2%."21;#$%2#'!(7!#;%8#',)1#1%#.2%:(/"#/,1,#7!,)*"#)%1(A7,1(%)@#D)#,#.2,71(3
7,&#&":"&9#1!(0#(0#"00")1(,&&;#":"2;#.85&(7#.2%."21;#1!,1#-(*!1#7!,)*"@# !"#%)&;#.2%."21("0#
$%2#'!(7!#;%8#-(*!1#)%1#2,(0"#1!(0#":")1#,2"#.2%."21("0#1!,1#)":"2#7!,)*"9#087!#,0#8)(T8"#
(/")1(A"20@# !"#$%&&%'()*#"+,-.&"#0!%'0#,#0(-.&"#7&,00#'(1!#%)"#.2%."21;#1!,1#(-.&"-")10#
# C*$%L<M-*B(-$<)I'+/(4<#
!"#$%&'(&,-./!$&0!.-1&)'+%
Public Class LastName
Implements System.ComponentModel.INotifyPropertyChanged
Public Event PropertyChanged(ByVal sender As Object, ByVal e As _
System.ComponentModel.PropertyChangedEventArgs) Implements _
System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Dim mLastName As String
Public Property Name()
Get
Return mLastName
End Get
Set (ByVal value)
mLastName = value
RaiseEvent PropertyChanged(Me, _
New System.ComponentModel.PropertyChangedEventArgs("LastName"))
End Set
End Property
End Class
!"#$%&'(&)*&)'+%
public class LastName : System.ComponentModel.INotifyPropertyChanged
{
public event System.ComponentModel.PropertyChangedEventHandler
PropertyChanged;
string mLastName;
public string Name
{
get
{
return mLastName;
}
set
{
mLastName = value;
PropertyChanged(this,
www.it-ebooks.info
!B? $%&'()* + =%24()*#'(1!#>,1,#?()/()*
new System.ComponentModel.PropertyChangedEventArgs("LastName"));
}
}
}
2.-34&89:#4;*9+#5'++#"%&'(
Q801#,0#.2%."21("0#-801#.2%:(/"#7!,)*"#)%1(A7,1(%)#()#%2/"2#$%2#1!,1#7!,)*"#1%#5"#/"1"71"/#
5;#=EF#/,1,#5()/()*9#7%&&"71(%)0#-801#.2%:(/"#)%1(A7,1(%)#'!")":"2#,#-"-5"2#(0#,//"/#%2#
2"-%:"/@#Q801#$%2#1!(0#.82.%0"9#@H\ #F2,-"'%24#]@G#.2%:(/"0#1!"#@68(-,'6#()*##(1$%*+#7&,00@
@68(-,'6#()*##(1$%*+#(0#,#*")"2(7#7%&&"71(%)#'(1!#58(&13()#7%&&"71(%)#7!,)*"#)%1(A7,1(%)@#
!809#'!")#(1"-0#,2"#,//"/#1%#%2#2"-%:"/#$2%-#@68(-,'6#()*##(1$%*+9#1!"#7!,)*"0#,2"#/"3
1"71"/#,81%-,1(7,&&;#5;#=EF#/,1,#5()/()*@#M0#'(1!#%1!"2#*")"2(7#7&,00"09#;%8#-801#0."7($;#1!"#
1;."#'(1!#'!(7!#1!"#7%&&"71(%)#'%240@#B%8#7,)#72",1"#,#)"'#()01,)7"#%$#@68(-,'6#()*##(1$%*+9#
,0#0!%')#!"2"<
!"#$%&'(&,-./!$&0!.-1&)'+%
Dim LastNames As New _
System.Collections.ObjectModel.ObservableCollection(Of LastName)
!"#$%&'(&)*&)'+%
System.Collections.ObjectModel.ObservableCollection<LastName> LastNames =
new System.Collections.ObjectModel.ObservableCollection<LastName>();
C)#-%01#7,0"09#!%'":"29#1!(0#(0#()08$A7(")1#$%2#;%82#.82.%0"0@#B%8#&(4"&;#',)1#1%#.2%3
:(/"#()(1(,&(S,1(%)#7%/"#$%2#;%82#7%&&"71(%)#%2#,//#%1!"2#7%/"#1%#$,7(&(1,1"#;%82#/,1,#%56"71@#
#@68(-,'6#()*##(1$%*+#(-.&"-")10# C*$%L<)*##(1$%*+)I'+/(4FD1!"#7%&&"71(%)35,0"/#:"20(%)#%$#
C*$%L<M-*B(-$<)I'+/(4@#M&1!%8*!#(1#(0#.%00(5&"#1%#72",1"#;%82#%')#%50"2:,5&"#7%&&"71(%)#
7&,00#5;#(-.&"-")1()*# C*$%L<)*##(1$%*+)I'+/(49#()!"2(1()*#$2%-#@68(-,'6#()*##(1$%*+#1%#
58(&/#;%82#%')#7&,00#(0#,&-%01#,&',;0#1!"#5"01#7!%(7"@#C)#1!(0#7,0"9#;%8#0!%8&/#()!"2(1#$2%-#1!"#
,..2%.2(,1"&;#1;."/#@68(-,'6#()*##(1$%*+#,)/#,//#7%/"#,0#;%82#580()"00#)""/0#2"T8(2"@#M)#
"+,-.&"#(0#0!%')#!"2"<
!"#$%&'(&,-./!$&0!.-1&)'+%
Public Class LastNames
Inherits System.Collections.ObjectModel.ObservableCollection(Of _
LastName)
Public Sub New()
' Initialization code omitted
End Sub
End Class
!"#$%&'(&)*&)'+%
public class LastNames :
System.Collections.ObjectModel.ObservableCollection<LastName>
{
public LastNames()
{
// Initialization code omitted
www.it-ebooks.info
# J"00%)#]<#^,&(/,1()*#>,1,#,)/#I%)A*82()*#I!,)*"#H%1(A7,1(%)# $%&'()* + !B!
}
}
!"#$%&$' $60F1G4/01 $H801< @63/FI83/60 809 E838 D8-/983/60
C)#1!(0#.2,71(7"9#;%8#7%)A*82"#7!,)*"#)%1(A7,1(%)#,)/#:,&(/,1()*#/,1,@#B%8#58(&/#,#0(-.&"#
/,1,#%56"719#72",1"#,#0(-.&"#7%&&"71(%)#%$#%56"710#%$#1!,1#1;."9#72",1"#,#0(-.&"#80"2#()1"2$,7"#
$%2#:("'()*#,)/#,//()*#/,1,#%56"7109#,)/#(-.&"-")1#,#0(-.&"#:,&(/,1(%)#07!"-"#$%2#;%82#80"2#
()1"2$,7"@
'('"$&)' * )6%!7-34& -"#$%&L!7!&SDT%17.
*+# C)#^(08,&#R18/(%9#72",1"#,#)"'#=EF#,..&(7,1(%)@
,+# C)#7%/"#:("'9#,//#1!"#$%&&%'()*#7&,009#'!(7!#(-.&"-")10# C*$%L<M-*B(-$<)I'+/(4<#
!"#$%&'(&,-./!$&0!.-1&)'+%
Public Class Name
Implements System.ComponentModel.INotifyPropertyChanged
Public Event PropertyChanged(ByVal sender As Object, ByVal e As _
System.ComponentModel.PropertyChangedEventArgs) Implements _
System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Public Sub New(ByVal fName As String, ByVal lName As String)
mFirstName = fName
mLastName = lName
End Sub
Private mFirstName As String
Private mLastName As String
Public Property FirstName()
Get
Return mFirstName
End Get
Set (ByVal value)
mFirstName = value
RaiseEvent PropertyChanged(Me, _
New System.ComponentModel.PropertyChangedEventArgs("FirstName"))
End Set
End Property
Public Property LastName()
Get
Return mLastName
End Get
Set (ByVal value)
mLastName = value
RaiseEvent PropertyChanged(Me, _
New System.ComponentModel.PropertyChangedEventArgs("LastName"))
End Set
End Property
End Class
www.it-ebooks.info
!B" $%&'()* + =%24()*#'(1!#>,1,#?()/()*
!"#$%&'(&)*&)'+%
public class Name : System.ComponentModel.INotifyPropertyChanged
{
public event System.ComponentModel.PropertyChangedEventHandler
PropertyChanged;
public Name(string fName, string lName)
{
mFirstName=fName;
mLastName = lName;
}
string mFirstName;
string mLastName;
public string FirstName
{
get
{
return mFirstName;
}
set
{
mFirstName = value;
PropertyChanged(this,
new System.ComponentModel.PropertyChangedEventArgs("FirstName"));
}
}
public string LastName
{
get
{
return mLastName;
}
set
{
mLastName = value;
PropertyChanged(this,
new System.ComponentModel.PropertyChangedEventArgs("LastName"));
}
}
}
-+# ?")",1!#1!(0#7&,009#,//#1!"#$%&&%'()*#7&,00#1%#72",1"#,#7%&&"71(%)#%$#C'2(#%56"710#1!,1#
()!"2(10#@68(-,'6#()*##(1$%*+<#
!"#$%&'(&,-./!$&0!.-1&)'+%
Public Class Names
Inherits System.Collections.ObjectModel.ObservableCollection(Of Name)
Public Sub New()
Dim aName As New Name("FirstName " & (Me.Count+1).ToString(), _
"LastName " & (Me.Count+1).ToString())
Me.Add(aName)
End Sub
End Class
www.it-ebooks.info
# J"00%)#]<#^,&(/,1()*#>,1,#,)/#I%)A*82()*#I!,)*"#H%1(A7,1(%)# $%&'()* + !BB
!"#$%&'(&)*&)'+%
public class Names :
System.Collections.ObjectModel.ObservableCollection<Name>
{
public Names()
{
Name aName = new Name("FirstName " + (this.Count+1).ToString(),
"LastName " + (this.Count+1).ToString());
this.Add(aName);
}
}
.+# M//#,#&()"#0(-(&,2#1%#1!"#&()"#0!%')#!"2"#1%#(-.%21#1!"#&%7,&#),-"0.,7"#()1%#;%82#
LMNJ<
xmlns:local="clr-namespace:Lesson_3"
/+# M//#1!"#$%&&%'()*#9%+4*:8.;(8*"-1(8#0"71(%)#1%#;%82#LMNJ#1%#72",1"#,)#()01,)7"#%$#
1!"#C'2(8#7%&&"71(%)<
<Window.Resources>
<local:Names x:Key="myNames"></local:Names>
</Window.Resources>
0+# `".&,7"#1!"#A-%4#/"7&,2,1(%)#'(1!#1!"#$%&&%'()*<
<Grid>
<TextBox Height="21" Margin="12,62,0,0" Name="TextBox1"
VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" >
<TextBox.Text>
<Binding Source="{StaticResource myNames}" Path="FirstName"
NotifyOnValidationError="True">
<Binding.ValidationRules>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<TextBox Height="21" HorizontalAlignment="Right" Margin="0,62,12,0"
Name="TextBox2" VerticalAlignment="Top" Width="120" >
<TextBox.Text>
<Binding Source="{StaticResource myNames}" Path="LastName"
NotifyOnValidationError="True">
<Binding.ValidationRules>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Button HorizontalAlignment="Left" Margin="35,122,0,116"
Name="Button1" Width="75">Back</Button>
<Button HorizontalAlignment="Right" Margin="0,122,34,117"
Name="Button2" Width="75">Forward</Button>
www.it-ebooks.info
!B+ $%&'()* + =%24()*#'(1!#>,1,#?()/()*
<Button Height="22" Margin="101,0,101,56" Name="Button3"
VerticalAlignment="Bottom">Add</Button>
</Grid>
1+# C)#7%/"#:("'9#,//#1!"#$%&&%'()*#7%/"#1%#72",1"#1'%#7&,003&":"&#:,2(,5&"0#,)/#1%#,//#X%2#
2".&,7"Y#1!"#7%)012871%2<
!"#$%&'(&,-./!$&0!.-1&)'+%
Dim aView As System.ComponentModel.ICollectionView
Dim myNames As Names
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
myNames = CType(Me.Resources("myNames"), Names)
aView = CollectionViewSource.GetDefaultView(myNames)
End Sub
!"#$%&'(&)*&)'+%
Names myNames;
System.ComponentModel.ICollectionView aView;
public MainWindow1()
{
InitializeComponent();
myNames=(Names)(this.Resources["myNames"]);
aView = CollectionViewSource.GetDefaultView(myNames);
}
4+# C)#1!"#/"0(*)"29#/%85&"37&(74#3"$$*+R#1%#%.")#1!"#/"$,8&1#)#%1H#":")1#!,)/&"2@#M//#1!"#
$%&&%'()*#7%/"<
!"#$%&'(&,-./!$&0!.-1&)'+%
If Not aView.CurrentPosition = 0 Then
aView.MoveCurrentToPrevious()
End If
!"#$%&'(&)*&)'+%
if (!(aView.CurrentPosition == 0))
aView.MoveCurrentToPrevious();
5+# C)#1!"#/"0(*)"29#/%85&"37&(74#3"$$*+G#1%#%.")#1!"#/"$,8&1#)#%1H#":")1#!,)/&"2@#M//#1!"#
$%&&%'()*#7%/"<
!"#$%&'(&,-./!$&0!.-1&)'+%
If Not aView.CurrentPosition = myNames.Count - 1 Then
aView.MoveCurrentToNext()
End If
!"#$%&'(&)*&)'+%
if (!(aView.CurrentPosition == myNames.Count - 1))
aView.MoveCurrentToNext();
www.it-ebooks.info
# J"00%)#]<#^,&(/,1()*#>,1,#,)/#I%)A*82()*#I!,)*"#H%1(A7,1(%)# $%&'()* + !BJ
*6+# C)#1!"#/"0(*)"29#/%85&"37&(74#3"$$*+E#1%#%.")#1!"#/"$,8&1#)#%1H#":")1#!,)/&"2@#M//#1!"#
$%&&%'()*#7%/"<
!"#$%&'(&,-./!$&0!.-1&)'+%
Dim aName As New Name("", "")
myNames.Add(aName)
aView.MoveCurrentToNext()
!"#$%&'(&)*&)'+%
Name aName = new Name("", "");
myNames.Add(aName);
aView.MoveCurrentToNext();
**+# E2"00#FG#1%#58(&/#,)/#28)#;%82#,..&(7,1(%)@#I&(74#M//#1%#,//#,#)"'#2"7%2/#1%#;%82#
7%&&"71(%)@#H,:(*,1"#5,74#1%#1!"#A201#2"7%2/#,)/#7!,)*"#1!"#")12("0#()#1!"#1"+1#5%+"0@#
H,:(*,1"#$%2',2/#,)/#1!")#5,74#,*,()@#H%1"#1!,1#7!,)*"0#,2"#."20(01"/#1%#5%1!#1!"#
.2%."21;#:,&8"0#,)/#1!"#7%&&"71(%)@
'('"$&)' , M"#$%"%37-34& -"#$%&,!$-+!7-'3
*+# C)#7%/"#:("'9#,//#1!"#$%&&%'()*#7&,00#1%#."2$%2-#:,&(/,1(%)<
!"#$%&'(&,-./!$&0!.-1&)'+%
Public Class StringValidator
Inherits ValidationRule
Public Overrides Function Validate(ByVal value As Object, ByVal _
cultureInfo As System.Globalization.CultureInfo) As _
System.Windows.Controls.ValidationResult
Dim astring As String = value.ToString
If astring = "" Then
Return New ValidationResult(False, "String cannot be empty")
Else
Return New ValidationResult(True, Nothing)
End If
End Function
End Class
!"#$%&'(&)*&)'+%
public class StringValidator : ValidationRule
{
public override ValidationResult Validate(object value,
System.Globalization.CultureInfo cultureinfo)
{
string aString = value.ToString();
if (aString == "")
return new ValidationResult(false, "String cannot be empty");
return new ValidationResult(true, null);
}
}
www.it-ebooks.info
!BK $%&'()* + =%24()*#'(1!#>,1,#?()/()*
,+# C)#LMNJ#:("'9#,//#1!"#$%&&%'()*#&()"#1%#5%1!#%$#1!"#S3%+4%+/.&'#%4'$%*+;"#(8T#1,*0#1%#
0"1#J$-%+/&'#%4'$*-#,0#1!"#:,&(/,1(%)#28&"#$%2#1!"0"#5()/()*0<
<local:StringValidator />
-+# E2"00#Fb#1%#58(&/#;%82#,..&(7,1(%)@
.+# N%/($;#1!"#A-%4#/"7&,2,1(%)9#,0#0!%')#!"2"#()#5%&/9#1%#72",1"#,)#"22%2#!,)/&"2#$%2#1!"#
*2(/@
<Grid Validation.Error="Grid_Error">
/+# C)#7%/"#:("'9#,//#1!"#$%&&%'()*#7%/"#1%#1!"#A-%4.N--*-#":")1#!,)/&"2<
!"#$%&'(&,-./!$&0!.-1&)'+%
If e.Action = ValidationErrorEventAction.Added Then
MessageBox.Show(e.Error.ErrorContent.ToString)
End If
!"#$%&'(&)*&)'+%
if (e.Action == ValidationErrorEventAction.Added)
MessageBox.Show(e.Error.ErrorContent.ToString());
0+# E2"00#FG#1%#58(&/#,)/#28)#;%82#,..&(7,1(%)@#>"&"1"#,&"+1#()#1!"#A201#1"+1#5%+#,)/#1!")#
.2"00# ,5#1%#-%:"#,',;#$2%-#1!,1#5%+@#H%1"#1!,1#,#-"00,*"#5%+#()$%2-()*#;%8#%$#,#
:,&(/,1(%)#"22%2#,..",20#,)/#1!,1#1!"#1"+1#5%+#(0#%81&()"/#()#2"/@
;%..'3& /""!69■# >,1,#5()/()*#/%"0#)%1#082$,7"#"+7".1(%)0a#1!";#,&&#,2"#!,)/&"/#()1"2),&&;@#B%8#7,)#80"#
:,&(/,1(%)#28&"0#1%#:,&(/,1"#/,1,#()#;%82#,..&(7,1(%)@#^,&(/,1(%)#28&"0#,2"#.&,7"/#()#1!"#
&'#%4'$%*+;"#(8#7%&&"71(%)#%$#1!"#5()/()*#,)/#,2"#":,&8,1"/#()#1!"#%2/"2#()#'!(7!#1!";#
,2"#0"1@
■# =!")#,#:,&(/,1(%)#"22%2#%778209#1!"#"&"-")1#7,80()*#1!"#:,&(/,1(%)#28&"#(0#%813
&()"/#()#2"/a#1!"#&'#%4'$%*+.O'8N--*-#.2%."21;#(0#0"1#1%#7-"(a#,##&'#%4'$%*+N--*-#
%56"71#(0#72",1"/#,)/#,//"/#1%#1!"#&'#%4'$%*+.N--*-8#7%&&"71(%)a#,)/9#($#1!"#
#3%+4%+/.DC*$%L<@+&'#%4'$%*+N--*-#.2%."21;#(0#0"1#1%#7-"(9#1!"#&'#%4'$%*+.N--*-#":")1#(0#
2,(0"/@
■# !"#N=1(B$%*+&'#%4'$%*+;"#(#7,80"0#,#:,&(/,1(%)#"22%2#1%#%7782#'!")":"2#,)#8)!,)/&"/#
"+7".1(%)#%77820#()#;%82#/,1,35()/()*#7%/"9#581#(1#/%"0#)%1#082$,7"#1!"#"+7".1(%)@
■# B%8#7,)#72",1"#7801%-#:,&(/,1(%)#28&"0#5;#(-.&"-")1()*#1!"# &'#%4'$%*+;"#(#7&,00@
■# %#7%)A*82"#/,1,#7!,)*"#)%1(A7,1(%)9#;%8#0!%8&/#(-.&"-")1#1!"#
# C*$%L<M-*B(-$<)I'+/(4#()1"2$,7"#,)/#2,(0"#1!"#M-*B(-$<)I'+/(4#":")1#()#,&&#.2%."23
1("0#1!,1#-(*!1#5"#5%8)/@#F%2#)%1(A7,1(%)3"),5&"/#7%&&"71(%)09#;%8#0!%8&/#()!"2(1#$2%-#
#@68(-,'6#()*##(1$%*+@
www.it-ebooks.info
J"00%)#d<#?()/()*#1%#>,1,#R%827"0 $%&'()* J !+L
;<==60 :C M/09/01 36 E838 26G4I<=
C)#1!"#.2":(%80#7!,.1"29#;%8#0,'#!%'#1%#5()/#,#.2%."21;#1%#,)%1!"2#.2%."21;#%$#,)#"&"-")1#
%2#%56"71@#C)#1!(0#&"00%)9#;%8#&",2)#!%'#1%#5()/#.2%."21("0#1%#,#:,2("1;#%$#/,1,#0%827"0<#!%'#
1%#5()/#1%#,)/#),:(*,1"#,#&(019#!%'#1%#5()/#1%#M>D@H\ #/,1,#0%827"09#,)/#!%'#1%#72",1"#,#
-,01"23/"1,(()/()*#'(1!#!("2,27!(7,&#/,1,@# !")#;%8#&",2)#!%'#1%#80"#1!"#U!50'$'J*"-1(
!"# !"#$%&'%'()*+$# $%!&&'& () *+"# () ,-. !"# &/'$+!%+0'# #!(!1
!"#$%"&'(%)#((*+,%-*.%/'))%0#%10)#%"*2%
■ 2+"# !" +('3 $)"(4)% () ! %+&( )5 #!(!1
■ 2+"# ! /4)/'4(6 () ! %+&(1
■ 7!8+9!(' ! %+&(1
■ 2+"# () !" :;<17=> )*?'$(1
■ 2+"# () @+'4!4$@+$!% #!(!1
■ A&' (@' !"#$%&'%',+)-./#+ $%!&& () *+"# () )*?'$(& !"# 3'(@)#&1
■ A&' (@' 012&'%',+)-./#+ $%!&& () *+"# () ,-.1
3("'41"#5%)#((*+%"'4#2%67%4'+."#(
8'+5'+9%"*%1%:'("B4'CD'"(%6E 6)D F!"( () *+"# !" '%'3'"( () ! %+&( )5 )*?'$(& 4!(@'4 (@!" ?D&( () ! &+"9%' )*?'$(1
>@'4' !4' (F) &$'"!4+)& +" (@+& $!&'G *+"#+"9 ! &+"9%' '%'3'"( () ! %+&( !"# '"!*%+"9 "!8+9!(+)"
)5 (@!( %+&(E !"# *+"#+"9 ! $)%%'$(+)" H&D$@ !& (@' +('3& +" 3.4%5)6I () ! %+&( &) (@!( (@' %+&(J& '%'K
3'"(& !4' !%% #+&/%!6'# !( )"' (+3'1
8'+5'+9%1+%;"#4%<*+"$*)%"*%1%:'("
<"' $)33)" &$'"!4+) +" *+"#+"9 () ! %+&( )5 #!(! )4 ! $)%%'$(+)" +& () #+&/%!6 !%% +('3& +" (@!(
$)%%'$(+)" +" ! %+&(K*!&'# '%'3'"( &D$@ !& 3.4%5)61 L('3 $)"(4)%& @!8' *D+%(K+" /4)/'4(+'& (@!(
'"!*%' #!(! *+"#+"91 >@'&' !4' #'&$4+*'# +" >!*%' MKN1
!"#$%&'(%;!(!KO'%!('# P4)/'4(+'& )5 L('3 Q)"(4)%&
)*+)$* , -$./*0) 0+1
&.472'89#1!#+,'%: L"#+$!('& (@' /4)/'4(6 )5 (@' *)D"# $)%%'$(+)" (@!( F+%%
*' D&'# () $4'!(' (@' #+&/%!6 ('R( 5)4 '!$@ +('31
;4(8<$:+)<.=#/>.%:?*++#<%;%#1 ;'('43+"'& F@'(@'4 (@' &'%'$('# +('3 +& S'/( &6"$@4)K
"+0'# F+(@ (@' ?*++#<%;%#1 /4)/'4(6 +" (@' ;%#14 $)%%'$K
(+)"1 7)( &(4+$(%6 ! #!(!K4'%!('# /4)/'4(6E *D( D&'5D% 5)4
*D+%#+"9 3!&('4K#'(!+% 8+'F&1
!"#$%"&'(%)#((*+,%-*.%/'))%0#%10)#%"*2%
■ 2+"# !" +('3 $)"(4)% () ! %+&( )5 #!(!1
■ 2+"# ! /4)/'4(6 () ! %+&(1
■ 7!8+9!(' ! %+&(1
■ 2+"# () !" :;<17=> )*?'$(1
■ 2+"# () @+'4!4$@+$!% #!(!1
■ A&' (@' !"#$%&'%',+)-./#+ $%!&& () *+"# () )*?'$(& !"# 3'(@)#&1 !"#$%&'%',+)-./#+
■ A&' (@' 012&'%',+)-./#+ $%!&& () *+"# () ,-.1012&'%',+)-./#+
3("'41"#5%)#((*+%"'4#2%67%4'+."#(
www.it-ebooks.info
%2&3 /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
;%#14()*+$# O'/4'&'"(& (@' $)%%'$(+)" (@!( $)"(!+"& (@' +('3& (@!(
3!S' D/ (@' &)D4$' )5 (@' %+&(1 U)D &'( (@+& /4)/'4(6
() ! 5.</.<@ )*?'$( (@!( +& *)D"# () (@' !//4)/4+!('
$)%%'$(+)"1
;%#1A#172'%# >@' #!(! ('3/%!(' D&'# () $4'!(' (@' 8+&D!% !//'!4!"$'
)5 '!$@ +('31 ;!(! ('3/%!('& F+%% *' #+&$D&&'# +" .'&&)"
V )5 (@+& $@!/('4E W-!"+/D%!(+"9 !"# ;+&/%!6+"9 ;!(!1X
B)4 &+3/%' #+&/%!6+"9 )5 *)D"# 3'3*'4&E 6)D 3D&( &'( (@' ;%#14()*+$# /4)/'4(6 () (@'
$)%%'$(+)" () F@+$@ 6)D !4' *+"#+"9 !"# &'( (@' &.472'89#1!#+,'%: /4)/'4(6 () (@' $)%K
%'$(+)" 3'3*'4 (@!( +& () *' #+&/%!6'#1 -)4' $)3/%'R #+&/%!6& D&+"9 #!(! ('3/%!('& !4'
#+&$D&&'# +" .'&&)" V1 >@' 5)%%)F+"9 'R!3/%' #'3)"&(4!('& @)F () *+"# ! 3.4%5)6 $)%%'$(+)"
() ! &(!(+$ 4'&)D4$' "!3'# 183.4% !"# ! #+&/%!6 3'3*'4 $!%%'# B.+4%C'1#G
<ListBox Width="200" ItemsSource="{Binding Source={StaticResource myList}}"
DisplayMemberPath="FirstName" />
: 3)4' $)33)" &$'"!4+) F@'" F)4S+"9 F+(@ *)D"# %+&(&E @)F'8'4E +& () *+"# () !" )*?'$(
(@!( +& #'T"'# !"# T%%'# F+(@ #!(! +" $)#'1 L" (@+& $!&'E (@' *'&( F!6 () *+"# () (@' %+&( +& ()
&'( &.472'89#1!#+,'%: +" ,:-. !"# (@'" &'( (@' &'%'?)<%#6% /4)/'4(6 )5 (@' '%'3'"( )4 +(&
$)"(!+"'4 +" $)#'1 >@' 5)%%)F+"9 'R!3/%' #'3)"&(4!('& @)F () *+"# ! 3.4%5)6 $)"(4)% () !"
)*?'$( $!%%'# 18?*4%)1#+4 (@!( +& $4'!('# !( 4D" (+3'D >@' 3.4%5)6 $)"(4)% #+&/%!6& (@' '"(4+'&
54)3 (@' ?*4%)1#+C'1# /4)/'4(6G
=14>)#%*!%?'(.1)%81('@%<*5#
' Code to initialize and fill myCustomers has been omitted
grid1.DataContext = myCustomers;
=14>)#%*!%<A%<*5#
55%<*5#%"*%'+'"'1)'B#%1+5%!'))%4-<.("*4#$(%&1(%0##+%*4'""#5
9$'5CDE1"1<*+"#F"%G%4-<.("*4#$(H%
%
=14>)#%*!%I J:%<*5#
<!-- XAML -->
<Grid Name="grid1">
<ListBox ItemsSource="{Binding}" DisplayMemberPath="CustomerName"
Margin="92,109,66,53" Name="ListBox1" />
</Grid>
7)(' (@!( +" (@' ,:-. 5)4 (@+& 'R!3/%'E (@' ;%#14()*+$# /4)/'4(6 +& &'( () ! 5.</.<@
)*?'$( (@!( @!& ") /4)/'4(+'& +"+(+!%+0'#1 >@' 5.</.<@ )*?'$( *+"#& (@' ;%#14()*+$# /4)/'4(6
)5 3.4%5)6E *D( *'$!D&' (@' ()*+$# /4)/'4(6 )5 (@' 5.</.<@ )*?'$( +& ")( &'(E YPB &'!4$@'&
D/F!4# (@4)D9@ (@' 8+&D!% (4'' D"(+% +( T"#& ! &'%'?)<%#6% )*?'$( (@!( @!& *''" &'(1 2'$!D&'
&'%'?)<%#6% 5)4 @+./E @!& *''" &'( +" $)#' () 18?*4%)1#+4E (@+& (@'" *'$)3'& (@' &)D4$' 5)4
(@' *+"#+"91
www.it-ebooks.info
.'&&)" NG 2+"#+"9 () ;!(! Z)D4$'& /4!) $*%&% 2&(
8'+5'+9%1%='+9)#%K$*>#$"-%"*%1%:'("
U)D $!" !%&) *+"# ! &+"9%' /4)/'4(6 () ! %+&( )4 $)%%'$(+)"1 >@' /4)$'&& +& 3D$@ (@' &!3' !&
*+"#+"9 !" +('3 $)"(4)% () ! %+&( 'R$'/( (@!(E +"+(+!%%6E )"%6 (@' T4&( +('3 +" (@' %+&( +& #+&/%!6'#1
U)D $!" "!8+9!(' (@4)D9@ (@' %+&( () #+&/%!6 &D*&'CD'"( +('3& +" (@' %+&(1 7!8+9!(+)" )5 %+&(& +&
#+&$D&&'# +" (@' "'R( &'$(+)"1 >@' 5)%%)F+"9 'R!3/%' #'3)"&(4!('& $4'!(+"9 (@' #!(! &)D4$'
)*?'$( +" $)#' !"# &'((+"9 (@' #!(! $)"('R( 5)4 ! 94+# !"# (@'"E +" ,:-.E *+"#+"9 ! 3'!#2
)*?'$( () (@' B.+4%C'1# /4)/'4(6 )5 (@' +('3& $)"(!+"'# +" (@' #!(! &)D4$' )*?'$(G
=14>)#%*!%?'(.1)%81('@%<*5#
' Code to initialize and fill myCustomers omitted
grid1.DataContext = myCustomers;
=14>)#%*!%<A%<*5#
Code to initialize and fill myCustomers omitted
grid1.DataContext = myCustomers;
=14>)#%*!%I J:%<*5#
<!-- XAML -->
<Grid Name="grid1">
<Label Content="{Binding Path=FirstName}" Height="23"
Width="100"></Label>
</Grid>
L1M'91"'+9%1%<*))#@"'*+%*$%:'("
Y@'" +"#+8+#D!% /4)/'4(+'&E &D$@ !& (@' ?)<%#<% /4)/'4(6 )5 3'!#2E !4' *)D"# () ! $)%%'$K
(+)"E (@'6 !4' $!/!*%' )5 #+&/%!6+"9 )"%6 ! &+"9%' 3'3*'4 )5 (@!( $)%%'$(+)" !( ! (+3'1 >@+& +&
! $)33)" /!(('4" &''" +" #!(! !$$'&& !//%+$!(+)"&G : F+"#)F 3+9@( *' #'&+9"'# () #+&/%!6
)"' 4'$)4# !( ! (+3' !"# @!8' +"#+8+#D!% $)"(4)%& #+&/%!6 '!$@ #!(! $)%D3"1 2'$!D&' )"%6 )"'
4'$)4# +& #+&/%!6'# !( ! (+3'E +( *'$)3'& "'$'&&!46 () @!8' ! 3'$@!"+&3 (@!( '"!*%'& (@' D&'4
() "!8+9!(' (@4)D9@ (@' 4'$)4#&1
YPB @!& ! *D+%(K+" "!8+9!(+)" 3'$@!"+&3 5)4 #!(! !"# $)%%'$(+)"&1 Y@'" ! $)%%'$(+)"
+& *)D"# () ! YPB *+"#+"9E !" ;?)22#$%.)<F.#G +"('45!$' +& $4'!('# *'@+"# (@' &$'"'&1 >@'
;?)22#$%.)<F.#G +"('45!$' $)"(!+"& 3'3*'4& (@!( 3!"!9' #!(! $D44'"$6 !& F'%% !& 8+'F&E
94)D/+"9E !"# &)4(+"9E !%% )5 F@+$@ !4' #+&$D&&'# +" .'&&)" V )5 (@+& $@!/('41 >!*%' MKV #'K
&$4+*'& 3'3*'4& +"8)%8'# +" "!8+9!(+)"1
!"#$%&'6% ;?)22#$%.)<F.#G -'3*'4& L"8)%8'# +" 7!8+9!(+)"
7$7"$* -$./*0) 0+1
?*++#<%;%#1 >@+& /4)/'4(6 4'(D4"& (@' $D44'"( +('31
?*++#<%,)4.%.)< >@+& /4)/'4(6 4'(D4"& (@' "D3'4+$ /)&+(+)" )5 (@' $D44'"(
+('31
;4?*++#<%HI%#+3'4% >@+& /4)/'4(6 +"#+$!('& F@'(@'4 (@' $D44'"( +('3 +& !5('4 (@'
%!&( +('3 +" (@' $)%%'$(+)"1
www.it-ebooks.info
%2&6 /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
;4?*++#<%5#I)+#B.+4% >@+& /4)/'4(6 +"#+$!('& F@'(@'4 (@' $D44'"( +('3 +& *'5)4'
(@' T4&( +('3 +" (@' $)%%'$(+)"1
9)-#?*++#<%A) >@+& 3'(@)# &'(& (@' $D44'"( +('3 () (@' +"#+$!('# +('31
9)-#?*++#<%A)B.+4% >@+& 3'(@)# &'(& (@' $D44'"( +('3 () (@' T4&( +('3 +" (@'
$)%%'$(+)"1
9)-#?*++#<%A)3'4% >@+& 3'(@)# &'(& (@' $D44'"( +('3 () (@' %!&( +('3 +" (@'
$)%%'$(+)"1
9)-#?*++#<%A)C#6% >@+& 3'(@)# &'(& (@' $D44'"( +('3 () (@' "'R( +('3 +" (@'
$)%%'$(+)"1
9)-#?*++#<%A),)4.%.)< >@+& 3'(@)# &'(& (@' $D44'"( +('3 () (@' +('3 !( (@' #'&+9K
"!('# /)&+(+)"1
9)-#?*++#<%A),+#-.)*4 >@+& 3'(@)# &'(& (@' $D44'"( +('3 () (@' /4'8+)D& +('31
U)D $!" 9'( ! 4'5'4'"$' () ;?)22#$%.)<F.#G *6 $!%%+"9 (@'
?)22#$%.)<F.#G()*+$#DJK#%&#I'*2%F.#G 3'(@)#E !& &@)F" @'4'G
=14>)#%*!%?'(.1)%81('@%<*5#
' This example assumes a collection named myCollection
Dim myView As System.ComponentModel.ICollectionView
myView = CollectionViewSource.GetDefaultView (myCollection)
=14>)#%*!%<A%<*5#
// This example assumes a collection named myCollection
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView (myCollection);
Y@'" $!%%+"9 (@+& 3'(@)#E 6)D 3D&( &/'$+56 (@' $)%%'$(+)" )4 %+&( 5)4 F@+$@ () 4'(4+'8' (@'
8+'F HF@+$@ +& 18?)22#$%.)< +" (@' /4'8+)D& 'R!3/%'I1 ?)22#$%.)<F.#G()*+$#DK#%L&#I'*2%F.#G
4'(D4"& !" ;?)22#$%.)<F.#G )*?'$( (@!( +& !$(D!%%6 )"' )5 (@4'' $%!&&'&E #'/'"#+"9 )" (@' $%!&&
)5 (@' &)D4$' $)%%'$(+)"1
L5 (@' &)D4$' $)%%'$(+)" +3/%'3'"(& ;5.</.<@3.4%E (@' 8+'F 4'(D4"'# +& !
5.</.<@3.4%LJ?)22#$%.)<F.#G )*?'$(1 L5 (@' &)D4$' $)%%'$(+)" +3/%'3'"(& ;3.4% *D( ")(
;5.</.<@3.4%E (@' 8+'F 4'(D4"'# +& ! 3.4%?)22#$%.)<F.#G )*?'$(1 L5 (@' &)D4$' $)%%'$(+)" +3/%'K
3'"(& ;M<*1#+'!2# *D( ")( ;3.4% )4 ;5.</.<@3.4%E (@' 8+'F 4'(D4"'# +& ! ?)22#$%.)<F.#G )*?'$(1
B)4 "!8+9!(+)"!% /D4/)&'&E F)4S+"9 F+(@ (@' ;?)22#$%.)<F.#G &@)D%# *' &D5T$+'"(1 L5 6)D
"''# () !$$'&& 3'3*'4& )5 (@' )(@'4 $%!&&'&E 6)D 3D&( $!&( (@' ;?)22#$%.)<F.#G )*?'$( () (@'
$)44'$( $%!&&1
Y@'" !" +('3 $)"(4)% )4 $)"('"( $)"(4)% +& *)D"# () ! #!(! &)D4$'E (@' #'5!D%( $)%%'$(+)"
8+'F @!"#%'& $D44'"$6 !"# "!8+9!(+)" *6 #'5!D%(1 >@' $D44'"( +('3 +" (@' 8+'F +& 4'(D4"'# *6
(@' ?*++#<%;%#1 /4)/'4(61 >@+& +& (@' +('3 $D44'"(%6 #+&/%!6'# +" !%% $)"('"( $)"(4)%& *)D"#
www.it-ebooks.info
.'&&)" NG 2+"#+"9 () ;!(! Z)D4$'& /4!) $*%&% 2&2
() (@+& 8+'F1 7!8+9!(+)" *!$SF!4# !"# 5)4F!4# (@4)D9@ (@' %+&( +& !$$)3/%+&@'# D&+"9 (@'
9)-#?*++#<%A)C#6% !"# 9)-#?*++#<%A),+#-.)*4 3'(@)#&E !& &@)F" @'4'G
=14>)#%*!%?'(.1)%81('@%<*5#
Dim myView As System.ComponentModel.ICollectionView
myView = CollectionViewSource.GetDefaultView (myCollection)
' Sets the CurrentItem to the next item in the list
myView.MoveCurrentToNext()
' Sets the CurrentItem to the previous item in the list
myView.MoveCurrentToPrevious()
=14>)#%*!%<A%<*5#
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView (myCollection);
// Sets the CurrentItem to the next item in the list
myView.MoveCurrentToNext();
// Sets the CurrentItem to the previous item in the list
myView.MoveCurrentToPrevious();
2'$!D&' +('3 $)"(4)%& (6/+$!%%6 !4' *)D"# () !%% (@' +('3& +" ! %+&(E "!8+9!(+)" (@4)D9@ (@'
%+&( +& ")( D&D!%%6 '&&'"(+!%1 [)F'8'4E 6)D $!" D&' !" +('3 $)"(4)% () '"!*%' (@' D&'4 () "!8+K
9!(' 4'$)4#& *6 &'((+"9 ;4(8<$:+)<.=#/>.%:?*++#<%;%#1 () A+*#E !& &@)F" +" *)%# @'4'G
<ListBox ItemsSource="{Binding}" DisplayMemberPath="City"
Margin="92,109,66,53" Name="ListBox1"
IsSynchronizedWithCurrentItem="True" />
Y@'" (@' ;4(8<$:+)<.=#/>.%:?*++#<%;%#1 /4)/'4(6 +& &'( () A+*#E (@' (#2#$%#/;%#1 /4)/K
'4(6 )5 (@' +('3 $)"(4)% !%F!6& +& &6"$@4)"+0'# F+(@ (@' ?*++#<%;%#1 /4)/'4(6 )5 (@' 8+'F1
>@D&E +5 (@' D&'4 &'%'$(& !" +('3 +" !" +('3 $)"(4)%E (@' ?*++#<%;%#1 /4)/'4(6 )5 (@' 8+'F +& &'(
() (@!( +('31 >@+& $@!"9' (@'" +& 4'\'$('# +" !%% )(@'4 $)"(4)%& *)D"# () (@' &!3' #!(! &)D4$'1
>@+& $)"$'/( +& +%%D&(4!('# +" (@' %!* 5)4 (@+& %'&&)"1
8'+5'+9%"*% ENDL3O%N0P#@"(2+"#+"9 () :;<17=> )*?'$(& +& *!&+$!%%6 (@' &!3' !& *+"#+"9 () !"6 )(@'4 $)%%'$(+)" )4 %+&(1
2'$!D&' :;<17=> )*?'$(& D&D!%%6 !4' +"+(+!%+0'# +" $)#'E (@' 9'"'4!% /!(('4" +& () +"+(+!%+0' (@'
:;<17=> )*?'$(& +" $)#' !"# &'( (@' #!(! $)"('R( 5)4 (@' D&'4 +"('45!$'1 2+"#+"9& +" ,:-.
&@)D%# /)+"( () (@' !//4)/4+!(' :;<17=> )*?'$(1
=#""'+9% !"!#$%"&'"%"*%1+% ENDL3O% !"!(!)*&%N0P#@"
Y@'" &'((+"9 &'%'?)<%#6% () !" :;<17=> &'%'A'!2# )*?'$( (@!( $)"(!+"& (@' #!(! ()
F@+$@ 6)D F!"( () *+"#E &'( (@' ;%#14()*+$# /4)/'4(6 )5 !"6 +('3 $)"(4)%& 6)D !4' *+"#K
+"9 () (@!( (!*%' () !" '3/(6 5.</.<@ )*?'$( !"# &/'$+56 (@' $)%D3" () *' #+&/%!6'# +" (@'
&.472'89#1!#+,'%: /4)/'4(61 B)4 $)"('"( $)"(4)%& )4 )(@'4 &+"9%' /4)/'4(+'&E 6)D &@)D%#
&'( (@' !//4)/4+!(' /4)/'4(6 () ! 5.</.<@ )*?'$( (@!( &/'$+T'& (@' !//4)/4+!(' $)%D3" +" (@'
,'%: /4)/'4(61 >@' 5)%%)F+"9 'R!3/%' #'3)"&(4!('& (@' $)#' () +"+(+!%+0' !" :;<17=> #!(!
www.it-ebooks.info
%2&8 /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
&'( !"# &'( (@' &'%'?)<%#6%E !"# (@' ,:-. () *+"# ! 3.4%5)6 $)"(4)% !"# ! 3'!#2 $)"(4)% ()
(@!( #!(!&'(G
=14>)#%*!%?'(.1)%81('@%<*5#
Public Class Window1
Dim aset As NwindDataSet = New NwindDataSet()
Dim custAdap As _
NwindDataSetTableAdapters.CustomersTableAdapter = _
New NwindDataSetTableAdapters.CustomersTableAdapter()
Dim ordAdap As NwindDataSetTableAdapters.OrdersTableAdapter _
= New NwindDataSetTableAdapters.OrdersTableAdapter()
Public Sub New()
InitializeComponent()
custAdap.Fill(aset.Customers)
OrdAdap.Fill(aset.Orders)
Grid1.DataContext = aset.Customers
End Sub
=14>)#%*!%<A%<*5#
public partial class Window1 : Window
{
NwindDataSet aset = new NwindDataSet();
NwindDataSetTableAdapters.CustomersTableAdapter custAdap =
new NwindDataSetTableAdapters.CustomersTableAdapter();
NwindDataSetTableAdapters.OrdersTableAdapter ordAdap =
new NwindDataSetTableAdapters.OrdersTableAdapter();
public Window1()
{
InitializeComponent();
custAdap.Fill(aset.Customers);
ordAdap.Fill(aset.Orders);
Grid1.DataContext = aset.Customers;
}
}
=14>)#%*!%I J:%<*5#
<!-- XAML -->
<Grid Name="Grid1">
<ListBox ItemsSource="{Binding}" DisplayMemberPath="ContactName"
Name="listBox1" Width="100" Height="100" VerticalAlignment="Top" />
<Label Content="{Binding Path=ContactTitle}" Height="23" Width="100"
Name="label1" VerticalAlignment="Top"></Label>
</Grid>
=#""'+9% !"!#$%"&'"%"*%1+% ENDL3O% !"!+&"%N0P#@"
U)D $!" !%&) &'( &'%'?)<%#6% () !" :;<17=> &'%'(#% )*?'$( +"&('!# )5 () ! &'%'A'!2# )*?'$(1
2'$!D&' ! &'%'(#% )*?'$( +& ! $)%%'$(+)" )5 &'%'A'!2# )*?'$(&E 6)D 3D&( /4)8+#' (@' "!3' )5
(@' &'%'A'!2# )*?'$( !& /!4( )5 (@' ,'%: /4)/'4(61 =R!3/%'& !4' &@)F" @'4'G
=14>)#%*!%?'(.1)%81('@%<*5#
' The rest of the code is identical to the previous example
www.it-ebooks.info
.'&&)" NG 2+"#+"9 () ;!(! Z)D4$'& /4!) $*%&% 2&9
' and has been omitted.
Grid1.DataContext = aset
=14>)#%*!%<A%<*5#
// The rest of the code is identical to the previous example
// and has been omitted.
Grid1.DataContext = aset;
<!--XAML-->
<Grid Name="Grid1">
<ListBox ItemsSource="{Binding Path=Customers}"
DisplayMemberPath="ContactName" Name="listBox1" Width="100"
Height="100" VerticalAlignment="Top" />
<Label Content="{Binding Path=Customers/ContactTitle}" Height="23"
Width="100" Name="label1" VerticalAlignment="Top"></Label>
</Grid>
Q('+9%"&#%?'(.1)%=".5'*%E#('9+#$%O**)(%!*$% ENDL3O
L" ]+&D!% Z(D#+) V^N^E &D*&(!"(+!% #'&+9" (+3' &D//)4( @!& *''" !##'# 5)4 F)4S+"9 F+(@ :;<1
7=> +" YPB !//%+$!(+)"&1 :5('4 6)D @!8' !##'# !" :;<17=> #!(! &)D4$' () 6)D4 !//%+$!(+)"E
6)D $!" "!8+9!(' (@' !8!+%!*%' #!(! T'%#& +" (@!( #!(! &)D4$' +" (@' ;!(! Z)D4$'& F+"#)FE
&@)F" @'4' +" B+9D4' MKN1
:0;<*$%&'(% >@' ;!(! Z)D4$'& F+"#)F1
>@' ;!(! Z)D4$'& F+"#)F '"!*%'& 6)D () #4!9 T'%#& 54)3 6)D4 #!(! &)D4$' !"# #4)/ (@'3
)"() (@' #'&+9" &D45!$'1 Y@'" ! #!(! T'%# +& #4)//'# )"() (@' #'&+9" &D45!$'E ! *)D"# $)"K
(4)% +& !D()3!(+$!%%6 9'"'4!('# !%)"9 F+(@ !"6 4'CD+4'# ,:-. $)#' () $4'!(' 4'CD+4'# #!(!
4'&)D4$'&E &D$@ !& ?)22#$%.)<F.#G()*+$# )*?'$(&1 U)D $!" $@!"9' (@' (6/' )5 *)D"# $)"(4)%
(@!( +& $4'!('# *6 $%+$S+"9 (@' T'%# +" (@' ;!(! Z)D4$'& F+"#)F !"# &'%'$(+"9 (@' $)"(4)% 54)3
www.it-ebooks.info
%2&= /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
(@' #4)/K#)F" *)R1 L5 (@' $)"(4)% 6)D #'&+4' +& ")( %+&('#E 6)D $!" !## +( () (@' #'5!D%( %+&( *6
&'%'$(+"9 QD&()3+0'1
8'+5'+9%"*%R'#$1$@&'@1)%E1"1Y@'" *+"#+"9 () %+&(& )5 $)3/%'R )*?'$(&E 6)D 3+9@( F!"( () $4'!(' ! 3!&('4K#'(!+% 8+'F (@!(
'"!*%'& (@' D&'4 () &'%'$( )"' +('3 54)3 !" D//'4K%'8'% %+&( !"# 8+'F (@' #'(!+%& !*)D( (@'
&'%'$('# )*?'$(1 B)4 %+&(& )5 $)3/%'R )*?'$(&E (@+& +& !& &+3/%' !& &'((+"9 (@' ,'%: /4)/'4(6 )5
'!$@ #'(!+% *+"#+"9 () (@' $)44'$( /4)/'4(6 () #+&/%!6 !"# 3!S+"9 &D4' (@!( (@' D//'4K%'8'%
+('3 $)"(4)%& +" (@' D&'4 +"('45!$' @!8' (@' ;4(8<$:+)<.=#/>.%:?*++#<%;%#1 /4)/'4(6 &'(
() A+*# &) (@!( (@' &'%'$('# +('3 +& &'( () (@' $D44'"( +('3 !"# (@' #'(!+% %+&(& !4' D/#!('#
!D()3!(+$!%%61 >@' 5)%%)F+"9 'R!3/%' #'3)"&(4!('& ! &+3/%' 3!&('4K#'(!+% 8+'F1 =!$@ &.-.4.)<
)*?'$( $)"(!+"& ! %+&( )5 K+)*7 )*?'$(&E '!$@ K+)*7 )*?'$( $)"(!+"& ! %+&( )5 M172)8## )*?'$(&E
!"# !%% )*?'$(& +" (@+& 'R!3/%' @!8' ! C'1# /4)/'4(6G
<Grid DataContext="{Binding Source={StaticResource Divisions}}">
<StackPanel>
<Label>Divisions</Label>
<ListBox ItemsSource="{Binding}" DisplayMemberPath="Name"
IsSynchronizedWithCurrentItem="True" />
</StackPanel>
<StackPanel>
<Label Content="{Binding Path=Name}" />
<ListBox ItemsSource="{Binding Path=Groups}" DisplayMemberPath="Name"
IsSynchronizedWithCurrentItem="True" />
</StackPanel>
<StackPanel>
<Label Content="{Binding Path=Groups/Name}" />
<ListBox DisplayMemberPath="Name"
ItemsSource="{Binding Path=Groups/Employees}" />
</StackPanel>
</Grid>
B)4 #+&/%!6+"9 @+'4!4$@+$!% #!(!E &'' A&+"9 [+'4!4$@+$!% ;!(! >'3/%!('& +" .'&&)" V1
8'+5'+9%"*%S#)1"#5% ENDL3O%O10)#(
Y@'" @+'4!4$@+$!% #!(! +& 4'(4+'8'# 54)3 #!(!*!&'&E +( (6/+$!%%6 +& /4'&'"('# +" 4'%!('# (!*%'&1
L" :;<17=>E (@'&' 4'%!(+)"&@+/& *'(F''" (!*%'& !4' '&(!*%+&@'# *6 &'%'N#2'%.)< )*?'$(&E
F@+$@ %+"S ! $)%D3" +" )"' (!*%' () ! $)%D3" +" !")(@'4 (!*%'1 L" YPBE 6)D $!" 4'(4+'8' 4'K
%!('# 4'$)4#& *6 *+"#+"9 () (@' #!(! 4'%!(+)"1 >@' /!(('4" 5)4 $4'!(+"9 ! *+"#+"9 () ! 4'%!(+)"
+& !& 5)%%)F&E F@'4' ,'+#<%A'!2# 4'/4'&'"(& ! (!*%'E N#2'%.)< 4'/4'&'"(& ! $@+%# 4'%!(+)" )5 (@!(
(!*%'E !"# +#2'%.)<O 4'/4'&'"(& ! $@+%# 4'%!(+)" )5 (@' #!(! 4'(D4"'# *6 N#2'%.)<G
{Binding Path=ParentTable/Relation/Relation2}
U)D $!" *+"# (@4)D9@ $@+%# 4'%!(+)"& )"%6_ 6)D $!"")( *+"# D/ (@4)D9@ /!4'"( 4'%!(+)"&1
www.it-ebooks.info
.'&&)" NG 2+"#+"9 () ;!(! Z)D4$'& /4!) $*%&% 2&&
>@' 5)%%)F+"9 'R!3/%' #'3)"&(4!('& +"+(+!%+0+"9 ! #!(! &'( F+(@ (F) 4'%!('# (!*%'&G
?*4%)1#+4 !"# +/#+41 >@' +/#+4 (!*%' @!& ! 5)4'+9" S'6 $!%%'# ?*4%)1#+;& (@!( 4'%!('& ()
(@' /4+3!46 S'6 )5 (@' ?*4%)1#+4 (!*%'E !%&) $!%%'# ?*4%)1#+;&1 >@' "!3' )5 (@' 4'%!(+)" +"
(@' #!(!*!&' +& ?*4%)1#+4 +/#+41 >@' $)#' &@)F& (@' +"+(+!%+0+"9 )5 (@+& #!(! &'( !"# (@' &'(K
(+"9 )5 &'%'?)<%#6% () (@' /!4'"( (!*%'1 >@' ,:-. &@)F& @)F () *+"# (@' 4'%!('# (!*%' () (@'
#!(! 4'%!(+)" () 8+'F 4'%!('# 4'$)4#& !D()3!(+$!%%6G
=14>)#%*!%?'(.1)%81('@%<*5#
Public Class Window1
Dim aset As NwindDataSet = New NwindDataSet()
Dim custAdap As _
NwindDataSetTableAdapters.CustomersTableAdapter = _
New NwindDataSetTableAdapters.CustomersTableAdapter()
Dim ordAdap As NwindDataSetTableAdapters.OrdersTableAdapter = _
New NwindDataSetTableAdapters.OrdersTableAdapter()
Public Sub New()
InitializeComponent()
custAdap.Fill(aset.Customers)
OrdAdap.Fill(aset.Orders)
Grid1.DataContext = aset.Customers
End Sub
=14>)#%*!%<A%<*5#
public partial class Window1 : Window
{
NwindDataSet aset = new NwindDataSet();
NwindDataSetTableAdapters.CustomersTableAdapter custAdap =
new NwindDataSetTableAdapters.CustomersTableAdapter();
NwindDataSetTableAdapters.OrdersTableAdapter ordAdap =
new NwindDataSetTableAdapters.OrdersTableAdapter();
public Window1()
{
InitializeComponent();
custAdap.Fill(aset.Customers);
ordAdap.Fill(aset.Orders);
Grid1.DataContext = aset.Customers;
}
}
=14>)#%*!%I J:%<*5#
<!-- XAML -->
<Grid Name="Grid1">
<ListBox ItemsSource="{Binding}" DisplayMemberPath="ContactName"
Name="listBox1" Width="100" Height="100" VerticalAlignment="Top" />
<ListBox ItemsSource="{Binding Path=CustomersOrders}"
DisplayMemberPath="OrderID" Height="100" Width="100"
Name="listBox2" VerticalAlignment="Bottom" />
</Grid>
www.it-ebooks.info
%2&> /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
8'+5'+9%"*%1+%N0P#@"%/'"&%,)-&." !"!/0$123&0>@' !"#$%&'%',+)-./#+ $%!&& '"!*%'& 6)D () *+"# ! YPB '%'3'"( )4 /4)/'4(6 () ! 3'(@)#
$!%%'# )" !" )*?'$(1 U)D $!" &/'$+56 !" )*?'$( (6/' !"# ! 3'(@)# )" (@!( (6/'E (@'" *+"# ()
(@' 4'&D%(& )5 (@!( 3'(@)# $!%%1 >!*%' MK` %+&(& (@' +3/)4(!"( /4)/'4(+'& )5 !"#$%&'%',+)-./#+1
!"#$%&'2% L3/)4(!"( P4)/'4(+'& )5 !"#$%&'%',+)-./#+
)*+)$* , -$./*0) 0+1
?)<4%+*$%)+,'+'1#%#+4 O'/4'&'"(& (@' %+&( )5 /!4!3'('4& () /!&& () (@' $)"&(4D$()41
;4H48<$:+)<)*4 L"#+$!('& F@'(@'4 )*?'$( $4'!(+)" !"# 3'(@)# $!%%& !4'
/'45)43'# )" (@' 5)4'94)D"# (@4'!# )4 )" ! *!$S94)D"#
(@4'!#1
9#%:)/C'1# O'/4'&'"(& (@' "!3' )5 (@' 3'(@)# )5 (@' &)D4$' )*?'$(
() $!%%1
9#%:)/,'+'1#%#+4 O'/4'&'"(& (@' %+&( )5 /!4!3'('4& () /!&& () (@' 3'(@)#
&/'$+T'# *6 (@' 9#%:)/C'1# /4)/'4(61
!"#$%;<4%'<$# a'(& )4 &'(& (@' )*?'$( D&'# !& (@' *+"#+"9 &)D4$'1
!"#$%A87# a'(& )4 &'(& (@' (6/' )5 )*?'$( )5 F@+$@ () $4'!(' !" +"&(!"$'1
>@' 5)%%)F+"9 'R!3/%' #'3)"&(4!('& @)F () $4'!(' ! &+3/%' !"#$%&'%',+)-./#+ )*?'$( 5)4
!" )*?'$( F+(@ ! 3'(@)# (@!( (!S'& ") /!4!3'('4&G
<Window.Resources>
<ObjectDataProvider x:Key="myObjectProvider" ObjectType="{x:Type
local:myObject}" MethodName="GetCollection" />
</Window.Resources>
U)D $!" !%&) *+"# () (@+& !"#$%&'%',+)-./#+ )*?'$(E D&+"9 ! 5.</.<@ )*?'$(E !& &@)F" @'4'G
<ListBox Name="ListBox1" DisplayMemberPath="ItemID"
ItemsSource="{Binding Source={StaticResource myObjectProvider}}" />
L5 (@' 3'(@)# 4'CD+4'& /!4!3'('4&E 6)D $!" /4)8+#' (@'3 +" (@' 9#%:)/,'+'1#%#+4
/4)/'4(61 .+S'F+&'E +5 (@' $)"&(4D$()4 4'CD+4'& /!4!3'('4&E (@'6 !4' /4)8+#'# +" (@'
?)<4%+*$%)+,'+'1#%#+4 /4)/'4(61 =R!3/%'& !4' &@)F" @'4'G
<Window.Resources>
<ObjectDataProvider x:Key="myObjectProvider"
ObjectType="{x:Type local:myObject}" MethodName="GetCollection">
<ObjectDataProvider.ConstructorParameters>
<system:Double>12</system:Double>
</ObjectDataProvider.ConstructorParameters>
<ObjectDataProvider.MethodParameters>
<system:String>Items</system:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
www.it-ebooks.info
.'&&)" NG 2+"#+"9 () ;!(! Z)D4$'& /4!) $*%&% 2&?
:%(@)D9@ 6)D $!" *+"# () #!(! /4'&'"('# *6 !"#$%&'%',+)-./#+P 6)D $!"")( D/#!(' #!(!_
(@!( +&E (@' *+"#+"9 +& !%F!6& 9)+"9 () *' 4'!#K)"%61
8'+5'+9%"*%IJ:%Q('+9%45* !"!/0$123&0>@' 012&'%',+)-./#+ $%!&& '"!*%'& 6)D () *+"# YPB '%'3'"(& () #!(! +" (@' ,-. 5)43!(1
L3/)4(!"( /4)/'4(+'& )5 (@' 012&'%',+)-./#+ $%!&& !4' &@)F" +" >!*%' MKb1
!"#$%&'8% L3/)4(!"( P4)/'4(+'& )5 012&'%',+)-./#+
)*+)$* , -$./*0) 0+1
&)$*1#<% a'(& )4 &'(& (@' 012&)$*1#<% )*?'$( () *' D&'# !& (@' *+"#+"9
&)D4$'1
()*+$# a'(& )4 &'(& (@' A"+5)43 O'&)D4$' L"#+$!()4 HAOLI )5 (@' ,-. T%' ()
*' D&'# !& (@' *+"#+"9 &)D4$'1
0,'%: a'(& )4 &'(& (@' 0,'%: CD'46 D&'# () 9'"'4!(' (@' ,-. #!(!1
>@' 5)%%)F+"9 'R!3/%' #'3)"&(4!('& !" 012&'%',+)-./#+ )*?'$( /4)8+#+"9 #!(! 54)3 !
&)D4$' T%' $!%%'# L('3&1R3%G
<Window.Resources>
<XmlDataProvider x:Key="Items" Source="Items.xml" />
</Window.Resources>
U)D $!" !%&) /4)8+#' (@' ,-. #!(! +"%+"' !& !" ,-. #!(! +&%!"#1 L" (@+& $!&'E 6)D F4!/ (@'
,-. #!(! +" 0&'%' (!9&E !& &@)F" @'4'G
<Window.Resources>
<XmlDataProvider x:Key="Items">
<x:XData>
<!--XML Data omitted-->
</x:XData>
</XmlDataProvider>
</Window.Resources>
U)D $!" *+"# '%'3'"(& () (@' #!(! /4)8+#'# *6 012&'%',+)-./#+ +" (@' &!3' F!6 6)D
F)D%# *+"# () !"6 )(@'4 #!(! &)D4$'G "!3'%6E D&+"9 ! 5.</.<@ )*?'$( !"# &/'$+56+"9 (@'
012&'%',+)-./#+ )*?'$( +" (@' ()*+$# /4)/'4(6E !& &@)F" @'4'G
<ListBox ItemsSource="{Binding Source={StaticResource Items}}"
DisplayMemberPath="ItemName" Name="listBox1" Width="100" Height="100"
VerticalAlignment="Top" />
Q('+9%4/!"6%/'"&%45* !"!/0$123&0
U)D $!" D&' 0,'%: 'R/4'&&+)"& () T%('4 (@' 4'&D%(& 'R/)&'# *6 012&'%',+)-./#+ )4 () T%('4 (@'
4'$)4#& #+&/%!6'# +" (@' *)D"# $)"(4)%&1 26 &'((+"9 (@' 0,'%: /4)/'4(6 )5 012&'%',+)-./#+ ()
!" 0,'%: 'R/4'&&+)"E 6)D $!" T%('4 (@' #!(! /4)8+#'# *6 (@' &)D4$'1 >@' 5)%%)F+"9 'R!3/%'
www.it-ebooks.info
%2>3 /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
T%('4& (@' 4'&D%(& 'R/)&'# *6 !" 012&'%',+)-./#+ )*?'$( () +"$%D#' )"%6 (@)&' ")#'& $!%%'#
QM67#<4.-#;%#14R +" (@' Q;%#14R ()/K%'8'% ")#'G
<Window.Resources>
<XmlDataProvider x:Key="Items" Source="Items.xml"
XPath="Items/ExpensiveItems" />
</Window.Resources>
U)D $!" !%&) !//%6 0,'%: 'R/4'&&+)"& +" (@' *)D"# $)"(4)%&1 >@' 5)%%)F+"9 'R!3/%' &'(&
(@' 0,'%: /4)/'4(6 () &.'1)</ H&@)F" +" *)%#IE F@+$@ +"#+$!('& (@!( )"%6 #!(! $)"(!+"'# +"
Q&.'1)</R (!9& F+%% *' *)D"#G
<ListBox ItemsSource="{Binding Source={StaticResource Items}
XPath=Diamond}" DisplayMemberPath="ItemName" Name="listBox1" Width="100"
Height="100" VerticalAlignment="Top" />
!"#$%&'
O&#$#%1$#%5'!!#$#+"%4#"&*5(%!*$%0'+5'+9%"*%5'!!#$#+"%51"1%(*.$@#(D%8#%(.$#%-*.%.+5#$("1+5%
&*/%"*%0'+5%+*"%*+)-%"*%)'("(%*!%51"1%0."%1)(*%"*% ENDL3O%*0P#@"(,%,)-&." !"!/0$123&0%*0T
P#@"(,%1+5%45* !"!/0$123&0%*0P#@"(%0#@1.(#%#1@&%*+#%&1(%'"(%*/+%'+5'M'5.1)%(.0")#"'#(D
!"#$%&$' !@@ABBCDE%F%-FGFHFBA
L" (@+& %!*E 6)D $4'!(' !" !//%+$!(+)" () 8+'F 4'%!('# #!(! +" ! #!(!*!&'1 U)D D&' (@'
7)4(@F+"# &!3/%' #!(!*!&' !"# $4'!(' !" !//%+$!(+)" (@!( '"!*%'& 6)D () $@))&' ! $)"(!$(
"!3'E 8+'F ! %+&( )5 #!('& )" F@+$@ )4#'4& F'4' /%!$'#E !"# &'' (@' #'(!+%& !*)D( &@+//+"9
!"# F@+$@ /4)#D$(& F'4' )4#'4'#1 L" .'&&)" VE 6)D F+%% *D+%# )" (@+& !//%+$!(+)"1
'('"$&)' * 55'+9%1%E1"1%=*.$@#
*+ B4)3 (@' ()/K%'8'% 5)%#'4 )5 (@' $)3/!"+)" Q;E $)/6 (@' 7F+"# #!(!*!&' () ! $)"8'K
"+'"( %)$!(+)"1
,+ L" ]+&D!% Z(D#+)E )/'" ! "'F YPB ://%+$!(+)" /4)?'$(1
-+ L" ]+&D!% Z(D#+)E 54)3 (@' ;!(! 3'"D $@))&' :## 7'F ;!(! Z)D4$'1 >@' ;!(! Z)D4$'
Q)"T9D4!(+)" Y+0!4# )/'"&E F+(@ ;!(!*!&' &'%'$('# +" (@' T4&( /!9'1 Q%+$S 7'R( ()
$)"(+"D'1
.+ <" (@' Q@))&' : ;!(!*!&' -)#'% /!9'E &'%'$( ;!(!&'( !"# $%+$S 7'R(1
/+ <" (@' Q@))&' U)D4 ;!(! Q)""'$(+)" /!9'E $%+$S 7'F Q)""'$(+)" () )/'" (@' :##
Q)""'$(+)" #+!%)9 *)R1 Q@!"9' ;!(! Z)D4$' () -+$4)&)5( :$$'&& ;!(!*!&' B+%'E
$%+$S Q)"(+"D'E !"# (@'" $%+$S 24)F&' () *4)F&' () (@' %)$!(+)" F@'4' 6)D $)/+'#
6)D4 7F+"# #!(!*!&' T%'1 :5('4 &'%'$(+"9 6)D4 #!(!*!&' T%'E $%+$S </'"1 L" (@' :##
Q)""'$(+)" #+!%)9 *)RE $%+$S >'&( Q)""'$(+)" () ('&( (@' $)""'$(+)"1 L5 (@' ('&( +& &D$K
$'&&5D%E $%+$S <cE $%+$S <c +" (@' :## Q)""'$(+)" #+!%)9 *)RE $%+$S 7'R( +" (@' Q@))&'
www.it-ebooks.info
.'&&)" NG 2+"#+"9 () ;!(! Z)D4$'& /4!) $*%&% 2>(
U)D4 ;!(! Q)""'$(+)" #+!%)9 *)RE !"# (@'" $%+$S U'& +" (@' /)/KD/ F+"#)F1 Q%+$S
7'R( !9!+"1
0+ <" (@' Q@))&' U)D4 ;!(!2!&' <*?'$(& /!9'E 'R/!"# (@' >!*%'& ")#' !"# &'%'$( (@'
QD&()3'4& (!*%' !"# (@' <4#'4& (!*%'1 =R/!"# (@' ]+'F& ")#'E &'%'$( <4#'4 ;'(!+%&
=R('"#'#E !"# $%+$S B+"+&@1 : "'F $%!&& $!%%'# CG.</&'%'(#% +& !##'# () 6)D4 &)%D(+)"E
!"# (!*%' !#!/('4& !4' $4'!('#1
1+ L" Z)%D(+)" =R/%)4'4E #)D*%'K$%+$S 7F+"#;!(!Z'(1R&# () )/'" (@' ;!(!&'( ;'&+9"'41
O+9@(K$%+$S (@' ;!(!&'( ;'&+9"'4_ $@))&' :## !"# (@'" $@))&' O'%!(+)" () )/'" (@'
O'%!(+)" F+"#)F1
2+ L" (@' O'%!(+)" F+"#)FE &'( P!4'"( >!*%' () <4#'4& !"# &'( Q@+%# >!*%' () <4#'4 ;'(!+%&
=R('"#'#1 ]'4+56 (@!( c'6 Q)%D3"& !"# B)4'+9" c'6 Q)%D3"& !4' &'( () <4#'4L;1 Q%+$S
<c () $4'!(' (@' "'F #!(! 4'%!(+)"1
3+ B4)3 (@' 2D+%# 3'"DE $@))&' 2D+%# Z)%D(+)" () *D+%# !"# &!8' 6)D4 &)%D(+)"1
'('"$&)' , 8'+5'+9%"*%S#)1"'*+1)%E1"1
*+ L" (@' #'&+9"'4E !## (@' "!3'&/!$' !((4+*D(' H&@)F" *)%#'# +" (@' 5)%%)F+"9 $)#'I ()
(@' Y+"#)F '%'3'"( () +3/)4( 6)D4 /4)?'$(1 P%'!&' ")(' (@!(E #'/'"#+"9 )" (@' "!3'
)5 6)D4 /4)?'$(E 6)D F+%% @!8' () D/#!(' (@' "!3'&/!$' )5 (@+& /4)?'$(1
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="350" Width="523" IJKDBLJMNO@KP'DFJABQF@AL#ABBRDS(">
</Window.Resources>
,+ B4)3 (@' ;!(! 3'"DE $@))&' Z@)F ;!(! Z)D4$'& () )/'" (@' ;!(! Z)D4$'& F+"#)F1
=R/!"# (@' QD&()3'4& ")#'1
-+ Q%+$S )"' )5 (@' T'%#&d5)4 'R!3/%'E Q)3/!"67!3'dD"#'4 (@' QD&()3'4& ")#'1
</'" (@' #4)/K#)F" *)R !"# &'%'$( QD&()3+0'1 >@' QD&()3+0' Q)"(4)% 2+"#+"9 F+"K
#)F )/'"&1
.+ L" (@' QD&()3+0' Q)"(4)% 2+"#+"9 F+"#)FE &'( (@' ;!(! >6/' #4)/K#)F" *)R () Z(4+"9
!"# '"&D4' (@!( (@' *)R "'R( () .+&(2)R +& &'%'$('#1 O'/'!( (@+& /4)$'#D4' F+(@ (@'
;!(! >6/' #4)/K#)F" *)R &'( () ;!('>+3'1 Q%+$S <c1
/+ L" (@' ;!(! Z)D4$'& F+"#)FE D"#'4 (@' QD&()3'4& ")#'E )/'" (@' #4)/K#)F" *)R 5)4
Q)"(!$(7!3' !"# (@'" &'%'$( .+&(2)R1
0+ B4)3 (@' ;!(! Z)D4$'& F+"#)FE #4!9 (@' Q)"(!$(7!3' ")#' () (@' #'&+9" &D45!$'1 :
*)D"# %+&( *)R F+(@ !" !//4)/4+!(' %!*'% +& $4'!('#1
1+ L" (@' ;!(! Z)D4$'& F+"#)FE F+(@+" (@' QD&()3'4& ")#'E 'R/!"# (@' <4#'4& ")#' !"#
)/'" (@' #4)/K#)F" *)R 5)4 <4#'4;!(' !"# &'%'$( .+&(2)R1
2+ B4)3 (@' ;!(! Z)D4$'& Y+"#)FE #4!9 (@' <4#'4;!(' ")#' () (@' ;'&+9" &D45!$' ()
$4'!(' ! *)D"# %+&( *)R1
www.it-ebooks.info
%2>6 /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
3+ L" (@' ;!(! Z)D4$'& F+"#)FE F+(@+" (@' QD&()3'4& ")#' !"# F+(@+" (@' <4#'4& ")#'E
)/'" (@' <4#'4 ;'(!+%& =R('"#'# ")#'1 </'" (@' #4)/K#)F" *)R 5)4 P4)#D$(7!3'
!"# &'%'$( .+&(2)R1
*4+ B4)3 (@' ;!(! Z)D4$'& F+"#)FE #4!9 (@' P4)#D$(7!3' ")#' () (@' #'&+9" &D45!$' ()
$4'!(' ! *)D"# %+&( *)R1
**+ L" (@' ;!(! Z)D4$'& F+"#)FE F+(@+" (@' QD&()3'4& ")#'E D"#'4 (@' <4#'4& ")#'E #4!9
(@' Z@+/7!3'E Z@+/:##4'&&E Z@+/Q+(6E !"# Z@+/Q)D"(46 ")#'& () (@' #'&+9" &D45!$' ()
$4'!(' *)D"# ('R( *)R'&1
*,+ P4'&& Be () 4D" 6)D4 !//%+$!(+)"1 7)(' (@!( F@'" ! Q)"(!$( 7!3' +& &'%'$('# +" (@' T4&(
%+&( *)RE (@' )(@'4 *)D"# $)"(4)%& !D()3!(+$!%%6 &6"$ () (@' &'%'$('# +('31 Z+3+%!4%6E +5
!" )4#'4 #!(' +& &'%'$('# +" (@' &'$)"# %+&( *)RE (@' +('3& +" (@' (@+4# %+&( H5)4 /4)#D$(
"!3'I *)R !4' &6"$@4)"+0'# F+(@ (@' &'%'$('# +('31
:#((*+%=.441$-■ Y@'" *+"#+"9 !" +('3 $)"(4)% () ! %+&( )5 #!(!E 6)D 3D&( &'( (@' ;%#14()*+$# /4)/'4(6
() ! 5.</.<@ $%!&& (@!( &/'$+T'& (@' &)D4$' )5 (@' %+&(1 &.472'89#1!#+,'%: +"#+$!('&
F@+$@ /4)/'4(6 )5 (@' %+&( &@)D%# *' #+&/%!6'# +" (@' +('3 $)"(4)%1
■ L"#+8+#D!% /4)/'4(+'& $!" *' *)D"# () %+&(& )5 #!(!1 L"+(+!%%6E (@' T4&( 3'3*'4 )5
!"6 &D$@ *)D"# %+&( +& #+&/%!6'#E *D( (@' %+&( $!" *' "!8+9!('# (@4)D9@ (@' #'5!D%(
;?)22#$%.)<F.#G /4)/'4(6 4'(4+'8'# (@4)D9@ (@' ?)22#$%.)<F.#G()*+$# )*?'$(1
■ Y@'" *+"#+"9 () @+'4!4$@+$!% #!(!E &'( (@' ;4(8<$:+)<.=#/>.%:?*++#<%;%#1 /4)/'4(6 )"
'!$@ +('3 $)"(4)% () A+*# () '"!*%' !D()3!(+$ AL D/#!('& )5 @+'4!4$@+$!% #!(!1 U)D $!"
&'( ! 5.</.<@ $%!&& () #'(!+% %+&(& *6 &/'$+56+"9 (@' #'(!+% %+&( (@4)D9@ (@' ,'%: /4)/'4(61
■ U)D $!" *+"# () (@' 8!%D' 4'(D4"'# *6 ! 3'(@)# (@4)D9@ !"#$%&'%',+)-./#+1
■ U)D $!" *+"# () ,-. F+(@ 012&'%',+)-./#+1 012&'%',+)-./#+ 4'CD+4'& ,-. !& ! T%'E !"
012&)$*1#<% )*?'$(E )4 ! #!(! +&%!"#1
:#((*+%S#M'#/U)D $!" D&' (@' 5)%%)F+"9 CD'&(+)"& () ('&( 6)D4 S")F%'#9' )5 (@' +"5)43!(+)" +" .'&&)" NE
W2+"#+"9 () ;!(! Z)D4$'&1X >@' CD'&(+)"& !4' !%&) !8!+%!*%' )" (@' $)3/!"+)" Q; +5 6)D /4'5'4
() 4'8+'F (@'3 +" '%'$(4)"+$ 5)431
()% % !1.T$*.%
+(/#$(%"*%"&#(#%U.#("'*+(%1+5%#F>)1+1"'*+(%*!%/&-%#1@&%1+(/#$%@&*'@#%'(%@*$$#@"%*$%'+@*$T
$#@"%1$#%)*@1"#5%'+%"&#%V +(/#$(W%(#@"'*+%1"%"&#%#+5%*!%"&#%0**XD
*+ Y@+$@ )5 (@' 5)%%)F+"9 $)#' &!3/%'& &@)F& ! 3.4%5)6 )*?'$( $)44'$(%6 *)D"# () (@'
?*4%)1#+H//+#44 T'%# )5 ! #!(! (!*%'f >@' #!(! (!*%' +& "!3'# ?*4%)1#+4 +" !" :;<1
()% !1.T$*.%
+(/#$(%"*%"&#(#%U.#("'*+(%1+5%#F>)1+1"'*+(%*!%/&-%#1@&%1+(/#$%@&*'@#%'(%@*$$#@"%*$%'+@*$T
$#@"%1$#%)*@1"#5%'+%"&#%V +(/#$(W%(#@"'*+%1"%"&#%#+5%*!%"&#%0**XD
www.it-ebooks.info
.'&&)" NG 2+"#+"9 () ;!(! Z)D4$'& /4!) $*%&% 2>2
7=> #!(! &'( "!3'# 18(#%1 >!S' *)(@ ,:-. !"# $)#' +"() !$$)D"( +" (@' /)&&+*%'
!"&F'4&1
#+
=14>)#%*!%?'(.1)%81('@%<*5#
Grid1.DataContext=mySet
=14>)#%*!%<A%<*5#
Grid1.DataContext=mySet;
=14>)#%*!%I J:%<*5#
<!-- XAML -->
<Grid Name="Grid1">
<ListBox ItemsSource="{Binding}"
DisplayMemberPath="CustomerAddress"
Name="listBox1" Width="100" Height="100" VerticalAlignment="Top" />
</Grid>
5+
=14>)#%*!%?'(.1)%81('@%<*5#
Grid1.DataContext=mySet
=14>)#%*!%<A%<*5#
Grid1.DataContext=mySet;
=14>)#%*!%I J:%<*5#
<!-- XAML -->
<Grid Name="Grid1">
<ListBox ItemsSource="{Binding Path=mySet.Customers}"
DisplayMemberPath="CustomerAddress"
Name="listBox1" Width="100" Height="100" VerticalAlignment="Top" />
</Grid>
$+
=14>)#%*!%?'(.1)%81('@%<*5#
Grid1.DataContext=mySet.Customers
=14>)#%*!%<A%<*5#
Grid1.DataContext=mySet.Customers;
=14>)#%*!%I J:%<*5#
<!-- XAML -->
<Grid Name="Grid1">
<ListBox ItemsSource="{Binding}"
DisplayMemberPath="CustomerAddress"
Name="listBox1" Width="100" Height="100" VerticalAlignment="Top" />
</Grid>
www.it-ebooks.info
%2>8 /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
6+
=14>)#%*!%?'(.1)%81('@%<*5#
Grid1.DataContext=mySet.Customers
=14>)#%*!%<A%<*5#
Grid1.DataContext=mySet.Customers;
=14>)#%*!%I J:%<*5#
<!-- XAML -->
<Grid Name="Grid1">
<ListBox ItemsSource="{Binding}"
DisplayMemberPath="Customers/CustomerAddress"
Name="listBox1" Width="100" Height="100" VerticalAlignment="Top" />
</Grid>
,+ U)DJ4' *+"#+"9 ! 3.4%5)6 )*?'$( () (@' P4+$' T'%# +" !" :;<17=> #!(! (!*%' $!%%'#
;'(!+%&1 >@+& (!*%' +& 4'%!('# () (@' <4#'4& (!*%' (@4)D9@ ! /!4'"( 4'%!(+)" $!%%'#
<4#'4&;'(!+%&1 >@' <4#'4& (!*%' +& 4'%!('# () ! (!*%' $!%%'# QD&()3'4& (@4)D9@ ! /!4'"(
4'%!(+)" $!%%'# QD&()3'4&<4#'4&D >@' &'%'?)<%#6% /4)/'4(6 5)4 6)D4 %+&( *)RJ@!& *''"
&'( () (@' QD&()3'4& (!*%'E F@+$@ +& (@' /!4'"( (!*%' )5 (@' QD&()3'4&<4#'4& 4'%!(+)"1
Y@+$@ )5 (@' 5)%%)F+"9 $)44'$(%6 *+"#& 3.4%5)6 () (@' ,+.$# T'%#f
#+
<ListBox ItemsSource="{Binding}"
DisplayMemberPath="Price" Name="listBox1"
Width="100" Height="100" VerticalAlignment="Top" />
5+
<ListBox ItemsSource="{Binding Path=OrdersDetails}"
DisplayMemberPath="Price" Name="listBox1"
Width="100" Height="100" VerticalAlignment="Top" />
$+
<ListBox ItemsSource="{Binding Path=CustomersOrders/OrdersDetails}"
DisplayMemberPath="Price" Name="listBox1"
Width="100" Height="100" VerticalAlignment="Top" />
6+
<ListBox ItemsSource="{Binding Path=Customers/CustomersOrders/OrdersDetails}"
DisplayMemberPath="Price" Name="listBox1"
Width="100" Height="100" VerticalAlignment="Top" />
www.it-ebooks.info
.'&&)" VG -!"+/D%!(+"9 !"# ;+&/%!6+"9 ;!(! /4!) $*%&% 2>9
#ABBRD%6L%7FDCQUKFGCDE%FDV%-CBQKFMCDE%-FGF
YPB @!& *D+%(K+" 5D"$(+)"!%+(6 5)4 &)4(+"9E 94)D/+"9E !"# T%('4+"9 #!(!1 L" !##+(+)"E +( /4)8+#'&
D"/4'$'#'"('# &D//)4( 5)4 $D&()3+0+"9 #!(! #+&/%!6 (@4)D9@ #!(! ('3/%!(' ('$@")%)961 L"
(@+& %'&&)"E 6)D %'!4" () !//%6 &)4(+"9 !"# 94)D/+"9 (@4)D9@ (@' ;?)22#$%.)<F.#G +"('45!$'1
U)D %'!4" () $4'!(' !"# +3/%'3'"( $D&()3 T%('4& 5)4 #!(! #+&/%!6'# +" YPBE !"# 6)D %'!4" ()
D&' #!(! ('3/%!('& () $D&()3+0' (@' !//'!4!"$' )5 #!(! +" 6)D4 D&'4 +"('45!$'1
!"#$%"&'(%)#((*+,%-*.%/'))%0#%10)#%"*2%
■ Q4'!(' !"# +3/%'3'"( ! #!(! ('3/%!('1
■ Z)4( #!(! (@4)D9@ ;?)22#$%.)<F.#GD
■ ://%6 94)D/+"9 () #!(! F+(@ ;?)22#$%.)<F.#GD
■ A&' !" ;?)17'+#+ () $4'!(' ! $D&()3 &)4(+"9 &$@'3'1
■ ://%6 ! $D&()3 T%('4 () *)D"# #!(!1
■ ://%6 ! T%('4 () ! *)D"# :;<17=> )*?'$(1
■ L3/%'3'"( !"# D&' ! &'%'A#172'%#(#2#$%)+ $%!&&1
■ Q4'!(' !"# D&' S.#+'+$:.$'2&'%'A#172'%#1
3("'41"#5%)#((*+%"'4#2%67%4'+."#(
E1"1%O#4>)1"#(Z) 5!4E 6)D @!8' &''" @)F () *+"# $)"('"( $)"(4)%& !"# +('3 $)"(4)%& () #!(! () #+&/%!6 *)D"#
#!(! +" (@' D&'4 +"('45!$'1 >@' 4'&D%(&E @)F'8'4E @!8' *''" D"#'4F@'%3+"91 U)D @!8' &''"
@)F () /4'&'"( #!(! T'%#& !& &+3/%' ('R( +" $)"('"( $)"(4)%& !"# %+&(& )5 ('R( +" +('3 $)"(4)%&1
U)D $!" $4'!(' ! 4+$@ #!(! /4'&'"(!(+)" 'R/'4+'"$'E @)F'8'4E *6 +"$)4/)4!(+"9 #!(! ('3/%!('&
+"() 6)D4 AL #'&+9"1
: /'%'J%#172'%# +& ! *+( )5 ,:-. (@!( #'&$4+*'& @)F *)D"# #!(! +& #+&/%!6'#1 : #!(!
('3/%!(' $!" $)"(!+" '%'3'"(& (@!( !4' '!$@ *)D"# () ! #!(! /4)/'4(6E !%)"9 F+(@ !##+K
(+)"!% 3!4SD/ (@!( #'&$4+*'& %!6)D(E $)%)4E !"# )(@'4 !&/'$(& )5 !//'!4!"$'1 >@' 5)%%)F+"9
'R!3/%' #'3)"&(4!('& ! &+3/%' #!(! ('3/%!(' (@!( #'&$4+*'& ! 3'!#2 '%'3'"( *)D"# () (@'
?)<%'$%C'1# /4)/'4(61 >@' B)+#@+)*</E 5'$T@+)*</E 5)+/#+5+*4:EJ!"# 5)+/#+A:.$T<#44 /4)/K
'4(+'& !4' !%&) &'(G
<DataTemplate>
<Label Content="{Binding Path=ContactName}" BorderBrush="Black"
Background="Yellow" BorderThickness="3" Foreground="Blue" />
</DataTemplate>
B+9D4' MKV &@)F& ! %+&( *)R #+&/%!6+"9 ! %+&( )5 *)D"# #!(!1 B+9D4' MK` &@)F& (@' &!3'
%+&( *)R #+&/%!6+"9 (@' &!3' *)D"# #!(! F+(@ (@' /4'8+)D&%6 $+('# #!(! ('3/%!(' &'( () (@'
3.4%5)6D;%#14A#172'%# /4)/'4(61
!"#$%"&'(%)#((*+,%-*.%/'))%0#%10)#%"*2%
■ Q4'!(' !"# +3/%'3'"( ! #!(! ('3/%!('1
■ Z)4( #!(! (@4)D9@ ;?)22#$%.)<F.#GD
■ ://%6 94)D/+"9 () #!(! F+(@ ;?)22#$%.)<F.#GD
■ A&' !" ;?)17'+#+ () $4'!(' ! $D&()3 &)4(+"9 &$@'3'1;?)17'+#+
■ ://%6 ! $D&()3 T%('4 () *)D"# #!(!1
■ ://%6 ! T%('4 () ! *)D"# :;<17=> )*?'$(1
■ L3/%'3'"( !"# D&' ! &'%'A#172'%#(#2#$%)+ $%!&&1&'%'A#172'%#(#2#$%)+
■ Q4'!(' !"# D&' S.#+'+$:.$'2&'%'A#172'%#1
3("'41"#5%)#((*+%"'4#2%67%4'+."#(
www.it-ebooks.info
%2>= /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
:0;<*$%&'6% : *)D"# %+&( *)R F+(@)D( ! #!(! ('3/%!('1
:0;<*$%&'2% : *)D"# %+&( *)RJF+(@ ! #!(! ('3/%!(' !//%+'#1
Y@'" *+"#+"9 ! /4)/'4(6 )4 %+&( #+4'$(%6 () ! $)"(4)%E 6)D !4' %+3+('# () *+"#+"9 ! &+"9%'
/4)/'4(61 Y+(@ #!(! ('3/%!('&E @)F'8'4E 6)D $!" *+"# 3)4' (@!" )"' /4)/'4(6 +" '!$@ +('3E
(@'4'*6 #+&/%!6+"9 3D%(+/%' *+(& )5 4'%!('# #!(! ()9'(@'41 >@' 5)%%)F+"9 'R!3/%' #'3)"K
&(4!('& (@+& $)"$'/(1 L( +& ! 3)#+T$!(+)" )5 (@' ('3/%!(' &@)F" +" (@' /4'8+)D& 'R!3/%'E *D(
! @'!#'4 +& !##'# () '!$@ ?)<%'$%C'1# +('3 (@!( $)"&+&(& )5 (@' ('R( WQ)3/!"6 7!3'GX !"#
(@' ?)17'<8C'1# 8!%D' !&&)$+!('# F+(@ (@!( $)"(!$( "!3'1 :##+(+)"!% /4)/'4(+'& !4' &'( ()
/4)8+#' &(6%'E !"# *)(@ %!*'%& !4' /%!$'# F+(@+" ! (%'$T,'<#2 $%!&& () 5!$+%+(!(' %!6)D(G
<DataTemplate>
<StackPanel>
<Label Background="Purple" Foreground="White" BorderBrush="Red"
BorderThickness="4">
<Label.Content>
<WrapPanel HorizontalAlignment="Stretch">
<TextBlock>Company Name: </TextBlock>
<TextBlock Text="{Binding CompanyName}" />
</WrapPanel>
</Label.Content>
</Label>
<Label Content="{Binding Path=ContactName}" BorderBrush="Black"
www.it-ebooks.info
.'&&)" VG -!"+/D%!(+"9 !"# ;+&/%!6+"9 ;!(! /4!) $*%&% 2>&
HorizontalAlignment="Stretch" Background="Yellow"
BorderThickness="3" Foreground="Blue" />
</StackPanel>
</DataTemplate>
B+9D4' MKb &@)F& (@' 4'&D%(& )5 !//%6+"9 (@+& #!(! ('3/%!('1
:0;<*$%&'8% : *)D"# %+&( *)R F+(@ ! #!(! ('3/%!(' (@!( +"$%D#'& ! @'!#'4 F+(@ 4'%!('# #!(!1
U)D $!" !//%6 #!(! ('3/%!('& () $)"('"( $)"(4)%& !& F'%%1 :%(@)D9@ ! $)"('"( $)"(4)% $!"
#+&/%!6 )"%6 ! &+"9%' 4'$)4# !( ! (+3'E +( $!" D&' !%% (@' 5)43!((+"9 5'!(D4'& )5 (@' #!(! ('3K
/%!(' ('$@")%)961
=#""'+9%"&#%E1"1%O#4>)1"#
U)D &'( (@' #!(! ('3/%!(' )" ! $)"(4)% *6 &'((+"9 )"' )5 (F) /4)/'4(+'&1 B)4 $)"('"( $)"(4)%&E
6)D &'( (@' ?)<%#<%A#172'%# /4)/'4(6E !& &@)F" +" *)%# @'4'G
<Label Height="23" HorizontalAlignment="Left" Margin="56,0,0,91"
Name="label1" VerticalAlignment="Bottom" Width="120">
<Label.ContentTemplate>
<DataTemplate>
<!--Actual data template omitted-->
</DataTemplate>
</Label.ContentTemplate>
</Label>
B)4 +('3 $)"(4)%&E 6)D &'( (@' ;%#14A#172'%# /4)/'4(6E !& &@)F" +" *)%# @'4'G
<ListBox ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True"
Margin="18,19,205,148" Name="listBox1">
<ListBox.ItemTemplate>
<DataTemplate>
<!--Actual data template omitted-->
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
7)(' (@!( 5)4 +('3 $)"(4)%&E (@' &.472'89#1!#+,'%: !"# ;%#1A#172'%# /4)/'4(+'& !4' 3DK
(D!%%6 'R$%D&+8'_ 6)D $!" &'( )"' *D( ")( (@' )(@'41
www.it-ebooks.info
%2>> /4!) $*%& Q)"T9D4+"9 ;!(! 2+"#+"9
: 54'CD'"( /!(('4" F+(@ #!(! ('3/%!('& +& () #'T"' (@'3 +" ! 4'&)D4$' $)%%'$(+)" !"#
4'5'4'"$' (@'3 +" 6)D4 '%'3'"( 4!(@'4 (@!" #'T"+"9 (@'3 +"%+"' !& &@)F" +" (@' /4'8+)D&
'R!3/%'&1 :%% (@!( +& 4'CD+4'# () 4'D&' ! #!(! ('3/%!(' +" (@+& 3!""'4 +& () #'T"' (@' ('3/%!('
+" ! 4'&)D4$' $)%%'$(+)" !"# &'( ! U#8 !"#!$"%& '#" %($ %$)!*+%$, +- -(#./ ($"$0
<Window.Resources>
<DataTemplate x:Key="myTemplate">
<Label Content="{Binding Path=ContactName}" BorderBrush="Black"
Background="Yellow" BorderThickness="3" Foreground="Blue" />
</DataTemplate>
</Window.Resources>
1($/  3+/ -$% %($ %$)!*+%$ 4& "$'$""5/6 %# %($ "$-#2"3$, +- -(#./ 5/ 4#*7 ($"$0
<ListBox ItemTemplate="{StaticResource myTemplate}"
Name="ListBox1" />
!"#$%&'
!"#$%&#'()")'"*+,!)"*-'),,*).'"$'/*'.)"#*.'-0+,!*1'/*'-%.*'"#)"'2$%'#)3*'!$"-'$4',.)5"05*'
0+,!*+*6"06&')6('%-06&'"#*+7'8)")'"*+,!)"*-').*')6'*9".*+*!2',$:*.4%!'4*)"%.*'$4';<='
)6(',.$+0-*'"$'>&%.*',.$+06*6"!2'$6'"#*'*9)+7
?-06&'@$63*."*.-'"$' ,,!2'@$6(0"0$6)!'=$.+)""06&'06'8)")'A*+,!)"*-
8/$ #' %($ )#-% 2-$'2* %(5/6-  3+/ 7# .5%( 3#/9$"%$"- 5- %# +!!*& 3#/75%5#/+* '#")+%%5/6
%# 75-!*+&$7 7+%+: ;#" $<+)!*$, -2!!#-$  +"$ ."5%5/6 +/ +!!*53+%5#/ %(+% 45/7- %# + *5-% #'
7+%$- #/ .(53( #"7$"- .$"$ !*+3$7: =#2 )56(% .+/% #"7$"- %(+% .$"$ !*+3$7 5/ %($ 32""$/%
)#/%( %# (+9$ + 75''$"$/% '#"$6"#2/7 3#*#" %(+/ %($ #%($" #"7$"-: =#2 3+/ +33#)!*5-( %(5- 4&
45/75/6 %($ !"#$"!%&' !"#!$"%& #' %($ 3#/%"#* 2-$7 %# 45/7 %($ 7+%$ %# %($ ()*# >$*7 +/7
!"#9575/6 + 3#/9$"%$" %(+% $9+*2+%$- %($ 7+%$ +/7 "$%2"/- + 4"2-( #' %($ +!!"#!"5+%$ 3#*#":
1($ '#**#.5/6 $<+)!*$- -(#. -23( + 3#/9$"%$", +/ 5/-%+/3$ #' %(+% 3#/9$"%$" +77$7 %# %($
+,&'!-./#0!%"1#0 3#**$3%5#/, +/7, >/+**&, %($ !"#$"!%&' !"#!$"%& 4#2/7 %# %($ ()*# !"#!?
$"%& 2-5/6 %($ 3#/9$"%$" %# "$%2"/ + 2"%03 #4@$3%: ;5"-%, ($"$A- %($ 3#/9$"%$"0
B)+,!*'$4'C0-%)!'D)-05'@$(*
<ValueConversion(GetType(DateTime), GetType(Brush))> _
Public Class DateBrushConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
Dim aDate As DateTime
aDate = CType(value, DateTime)
If aDate.Month = Now.Month Then
Return New SolidColorBrush(Colors.Red)
Else
Return New SolidColorBrush(Colors.Black)
End If
www.it-ebooks.info
B$--#/ C0 D+/5!2*+%5/6 +/7 E5-!*+&5/6 E+%+ !"#$%&'(' )*+
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType _
As System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
B)+,!*'$4'@E'@$(*
[ValueConversion(typeof(DateTime), typeof(Brush))]
public class DateBrushConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
DateTime aDate = (DateTime)value;
if (aDate.Month == DateTime.Now.Month)
return new SolidColorBrush(Colors.Red);
else
return new SolidColorBrush(Colors.Black);
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
F/ 5/-%+/3$ 5- %($/ +77$7 %# %($ +,&'!-./#0!%"1#0 3#**$3%5#/, +- -(#./ 5/ 4#*7 ($"$0
<Window x:Class="WpfApplication5.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication5"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<local:DateBrushConverter
x:Key="myDateConverter"></local:DateBrushConverter>
</Window.Resources>
<!--- the rest of the window is omitted --!>
</Window>
;5/+**&,  3+/ 45/7 %($ !"#$"!%&' !"#!$"%& %# + 7+%$ 4& 2-5/6 %($ 3#/9$"%$", +- -(#./ 5/
4#*7 ($"$0
<ListBox Margin="60,58,98,104" Name="ListBox1">
<ListBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Path=OrderDate}" Foreground="{Binding
Path=OrderDate, Converter={StaticResource myDateConverter}}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
www.it-ebooks.info
')+, !"#$%&'( G#/>62"5/6 E+%+ H5/75/6
?-06&' !"!#$%&'!"$($'$)"*+
1($ ()*)4#567)*#8#7#1*!" 3*+-- $/+4*$-  %# +--56/ 7+%+ %$)!*+%$- 7&/+)53+**& %# 3#**$3?
%5#/ #4@$3%- 4+-$7 #/ %($ 3#/%$/% #' %($ 7+%+: ;#" $<+)!*$, 3#/-57$" %(+%  (+9$ %.# 7+%+
%$)!*+%$-, -(#./ 5/ IFDB ($"$0
<Window.Resources>
<DataTemplate x:Key="BasicTemplate">
<TextBlock Text="{Binding Path=RequiredDate}"/>
</DataTemplate>
<DataTemplate x:Key="PriorityTemplate">
<TextBlock Text="{Binding Path=RequiredDate}" Background="Red"/>
</DataTemplate>
</Window.Resources>
H#%( %$)!*+%$- 5/ %(5- $<+)!*$ +"$ J25%$ -5)!*$: 1($& $+3( 7$>/$ + %$<% 4*#3K %(+% 75-!*+&-
+ >$*7 3+**$7 L$J25"$7E+%$M5/ %(5- $<+)!*$, %($ 7+%$ +/ #"7$" 5- "$J25"$7 4& %($ 32-%#)$":
N#.$9$", 5/ %($ %$)!*+%$ 3+**$7 O"5#"5%&1$)!*+%$, %($ 4+3K6"#2/7 #' %($ %$<% 4*#3K 5- "$7:
P2!!#-$  .+/% " +!!*53+%5#/ %# $<+)5/$ %($ 9+*2$ #' %($ L$J25"$7E+%$ >$*7 +/7 2-$
O"5#"5%&1$)!*+%$ '#" #"7$"- %(+% +"$ 72$ %(5- )#/%( +/7 H+-531$)!*+%$ '#" +** #%($"-: =#2 3+/
5)!*$)$/% %(5- *#653 4& 2-5/6 %($ ()*)4#567)*#8#7#1*!" 3*+--:
()*)4#567)*#8#7#1*!" 5- +/ +4-%"+3% 3*+-- %(+% $<!#-$- + -5/6*$ )$%(#7 Q.(53( 3+/ 4$
#9$""577$/R 3+**$7 8#7#1*4#567)*#: 8#7#1*4#567)*# "$%2"/- + ()*)4#567)*# #4@$3% +/7, .($/
#9$""577$/, -(#2*7 5/3#"!#"+%$ %($ *#653 "$J25"$7 %# 7$%$")5/$ %($ 3#""$3% %$)!*+%$ 4+-$7
#/ %($ 7+%+: 1($ 8#7#1*4#567)*# )$%(#7 +33$!%- %.# !+"+)$%$"-0 +/ 9:;#1*'!+"+)$%$"'%(+%'
"$!"$-$/%- %($ #4@$3% 4#2/7 4& %($ 7+%+ %$)!*+%$, +/7 + (#6#&'#&1<9:;#1* !+"+)$%$" %(+%
"$!"$-$/%- %($ 3#/%+5/$" '#" %($ 4#2/7 #4@$3%: 1($ '#**#.5/6 $<+)!*$ -(#.- + -5)!*$ 5)!*$?
)$/%+%5#/ #' ()*)4#567)*#8#7#1*!" %(+% $<+)5/$- + >$*7 5/ + 7+%+ "#. +/7 "$%2"/- + 7+%+
%$)!*+%$ 4+-$7 #/ %($ 9+*2$ #' %(+% >$*7:
B)+,!*'$4'C0-%)!'D)-05'@$(*
Public Class DateDataTemplateSelector
Inherits DataTemplateSelector
Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As
DependencyObject) _
As DataTemplate
Dim element As FrameworkElement
element = TryCast(container, FrameworkElement)
' Tests to ensure that both the item and the container are not null, and that
' the item is of the expected data type.
If element IsNot Nothing AndAlso item IsNot Nothing AndAlso TypeOf item Is
System.Data.DataRowView Then
' Casts the item as the expected type, in this case a System.Data.
DataRowView
Dim dateitem As System.Data.DataRowView = CType(item, System.Data.
DataRowView)
' Compares the value of the expected field with the current month
If CType(dateitem("RequiredDate"), Date).Month = DateTime.Now.Month Then
' Returns the PriorityTemplate in the case of a match
Return TryCast(element.FindResource("PriorityTemplate"), DataTemplate)
www.it-ebooks.info
B$--#/ C0 D+/5!2*+%5/6 +/7 E5-!*+&5/6 E+%+ !"#$%&'(' )+-
Else
' Returns the BasicTemplate for other cases
Return TryCast(element.FindResource("BasicTemplate"), DataTemplate)
End If
End If
Return Nothing
End Function
End Class
B)+,!*'$4'@E'@$(*
public class DateDataTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
FrameworkElement element;
System.Data.DataRowView dateitem;
element = container as FrameworkElement;
// Tests to ensure that both the item and the container are not null, and that the
// item is of the expected data type.
if (element != null && item != null && item is System.Data.DataRowView)
{
// Casts the item as the expected type, in this case a System.Data.DataRowView
dateitem = (System.Data.DataRowView)item;
// Compares the value of the expected field with the current month
if (((DateTime)dateitem["RequiredDate"]).Month == DateTime.Now.Month)
// Returns the PriorityTemplate in the case of a match
return element.FindResource("PriorityTemplate") as DataTemplate;
else
// Returns the BasicTemplate for other cases
return element.FindResource("BasicTemplate") as DataTemplate;
}
return null;
}
}
F'%$"  (+9$ 3"$+%$7 " 5/($"5%$7 ()*)4#567)*#8#7#1*!" 3*+--,  3+/ 3"$+%$ +/ 5/?
-%+/3$ #' 5% 5/ " L$-#2"3$- -$3%5#/, +- -(#./ ($"$0
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication4"
Title="MainWindow" Height="350" Width="525" >
<Window.Resources>
<my:DateDataTemplateSelector x:Key="myTemplateSelector" />
</Window.Resources>
<!-- Implementation omitted -->
</Window>
F'%$"  (+9$ 7$>/$7 + ()*)4#567)*#8#7#1*!" "$-#2"3$,  3+/ +--56/ %($ "$-#2"3$ %#
%($ =*#54#567)*#8#7#1*!" !"#!$"%& #' +/ 5%$) 3#/%"#*, +- -(#./ ($"$0
<ListBox ItemTemplateSelector="{StaticResource myTemplateSelector}" />
www.it-ebooks.info
')+. !"#$%&'( G#/>62"5/6 E+%+ H5/75/6
S($/ +/ 5%$) 5- +77$7 %# %($ *5-% 4#< 5/ %(5- $<+)!*$, %($ 8#7#1*4#567)*# )$%(#7 #'
()*)4#567)*#8#7#1*!" 5- $<$32%$7 #/ %(+% 5%$), +/7 %($ +!!"#!"5+%$ %$)!*+%$ 5- "$%2"/$7 +/7
+!!*5$7 %# %($ 75-!*+& #' %(+% 5%$):
?-06&'F0*.).5#05)!'8)")'A*+,!)"*-
S($/ 75-!*+&5/6 (5$"+"3(53+* 7+%+, -23( +- 5/ + 4"##>,#- #" + ?#&% 3#/%"#*,  3+/
2-$ @,#")"13,1)7()*)4#567)*# %# !"#957$ '#")+%%5/6 +/7 *+% '#" 4#%( 5%$)- 5/ + *5-%
+/7 "$*+%$7 -24?5%$)-: 1($ @,#")"13,1)7()*)4#567)*# 3*+-- 5/3#"!#"+%$- +** %($ !"#!$"?
%5$- #' %($ ()*)4#567)*# 3*+-- +/7 -$"9$- +- %($ -%+/7+"7 7+%+ %$)!*+%$ '#" *5-% 5%$)-:
@,#")"13,1)7()*)4#567)*# +*-# 5/3#"!#"+%$- + /2)4$" #' !"#!$"%5$- %(+% +!!*& %# -24?5%$)-,
.(53( 1+4*$ T?U -2))+"5V$-:
$"/0%'(12' W%$)?L$*+%$7 O"#!$"%5$- #' @,#")"13,1)7()*)4#567)*#
#&3#%&$4 5%6 &7#$738
=*#52,&',&$A"!%6 X$%- #" -$%- %($ 2,&',&$A"!%6 !"#!$"%& %(+% 5- 3#!5$7 %#
$+3( 3(5*7 5%$)
=*#5B!&*),&#"8*<7# X$%- #" -$%- %($ 8*<7# !"#!$"%& %(+% 5- +!!*5$7 %# %($ 5%$)
3#/%+5/$" '#" $+3( 3(5*7 5%$)
=*#5B!&*),&#"8*<7#8#7#1*!" X$%- #" -$%- 32-%#) -%&*$?-$*$3%5#/ *#653 '#" + -%&*$ %(+%
3+/ 4$ +!!*5$7 %# $+3( 5%$) 3#/%+5/$"
=*#508!%"1# X$%- #" -$%- %($ 45/75/6 '#" %(5- 7+%+ %$)!*+%$, .(53(
5/753+%$- .($"$ %# >/7 %($ 3#**$3%5#/ %(+% "$!"$-$/%- %($
/$<% *$9$* 5/ %($ 7+%+ (5$"+"3(&
=*#58*",&$ !"5)* X$%- #" -$%- + 3#)!#-5%$ -%"5/6 %(+% -!$35>$- (#. %#
'#")+% %($ 5%$)- 5/ %($ /$<% *$9$* 5/ %($ 7+%+ (5$"+"3(& 5'
%($& +"$ 75-!*+&$7 +- -%"5/6-
=*#54#567)*# X$%- #" -$%- %($ 7+%+ %$)!*+%$ %# +!!*& %#
%($ =*#54#567)*# !"#!$"%& #/ + 6$/$"+%$7
@#)'#"#'=*#50B!&*"!7 3#/%"#* Q-23( +- ?#&%=*#5 #"
4"##>,#-=*#5R %# 5/753+%$ (#. %# 75-!*+& 5%$)- '"#) %($
/$<% *$9$* 5/ %($ 7+%+ (5$"+"3(&
=*#54#567)*#8#7#1*!" X$%- #" -$%- ()*)4#567)*#8#7#1*!" %# +!!*& %# %($
=*#54#567)*#8#7#1*!" !"#!$"%& #/ + 6$/$"+%$7
@#)'#"#'=*#50B!&*"!7 3#/%"#* Q-23( +- ?#&%=*#5 #"
4"##>,#-=*#5R %# 5/753+%$ (#. %# -$*$3% + %$)!*+%$ %#
75-!*+& 5%$)- '"#) %($ /$<% *$9$* 5/ %($ 7+%+ (5$"+"3(&
1($ =*#508!%"1# !"#!$"%& 5- + 45/75/6 %(+% !#5/%- %# %($ -24?5%$)- %# 4$ 75-!*+&$7 5/ %($
(5$"+"3(53+* 75-!*+&: 1($ =*#54#567)*# !"#!$"%& "$!"$-$/%- %($ 7+%+ %$)!*+%$ '#" %($ -24?
5%$)-: Y#")+**&, %(5- 5- + "$62*+" 7+%+ %$)!*+%$, 42% /#%$ %(+% -24?5%$)- 3+/ (+9$ -24?5%$)- #'
%($5" #./, 5/ .(53( 3+-$  3+/ -$% %(5- !"#!$"%& %# +/#%($" @,#")"13,1)7()*)4#567)*# 3*+--:
www.it-ebooks.info
B$--#/ C0 D+/5!2*+%5/6 +/7 E5-!*+&5/6 E+%+ !"#$%&'(' )+)
W'  .+/% %# $<+)5/$ %($ -24?5%$)- !"#6"+))+%53+**& +/7 !"#957$ 75''$"$/% 7+%+ %$)?
!*+%$- 4+-$7 #/ %($ 7+%+ 9+*2$-,  3+/ -$% %($ =*#54#567)*#8#7#1*!" !"#!$"%& %# +/ 5/-%+/3$
#' + 3*+-- 7$"595/6 '"#) ()*)4#567)*#8#7#1*!", +- 7$-3"54$7 5/ %($ !"$95#2- -$3%5#/:
1($ '#**#.5/6 IFDB 3#7$ 7$)#/-%"+%$- +/ $<+)!*$ #' @,#")"13,1)7()*)*#567)*#: W/ %(5-
$<+)!*$, + .5/7#. 7$>/$- %.# G#**$3%5#/Z5$.L$-#2"3$ #4@$3%-, .(53( "$!"$-$/% +/ FE8:
Y[1 ()*)4):7# #4@$3% +/7 + ()*)/#7)*,!& #4@$3% %(+% 7$>/$- %($ "$*+%5#/-(5! 4$%.$$/ 5% +/7
+ "$*+%$7 %+4*$: 1($ 2-$" 5/%$"'+3$ #' %($ .5/7#. 3#/%+5/- + 4"##>,#- 3#/%"#* %(+% .5** 75-!*+&
+ *5-% #' 5%$)-, $+3( #' .(53( .5** (+9$ -24?5%$)-: @,#")"13,1)7()*)4#567)*#, 5/ %(5- $<+)!*$,
5- +!!*5$7 %# %($ 5%$)- %(+% +"$ 75-!*+&$7 5/ C,0*>,#-, +/7 %($ =*#54#567)*# !"#!$"%& #'
@,#")"13,1)7()*)>,#- "$'$"- %# %($ E+%+1$)!*+%$ 3*+-- +!!*5$7 %# -24?5%$)- 5/ C,0*>,#-:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication4"
Title="MainWindow" Height="350" Width="525" >
<Window.Resources>
<!-- Creates a resource that refers to a DataSet defined in code -->
<my:NwindDataSet x:Key="NwindDataSet" />
<!-- Creates a resource that refers to the Customers table of the DataSet -->
<CollectionViewSource x:Key="CustomersViewSource" Source="{Binding
Path=Customers,
Source={StaticResource NwindDataSet}}" />
<!-- Creates a resource that refers to a DataRelation defined by the Customers
table -->
<CollectionViewSource x:Key="CustomersOrdersViewSource" Source="{Binding
Path=CustomersOrders,
Source={StaticResource CustomersViewSource}}" />
<!-- The DataTemplate that is applied to sub-items in the list view -->
<DataTemplate x:Key="BasicTemplate">
<TextBlock Text="{Binding Path=RequiredDate}"/>
</DataTemplate>
<!-- The HierarchicalDataTemplate that is applied to Listview items -->
<HierarchicalDataTemplate x:Key="HierarchTemplate" ItemsSource="{Binding
Path=CustomersOrders}"
ItemTemplate="BasicTemplate" >
<TextBlock Foreground="Red" Text="{Binding Path=CompanyName}" />
</HierarchicalDataTemplate>
</Window.Resources>
<Grid DataContext="{StaticResource CustomersViewSource}">
<TreeView Height="248" HorizontalAlignment="Left" Margin="46,39,0,0"
Name="TreeView1"
VerticalAlignment="Top" Width="394" ItemsSource="{Binding}"
ItemTemplate="{StaticResource HierarchTemplate}" />
</Grid>
</Window>
www.it-ebooks.info
')+9 !"#$%&'( G#/>62"5/6 E+%+ H5/75/6
B$."06&'8)")S($/ !"$-$/%5/6 7+%+ 5/ %($ 2-$" 5/%$"'+3$,  .+/% %# -#"% 5% 5/ 9+"5#2- .+&-: H#2/7 7+%+
3+/ 4$ -#"%$7 %("#26( %($ 7$'+2*% =B!77#1*,!&>,#- $*$)$/% '#" %($ 7+%+ *5-%: =#2 -+. !"$95#2-?
*& (#. %# #4%+5/ + "$'$"$/3$ %# %($ 7$'+2*% 3#**$3%5#/ 95$. %("#26( %($ B!77#1*,!&>,#-8!%"1#
#4@$3%, +- -(#./ +6+5/ ($"$0
B)+,!*'$4'C0-%)!'D)-05'@$(*
Dim myView As System.ComponentModel.ICollectionView
myView = CollectionViewSource.GetDefaultView(myCollection)
B)+,!*'$4'@E'@$(*
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myCollection);
=B!77#1*,!&>,#- $<!#-$- + !"#!$"%& 3+**$7 8!"*(#01",6*,!&0, .(53( 3#/%+5/- + 3#**$3%5#/ #'
8!"*(#01",6*,!& #4@$3%-: 8!"*(#01",6*,!& #4@$3%- 7$-3"54$ %($ 3#*2)/ /+)$ %# -#"% 4& +/7 +
75"$3%5#/ %(+% -!$35>$- $5%($" +/ +-3$/75/6 #" + 7$-3$/75/6 -#"% #"7$": 1($ '#**#.5/6 $<+)!*$
7$)#/-%"+%$- -#"%5/6 4& + 3#*2)/ /+)$7 B+-%Y+)$ 5/ +-3$/75/6 #"7$"0
B)+,!*'$4'C0-%)!'D)-05'@$(*
myView.SortDescriptions.Add(New _
System.ComponentModel.SortDescription("LastName", _
System.ComponentModel.ListSortDirection.Ascending)
B)+,!*'$4'@E'@$(*
myView.SortDescriptions.Add(new
System.ComponentModel.SortDescription("LastName",
System.ComponentModel.ListSortDirection.Ascending);
8!"*(#01",6*,!& #4@$3%- +"$ +!!*5$7 %# + 3#**$3%5#/ 5/ %($ #"7$" 5/ .(53( %($& +"$ +77$7
%# %($ 3#**$3%5#/ 95$.: 1(2-, 5'  .+/%$7 %# -#"% >"-% 4& %($ B+-%Y+)$ 3#*2)/ +/7 %($/ 4&
%($ ;5"-%Y+)$ 3#*2)/,  >"-% .#2*7 +77 + 8!"*(#01",6*,!& #4@$3% %(+% -!$35>$7 -#"%5/6
4& C)0*D)5# +/7 %($/ +77 + 8!"*(#01",6*,!& #4@$3% %(+% -!$35>$7 -#"%5/6 4& ,"0*D)5#, +-
-(#./ ($"$0
B)+,!*'$4'C0-%)!'D)-05'@$(*
myView.SortDescriptions.Add(New _
System.ComponentModel.SortDescription("LastName", _
System.ComponentModel.ListSortDirection.Ascending)
myView.SortDescriptions.Add(New _
System.ComponentModel.SortDescription("FirstName", _
System.ComponentModel.ListSortDirection.Ascending)
B)+,!*'$4'@E'@$(*
myView.SortDescriptions.Add(new
System.ComponentModel.SortDescription("LastName",
System.ComponentModel.ListSortDirection.Ascending);
myView.SortDescriptions.Add(new
System.ComponentModel.SortDescription("FirstName",
System.ComponentModel.ListSortDirection.Ascending);
www.it-ebooks.info
B$--#/ C0 D+/5!2*+%5/6 +/7 E5-!*+&5/6 E+%+ !"#$%&'(' )+2
,,!206&'@%-"$+'B$."06&
W'  +"$ 45/75/6 %# + 3*+-- .(#-$ 7$'+2*% 95$. 5- C,0*B!77#1*,!&>,#- Q%(+% 5-, 5% 5)!*$)$/%-
=C,0* 42% /#% =2,&',&$C,0*R, -23( +- 9:0#"E):7#B!77#1*,!&,  3+/ 5)!*$)$/% 32-%#) -#"%
#"7$"- 4& -$%%5/6 %($ C,0*B!77#1*,!&>,#-.B%0*!58!"* !"#!$"%&: 1($ B%0*!58!"* !"#!$"%& %+K$-
+/ #4@$3% %(+% 5)!*$)$/%- %($ =B!56)"#" 5/%$"'+3$: 1($ =B!56)"#" 5/%$"'+3$ "$J25"$- + -5/6*$
)$%(#7 3+**$7 B!56)"# %(+% %+K$- %.# +"62)$/%- +/7 "$%2"/- +/ 5/%$6$" %(+% "$!"$-$/%- %($
"$-2*% #' %($ 3#)!+"5-#/ #' %(#-$ %.# #4@$3%-: 1($ '#**#.5/6 $<+)!*$ 7$)#/-%"+%$- +/ 5)!*$?
)$/%+%5#/ #' %($ =B!56)"#" 5/%$"'+3$ %(+% %+K$- %.# F567!<## #4@$3%- +/7 -#"%- 4& %($ *$/6%(
#' %($ C)0*D)5# !"#!$"%&0
B)+,!*'$4'C0-%)!'D)-05'@$(*
Public Class myComparer
Implements IComparer
Public Function Compare(ByVal x As Object, ByVal y As Object) As _
Integer Implements System.Collections.IComparer.Compare
Dim empX As Employee = CType(x, Employee)
Dim empY As Employee = CType(y, Employee)
Return empX.LastName.Length.CompareTo(empY.LastName.Length)
End Function
End Class
B)+,!*'$4'@E'@$(*
public class myComparer : System.Collections.IComparer
{
public int Compare(object x, object y)
{
Employee empX = (Employee)x;
Employee empY = (Employee)y;
return empX.LastName.Length.CompareTo(empY.LastName.Length);
}
}
1($/  3+/ 3"$+%$ +/ 5/-%+/3$ #' %(5- 3*+-- %# -$% %# %($ B%0*!58!"* !"#!$"%& #' "
=B!77#1*,!&>,#- $*$)$/%, +- -(#./ ($"$0
B)+,!*'$4'C0-%)!'D)-05'@$(*
Dim myView As ListCollectionView
myView = CType(CollectionViewSource.GetDefaultView(myCollection), _
ListCollectionView)
myView.CustomSort = New myComparer()
B)+,!*'$4'@E'@$(*
System.ComponentModel.ICollectionView myView;
myView =
(ListCollectionView)CollectionViewSource.GetDefaultView(myCollection);
myView.CustomSort = new myComparer();
www.it-ebooks.info
')+: !"#$%&'( G#/>62"5/6 E+%+ H5/75/6
G.$%,06&=B!77#1*,!&>,#- +*-# -2!!#"%- 6"#2!5/6 7+%+: X"#2!5/6 7+%+ 5- -5)5*+" %# -#"%5/6 42% %+K$-
+79+/%+6$ #' %($ 425*%?5/ '2/3%5#/+*5%& #' 5%$) 3#/%"#*- %# !"#957$ '#")+%%5/6 '#" 75''$"$/%
6"#2!-, %(2- $/+4*5/6 %($ 2-$" %# 75-%5/625-( 6"#2!- 95-2+**& +% "2/ %5)$: =#2 3+/ 3"$+%$ +
6"#2! 4& +775/6 + G"!6#"*<A"!%6(#01",6*,!& #4@$3% %# %($ =B!77#1*,!&>,#-.A"!%6(#01",6*,!&0
3#**$3%5#/: 1($ '#**#.5/6 $<+)!*$ 7$)#/-%"+%$- 3"$+%5/6 6"#2!- 4+-$7 #/ %($ 9+*2$ #' %($
F567!<##4,*7# !"#!$"%&0
B)+,!*'$4'C0-%)!'D)-05'@$(*
Dim myView As System.ComponentModel.ICollectionView
myView = CollectionViewSource.GetDefaultView(myCollection)
myView.GroupDescriptions.Add( _
New PropertyGroupDescription("EmployeeTitle"))
B)+,!*'$4'@E'@$(*
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myCollection);
myView.GroupDescriptions.Add(
new PropertyGroupDescription("EmployeeTitle"));
F% >"-% 6*+/3$, +!!*&5/6 %(5- 6"#2!5/6 -$$)- %# (+9$ %($ -+)$ $''$3% +- -#"%5/6 4&
F567!<##4,*7#: 1($ 75''$"$/3$ 4$3#)$- $957$/% .($/ %(5- 7+%+ 5- 75-!*+&$7 5/ +/ 5%$) 3#/%"#*
.5%( %($ A"!%68*<7# !"#!$"%& -$%: 1($ A"!%68*<7# !"#!$"%& !"#957$- '#")+%%5/6 5/'#")+?
%5#/ '#" 6"#2!$7 5%$)- +/7 $/+4*$-  %# -$% (#. %($& +"$ 75-!*+&$7: 1+4*$ T?\ $<!*+5/- %($
!"#!$"%5$- #' %($ A"!%68*<7# #4@$3%:
$"/0%'(1:' O"#!$"%5$- #' A"!%68*<7#
#&3#%&$4 5%6 &7#$738
B!&*),&#"8*<7# X$%- #" -$%- %($ -%&*$ +!!*5$7 %# %($ X"#2!W%$) #4@$3% 6$/?
$"+%$7 '#" $+3( 5%$)
B!&*),&#"8*<7#8#7#1*!" L$!"$-$/%- +/ 5/-%+/3$ #' P%&*$P$*$3%#" %(+% 7$%$")5/$- %($
+!!"#!"5+%$ -%&*$ %# 2-$ '#" %($ 3#/%+5/$"
@#)'#"4#567)*# X$%- #" -$%- %($ %$)!*+%$ 2-$7 %# 75-!*+& %($ 6"#2! ($+7$"
@#)'#"4#567)*#8#7#1*!" L$!"$-$/%- +/ 5/-%+/3$ #' P%&*$P$*$3%#" %(+% 7$%$")5/$- %($
+!!"#!"5+%$ -%&*$ %# 2-$ '#" %($ ($+7$"
G) X$%- #" -$%- + %$)!*+%$ %(+% 3"$+%$- %($ !+/$* 2-$7 %# *+&
#2% %($ 5%$)-
1($ '#**#.5/6 $<+)!*$ 7$)#/-%"+%$- -$%%5/6 %($ A"!%6@#)'#" +/7 G) !"#!$"%5$-: W/ %(5-
$<+)!*$, %($ G) !"#!$"%& 5- "$!*+3$7 4& + +")6G) $*$)$/% %(+% 3+2-$- %($ 6"#2!- %#
."+! (#"5V#/%+**&, +/7 %($ @#)'#"4#567)*# 5- -$% %# 75-!*+& %($ ($+7$" 5/ !2"!*$ %$<% #/ + "$7
4+3K6"#2/70
<ListBox ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True"
DisplayMemberPath="ContactName" Margin="18,19,25,0" Name="listBox1"
www.it-ebooks.info
B$--#/ C0 D+/5!2*+%5/6 +/7 E5-!*+&5/6 E+%+ !"#$%&'(' )+(
Height="100" VerticalAlignment="Top">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Label Content="{Binding Path=Name}" Foreground="Purple"
Background="Red" Padding="4" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
Y#%$ %(+% 5/ %($ 7+%+ %$)!*+%$ '#" %($ A"!%68*<7#.@#)'#"4#567)*# !"#!$"%&, %($ B!&*#&*
!"#!$"%& 5- 4#2/7 %# %($ D)5# !"#!$"%&: 1(5- 5- /#% %($ D)5# !"#!$"%& #' %($ #4@$3%- 4#2/7
5/ %($ C,0*2!HI3#/%"#*, 42%, +3%2+**&, %($ D)5# !"#!$"%& #' %($ G"!6#"*<A"!%6(#01",6*,!& $*$?
)$/%: 1(2-, .($/  .+/% %($ ($+7$" %# "$]$3% %($ /+)$ #' %($ 3+%$6#"&,  +*.+&- 45/7
%# %($ D)5# !"#!$"%& "+%($" %(+/ %# %($ /+)$ #' %($ !"#!$"%&  +"$ 2-5/6 %# 6"#2! "
7+%+:
@.*)"06&'@%-"$+'G.$%,06&
W/ +775%5#/ %# 3"$+%5/6 6"#2!5/6- 4+-$7 #/ %($ 9+*2$- #' #4@$3% !"#!$"%5$-,  3+/ 3"$?
+%$ 32-%#) 6"#2!- %# +""+/6$ " 5%$)- 5/ +/ 5%$) 3#/%"#*: 1# 3"$+%$ + 32-%#) 6"#2!, 
)2-% 3"$+%$ + 3*+-- %(+% 5)!*$)$/%- %($ =>)7%#B!&E#"*#" 5/%$"'+3$, .(53( $<!#-$- %.# )$%(?
#7-0 B!&E#"* +/7 B!&E#"*2)1J: ;#" %($ !2"!#-$- #' 3"$+%5/6 32-%#) 6"#2!5/6,  /$$7 %#
!"#957$ #/*& + ^"$+*_ 5)!*$)$/%+%5#/ '#" %($ B!&E#"* )$%(#7` %($ B!&E#"*2)1J )$%(#7 .5**
/$9$" 4$ 3+**$7: 1($ B!&E#"* )$%(#7 %+K$- +/ #4@$3% +- + !+"+)$%$", .(53( .5** 4$ %($ #4@$3%
"$!"$-$/%$7 4& %($ !"#!$"%& /+)$7 5/ G"!6#"*<A"!%6(#01",6*,!&: W/ %($ B!&E#"* )$%(#7, $<?
+)5/$ %($ 9+*2$ #' %($ #4@$3%, 7$%$")5/$ .(53( 32-%#) 6"#2! 5% 4$*#/6- %#, +/7 %($/ "$%2"/
+ 9+*2$ %(+% "$!"$-$/%- %(+% 32-%#) 6"#2!: 1($ '#**#.5/6 $<+)!*$ 5- + -5)!*$ 7$)#/-%"+?
%5#/ #' %(5- 3#/3$!%: W% 5- 7$-56/$7 %# $<+)5/$ + 9+*2$ '"#) + /#$,!& !"#!$"%& +/7 7$%$")5/$
.($%($" %(+% "$65#/ 5- %($ W-*$ #' S56(%: W' 5% 5-, 5% "$%2"/- W-*$ 8' S56(% +- %($ 6"#2! ($+7$"`
#%($".5-$, 5% "$%2"/- [9$"&!*+3$ [*-$:
B)+,!*'$4'C0-%)!'D)-05'@$(*
Public Class RegionConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As _
System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.Convert
If Not value.ToString = "" Then
Dim region As String = value.ToString
www.it-ebooks.info
')+* !"#$%&'( G#/>62"5/6 E+%+ H5/75/6
If region = "Isle of Wight" Then
Return "Isle of Wight"
End If
End If
Return "Everyplace else"
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType _
As System.Type, ByVal parameter As Object, ByVal culture As _
System.Globalization.CultureInfo) As Object Implements _
System.Windows.Data.IValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
B)+,!*'$4'@E'@$(*
public class RegionGrouper : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (!(value.ToString() == ""))
{
string Region = (string)value;
if (Region == "Isle of Wight")
return "Isle of Wight";
}
return "Everyplace else";
}
public object ConvertBack(object value, Type targetType, object
parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
1($/  3+/ +77 " 32-%#) G"!6#"*<A"!%6(#01",6*,!& !+"+)$%$" 4& -!$35'&5/6 %($
/#$,!& !"#!$"%& +/7 + /$. 5/-%+/3$ #' %($ /#$,!&A"!%6#" !"#!$"%&, +- -(#./ ($"$0
B)+,!*'$4'C0-%)!'D)-05'@$(*
Dim myView As System.ComponentModel.ICollectionView
myView = CollectionViewSource.GetDefaultView(myCollection)
myView.GroupDescriptions.Add(New PropertyGroupDescription("Region", _
New RegionGrouper()))
B)+,!*'$4'@E'@$(*
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myCollection);
myView.GroupDescriptions.Add(new PropertyGroupDescription("Region",
new RegionGrouper()));
www.it-ebooks.info
B$--#/ C0 D+/5!2*+%5/6 +/7 E5-!*+&5/6 E+%+ !"#$%&'(' )++
=0!"*.06&'8)")=B!77#1*,!&>,#- (+- 425*%?5/ '2/3%5#/+*5%& %(+% $/+4*$-  %# 7$-56/+%$ + )$%(#7 %# >*%$" %($
7+%+ 5/ " 3#**$3%5#/ 95$.: 1($ =B!77#1*,!&>,#- !"#!$"%& +33$!%- + G"#',1)*# 7$*$6+%$ %(+%
-!$35>$- + H##*$+/ )$%(#7, .(53( %+K$- %($ #4@$3% '"#) %($ 3#**$3%5#/ +- +/ +"62)$/%, $<?
+)5/$- 5%, +/7 "$%2"/- 4"%# 5' %($ #4@$3% 5- 5/3*27$7 5/ %($ >*%$"$7 95$. +/7 )70# 5' %($ #4@$3%
5- $<3*27$7: 1($ '#**#.5/6 %.# $<+)!*$- 7$)#/-%"+%$ -$%%5/6 + -5)!*$ >*%$": 1($ >"-% $<+)!*$
7$)#/-%"+%$- -$%%5/6 %($ >*%$" #/ +/ =B!77#1*,!&>,#- #4@$3%, +/7 %($ -$3#/7 $<+)!*$ 7$)#/?
-%"+%$- %($ )$%(#7 %(+% 5)!*$)$/%- %(+% >*%$": 1($-$ $<+)!*$- 5/9#*9$ + 3#**$3%5#/ #' 5%$)-
/+)$7 5<=*#500
B)+,!*'$4'C0-%)!'D)-05'@$(*
Dim myView As System.ComponentModel.ICollectionView
myView = CollectionViewSource.GetDefaultView(myItems)
myView.Filter = New Predicate(Of Object)(AddressOf myFilter)
B)+,!*'$4'@E'@$(*
System.ComponentModel.ICollectionView myView;
myView = CollectionViewSource.GetDefaultView(myItems);
myView.Filter = new Predicate<object>(myFilter);
1($ /$<% $<+)!*$ -(#.- 5< ,7*#", + -5)!*$ )$%(#7 %(+% $<3*27$- +** #4@$3%- .(#-$ 4!8*",&$
)$%(#7 "$%2"/- + -%"5/6 *$/6%( #' $56(% 3(+"+3%$"- #" '$.$"0
B)+,!*'$4'C0-%)!'D)-05'@$(*
Public Function myFilter(ByVal param As Object) As Boolean
Return (param.ToString.Length > 8)
End Function
B)+,!*'$4'@E'@$(*
public bool myFilter(object param)
{
return (param.ToString().Length > 8);
}
Y#%$ %(+% %($ G"#',1)*# 7$*$6+%$ %# .(53( %($ ,7*#" !"#!$"%& 5- -$% )2-% 4$
G"#',1)*#K!:;#1*L aG"#',1)*#M9NI9:;#1*O 5/ Z5-2+* H+-53b "+%($" %(+/ + -%"#/6*& %&!$7 G"#',1)*#
7$*$6+%$ -23( +- G"#',1)*#K=*#5L. =#2 )2-% !$"'#") +/& /$3$--+"& 3+-%5/6 5/ %($ )$%(#7
%(+% 5)!*$)$/%- %($ >*%$":
=0!"*.06&' 8H7IJA'H/K*5"-
1($ >*%$"5/6 )$%(#7 7$-3"54$7 5/ %($ !"$95#2- -$3%5#/ 7#$- /#% .#"K .($/ 45/7?
5/6 %# FE8:Y[1 #4@$3%- #" +/&%5)$ %($ 2/7$"*&5/6 =B!77#1*,!&>,#- #4@$3% 5- +3%2+**& +
2,&',&$C,0*B!77#1*,!&>,#- #4@$3%: 1(5- 5- 4$3+2-$ %($ 7+%+ 3#**$3%5#/ 4#2/7 %# 5/ %(5- 95$.
+3%2+**& 5- 3#//$3%$7 %("#26( +/ FE8:Y[1 ()*)>,#- *+&$", .(53( 5)!*$)$/%- 5%- #./ >*%$"5/6
-3($)$: N#.$9$",  3+/ %+K$ +79+/%+6$ #' %($ >*%$"5/6 3+!+45*5%5$- #' ()*)>,#- 4& -$%%5/6
%($ 2,&',&$C,0*B!77#1*,!&>,#-.B%0*!5 ,7*#" !"#!$"%&: 1(5- !"#!$"%& +!!*5$- + -%"5/6?4+-$7
www.it-ebooks.info
'9,, !"#$%&'( G#/>62"5/6 E+%+ H5/75/6
$<!"$--5#/ 75"$3%*& %# %($ 2/7$"*&5/6 ()*)>,#- *+&$":I1($ >*%$" $<!"$--5#/ 5- + -%"5/6 $<!"$-?
-5#/ 5/ %($ '#**#.5/6 '#")+%0
<ColumnName> <Operator> <Value>
;#" $<+)!*$, %($ '#**#.5/6 >*%$" *5)5%- %($ "#.- "$%2"/$7 %# "#.- .(#-$ 8)&'-,13 !"#!$"%&
(+- + 9+*2$ #' cD2''+*$%%+A0
Sandwich = 'Muffaletta'
1# -$% %($ >*%$",  .#2*7 3"$+%$ %($ '#**#.5/6 3#7$0
B)+,!*'$4'C0-%)!'D)-05'@$(*
Dim myView As BindingListCollectionView
myView = CType(CollectionViewSource.GetDefaultView(myItems), _
BindingListCollectionView;
myView.CustomFilter = "Sandwich = 'Muffaletta'"
B)+,!*'$4'@E'@$(*
BindingListCollectionView myView;
myView =
(BindingListCollectionView)CollectionViewSource.GetDefaultView(myItems);
myView.CustomFilter = "Sandwich = 'Muffaletta'";
P%"5/6 *5%$"+*- '#" %($ >*%$" $<!"$--5#/ )2-% 4$ $/3*#-$7 5/ -5/6*$ J2#%$-, +- -(#./
5/ %($ !"$3$75/6 3#7$: F*%(#26( %($ 3#)!*$%$ "2*$- '#" >*%$" $<!"$--5#/- +"$ 4$&#/7
%($ -3#!$ #' %(5- *$--#/, %($& '#**#. %($ -+)$ -&/%+< +- 3#)!+"5-#/ $<!"$--5#/- '#" %($
()*)B!7%5&.IFH6"#00,!& !"#!$"%&, +/7  3+/ 95$. + 3#)!*$%$ "$'$"$/3$ 5/ %($ D53"#-#'%
"$'$"$/3$ %#!53 #' %(+% /+)$ +% 3**6PQQ50'&R.5,1"!0!N*.1!5Q#&S%0Q7,:")"<Q0<0*#5.')*)
.')*)1!7%5&.#H6"#00,!&M>8.TUO.)06H:
;<=>?' @A>?
■' ;#)"'0-'"#*'(044*.*65*'/*":**6'-$."06&'/2')',)."05%!).',.$,*."2')6('5.*)"06&'
)'&.$%,'/)-*('$6'"#)"',.$,*."2L
;<=>?' @A>?'"BCDAE
■' ;#*6'2$%'5.*)"*')'&.$%,1'2$%'#)3*')55*--'"$'"#*',+*-&(".'$'$/K*5"'5.*)"*('
4$.'"#)"'&.$%,7'M$%'5)6'-*"'06(030(%)!'"*+,!)"*-'4$.'"#*'#*)(*.')6('5$6")06*.'
)6('-%,,!2')'(044*.*6"'!)2$%"',)6*!7
!"#$%&$' #EF>G=>A'D=G@'5FGF'$AHIJFGAC
W/ %(5- *+4,  $<!+/7 #/ %($ +!!*53+%5#/  3#)!*$%$7 5/ %($ !"$95#2- *+4: =#2 +77 7+%+
%$)!*+%$- %# 75-!*+& 6"$+%$" 7$%+5* +/7 95-2+* +!!$+* %# %($ B!&*)1*D)5#0 +/7 G"!'%1*D)5#0
*5-%-:I
;<=>?' @A>?
■ ;#)"'0-'"#*'(044*.*65*'/*":**6'-$."06&'/2')',)."05%!).',.$,*."2')6('5.*)"06&'
)'&.$%,'/)-*('$6'"#)"',.$,*."2L
;<=>?' @A>?'"BCDAE
■ ;#*6'2$%'5.*)"*')'&.$%,1'2$%'#)3*')55*--'"$'"#*',+*-&(".'$'$/K*5"'5.*)"*('
4$.'"#)"'&.$%,7'M$%'5)6'-*"'06(030(%)!'"*+,!)"*-'4$.'"#*'#*)(*.')6('5$6")06*.'
)6('-%,,!2')'(044*.*6"'!)2$%"',)6*!7
www.it-ebooks.info
B$--#/ C0 D+/5!2*+%5/6 +/7 E5-!*+&5/6 E+%+ !"#$%&'(' 9,-
'('"$&)' ((06&'8)")'A*+,!)"*-
*+ 8!$/ %($ 3#)!*$%$7 -#*2%5#/ '#" B$--#/ d #' %(5- 3(+!%$" '"#) $5%($" %($ GE #" "
3#)!*$%$7 $<$"35-$: =#2 )56(% .+/% %# $<!+/7 %($ 2-$" 5/%$"'+3$ (#"5V#/%+**& +/7
5/3"$+-$ %($ .57%( #' *5-%4#<d Q'#" 3#/%+3% /+)$R +/7 *5-%4#<e Q'#" !"#723% /+)$R:
,+ W/ IFDB 95$., 7$*$%$ %($ '#**#.5/6 3#7$ '"#) %($ 7$3*+"+%5#/ '#" *5-%H#<d0
DisplayMemberPath="ContactName"
-+ W/ IFDB 95$., +77 %($ '#**#.5/6 7+%+ %$)!*+%$ +/7 -$% 5% %# %($ =*#54#567)*# !"#!$"%&
#' *5-%H#<d0
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Background="Purple" Foreground="White" BorderBrush="Red"
BorderThickness="4" Width="300">
<Label.Content>
<StackPanel HorizontalAlignment="Stretch">
<TextBlock>Company Name: </TextBlock>
<TextBlock Text="{Binding CompanyName}" />
</StackPanel>
</Label.Content>
</Label>
<Label Content="{Binding Path=ContactName}" BorderBrush="Black"
HorizontalAlignment="Stretch" Background="Yellow"
BorderThickness="3" Foreground="Blue" Width="200" />
</StackPanel>
</DataTemplate>
1(5- 7+%+ %$)!*+%$ 7#$- + *#% #' %(5/6-: W% 3"$+%$- 8*)1JG), 5/ .(53( 5- 4#2/7
%($ B!56)&<D)5# >$*7, +/7 %($/ *+&- 5% #2% -# %(+% 5% +!!$+"- %# %($ *$'% #' %($
B!&*)1*D)5# !"#!$"%& '#" %(+% 3#)!+/&: W% +*-# +77- -#)$ 3#*#"'2* fW $''$3%-:
.+ E$*$%$ %($ '#**#.5/6 3#7$ '"#) %($ 7$3*+"+%5#/ '#" *5-%H#<e0
DisplayMemberPath="ProductName"
/+ W/ IFDB 95$., -$% %($ '#**#.5/6 7+%+ %$)!*+%$ %# %($ =*#54#567)*# !"#!$"%& #'
*5-%H#<e0
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Background="Yellow" Content="{Binding Path=Quantity}"
Width="25" />
<Label Background="AliceBlue" Content="{Binding Path=ProductName}"
MinWidth="120" />
<Label Background="Red" Content="{Binding Path=ExtendedPrice}"
Width="50" />
</StackPanel>
</DataTemplate>
1(5- 7+%+ %$)!*+%$ 45/7- %# %($ V%)&*,*< +/7 FH*#&'#'G",1# >$*7-, +- .$** +- %# %($
G"!'%1*D)5# >$*7-, +/7 -$%- %($ 4+3K6"#2/7 3#*#" '#" $+3( >$*7:
www.it-ebooks.info
'9,. !"#$%&'( G#/>62"5/6 E+%+ H5/75/6
0+ O"$-- ;U %# 425*7 +/7 "2/ " +!!*53+%5#/: Y#%$ %(+% %($ 75-!*+& 5- /#. )#"$ 3#*#"?
'2* +/7 %(+% +775%5#/+* >$*7- +"$ 4#2/7 5/ %($ C,0*2!H $*$)$/%-: Y#%$ %(+% +*%(#26(
+ C):#7 #4@$3% 5/ %($ 7+%+ %$)!*+%$ '#" *5-%H#<e 5- 4#2/7 %# %($ FH*#&'#'G",1# >$*7, 5%
+!!$+"- +- + "$62*+" /2)4$" 5/-%$+7 #' 4$5/6 '#")+%%$7 +- 32""$/3&:
N*--$6'B%++).2■ E+%+ %$)!*+%$- +"$ !5$3$- #' IFDB )+"K2! %(+% -!$35'& (#. 4#2/7 7+%+ -(#2*7 4$
75-!*+&$7: 1($& $/+4*$  %# -$% %($ +!!$+"+/3$ +/7 4$(+95#" #' 4#2/7 7+%+ +-
.$** +- -!$35'& "$*+%$7 >$*7- %# 4$ 75-!*+&$7: =#2 3+/ -$% + 7+%+ %$)!*+%$ '#" +/ 5%$)
3#/%"#* 4& -$%%5/6 %($ =*#54#567)*# !"#!$"%&, +/7  3+/ -$% %($ 7+%+ %$)!*+%$ '#" +
3#/%$/% 3#/%"#* 4& -$%%5/6 %($ B!&*#&*4#567)*# !"#!$"%&:
■ =#2 3+/ +!!*& -#"%5/6 %# 7+%+ 4& +33$--5/6 %($ 7$'+2*% 3#**$3%5#/ 95$. +/7 +775/6 +
/$. -#"% 7$-3"5!%5#/ %# %($ 8!"*(#01",6*,!&0 !"#!$"%&: P%+/7+"7 -#"%5/6 $/+4*$- 
%# -#"% 4+-$7 #/ + 7+%+ >$*7 9+*2$ 5/ $5%($" +-3$/75/6 #" 7$-3$/75/6 )#7$: =#2 3+/
3"$+%$ 32-%#) -#"%- 4& 3"$+%5/6 + 3*+-- %(+% 5)!*$)$/%- =B!56)"#" +/7 -$%%5/6 5% %# %($
B%0*!58!"* !"#!$"%&:
■ =#2 3+/ 3"$+%$ 6"#2!- #' 7+%+ 4& +775/6 + /$. G"!6#"*<A"!%6(#01",6*,!& !+"+)?
$%$" %# %($ A"!%6(#01",6*,!&0 !"#!$"%& #' %($ 7$'+2*% 3#**$3%5#/ 95$.: =#2 3+/ -$% %($
($+7$" +/7 #%($" '#")+%%5/6 '#" 6"#2!- 4& -$%%5/6 %($ A"!%68*<7# !"#!$"%& #' %($ 5%$)
3#/%"#* %(+% 45/7- %($ 7+%+:
■ =#2 3+/ -!$35'& + 7$*$6+%$ %# !$"'#") >*%$"5/6 4& 3"$+%5/6 + H##*$+/ )$%(#7 %(+%
!$"'#")- %($ >*%$"5/6 +/7 -!$35'&5/6 + G"#',1)*#K!:;#1*L 7$*$6+%$ %(+% !#5/%- %# %(+%
)$%(#7: 1(5- 7#$- /#% .#"K .5%( FE8:Y[1 #4@$3%-, (#.$9$", +/7  )2-% -$% %($
B%0*!5 ,7*#" !"#!$"%& %# + >*%$" $<!"$--5#/ %# >*%$" FE8:Y[1 "$3#"7-:
N*--$6'O*30*:=#2 3+/ 2-$ %($ '#**#.5/6 J2$-%5#/- %# %$-% " K/#.*$76$ #' %($ 5/'#")+%5#/ 5/ B$--#/ C,
^D+/5!2*+%5/6 +/7 E5-!*+&5/6 E+%+:_ 1($ J2$-%5#/- +"$ +*-# +9+5*+4*$ #/ %($ 3#)!+/5#/ GE 5'
 !"$'$" %# "$95$. %($) 5/ $*$3%"#/53 '#"):
()% ' "86K%&6'
6-:*.-'"$'"#*-*'P%*-"0$6-')6('*9,!)6)"0$6-'$4':#2'*)5#')6-:*.'5#$05*'0-'5$..*5"'$.'065$.Q
.*5"').*'!$5)"*('06'"#*'R 6-:*.-S'-*5"0$6')"'"#*'*6('$4'"#*'/$$T7
*+ S(53( #' %($ '#**#.5/6 3#7$ -+)!*$- 3#""$3%*& 7$)#/-%"+%$- + 7+%+ %$)!*+%$ %(+%
45/7- %($ B!&*)1*D)5# >$*7 -$% 5/ C,0*2!Hg F--2)$ %(+% ()*)B!&*#H* 5- -$% 3#""$3%*&:
#+
<ListBox ItemsSource="{Binding}" name="ListBox1">
<DataTemplate>
<Label Content="{Binding Path=ContactName}" BorderBrush="Black"
()% "86K%&6'
6-:*.-'"$'"#*-*'P%*-"0$6-')6('*9,!)6)"0$6-'$4':#2'*)5#')6-:*.'5#$05*'0-'5$..*5"'$.'065$.Q
.*5"').*'!$5)"*('06'"#*'R 6-:*.-S'-*5"0$6')"'"#*'*6('$4'"#*'/$$T7
www.it-ebooks.info
!"#$%&'(' )*(
!" # $ % & ' (
!"#$%&'(!)*+ ,-
!"#$# %&'%() )##*) +, -# .$,-&#*) '"#/ 0+ 1,*#) +, *,20/3 4%+% -#+'##/ +"# 4%+%5
-%)# %/4 +"# 1&0#/+ %..&01%+0,/6 7/# ,8 +"# .$,-&#*) )+#*) 8$,* +"# 4088#$#/1#) 0/ 4%+%
+(.#) %+ -,+" &,1%+0,/)9 %/,+"#$ -03 .$,-&#* 0) +"# "%/4&0/3 ,8 /:&& 2%&:#) %+ #%1" &,1%+0,/6
;01$,),8+ 1%&&) +"0) %/ 0*.#4%/1# *0)*%+1"6
<#+ %/,+"#$ .$,-&#* )+#*) 8$,* .%))0/3 1,**%/4) +, +"# 4%+%-%)# %) )+$0/3)6 =/ (,:$
%..&01%+0,/> +"#)# )+$0/3) 1,*.0&# %) &,/3 %) +"# ?:,+# 0) %+ #%1" #/4 ,8 +"# )+$0/36 =8 +"#
)+$0/3 1,/+%0/) % $#8#$#/1# +, %/ :/@/,'/ 4%+%-%)# ,-A#1+> ,$ #2#/ % )(/+%B #$$,$> +"# 4%+%5
-%)# )#$2#$ '0&& +"$,' %/ #B1#.+0,/ %+ $:/ +0*# 0/)+#%4 ,8 %+ 1,*.0&# +0*#6
C=DE )+%/4) 8,$ C%/3:%3# =/+#3$%+#4 E:#$(6 C=DE 0) +"# ;01$,),8+ ),&:+0,/ +, +"#)#
.$,-&#*)> '"01" C=DE ),&2#) -( .$,2040/3 ?:#$(0/3 1%.%-0&0+0#) +, +"# 4%+%-%)#> :)0/3
)+%+#*#/+) +"%+ %$# -:0&+ 0/+, C=DE5#/%- &%/3:%3#) ):1" %) ;01$,),8+ FG %/4 H05
):%& I%)01 JKLK6 =/ %440+0,/> +"#)# ?:#$(0/3 1%.%-0&0+0#) #/%-&# (,: +, ?:#$( %&*,)+ %/(
1,&+0,/6
./01*$234'"(546*(!*"7(6*'708"4#9■ F$#%+# % C=DE ?:#$(6
+466$!6*(!*"7(6*'708"4#9*
■ C#)),/ LM N/4#$)+%/40/3 C=DE )*+
■ C#)),/ JM N)0/3 C=DE E:#$0#) ,-+
')** !"#$%&'( =/+$,4:10/3 C=DE
./012/'314'./567
<,: *:)+ "%2# ),*# :/4#$)+%/40/3 ,8 FG ,$ H0):%& I%)01 JKLK6 !"0) 1"%.+#$ $#?:0$#) ,/&( +"#
"%$4'%$# %/4 ),8+'%$# &0)+#4 %+ +"# -#30//0/3 ,8 +"0) -,,@6
!"#$%& #'
:;4!!*<$7!6$!
!74#4*0#4*10!=*6'4!0#($6*(!*>7('7*=$&#*088;('0"($!*706*'$;;4'"($!6*$?*$234'"6*
"70"*=$&*>0!"*"$*@&4#=A*B;"4#A*0!%*6$#"C* !*10!=*'0646A*=$&*1()7"*!44%*"$*#4"&#!*
"74*#46&;"6*$?*"7464*@&4#(46*06*0*'$;;4'"($!*$?*%(??4#4!"*$234'"6*"70"*'$!"0(!*$!;=*
"74*(!?$#10"($!*!44%4%D?$#*(!6"0!'4A*8$8&;0"(!)*0*)#(%*$!*"74*&64#*(!"4#?0'4*>("7*
0*6&264"*$?*"74*%0"0C*+ ,-*#40;;=*6(18;(B46*"7464*@&4#=*8#$2;416A*8#$5(%(!)*0!*
4;4)0!"A*;0!)&0)4E684'(B'*6$;&"($!C
!"#$%& #'
:;4!!*<$7!6$!
!74#4*0#4*10!=*6'4!0#($6*(!*>7('7*=$&#*088;('0"($!*706*'$;;4'"($!6*$?*$234'"6*
"70"*=$&*>0!"*"$*@&4#=A*B;"4#A*0!%*6$#"C* !*10!=*'0646A*=$&*1()7"*!44%*"$*#4"&#!*
"74*#46&;"6*$?*"7464*@&4#(46*06*0*'$;;4'"($!*$?*%(??4#4!"*$234'"6*"70"*'$!"0(!*$!;=*
"74*(!?$#10"($!*!44%4%D?$#*(!6"0!'4A*8$8&;0"(!)*0*)#(%*$!*"74*&64#*(!"4#?0'4*>("7*
0*6&264"*$?*"74*%0"0C*+ ,-*#40;;=*6(18;(B46*"7464*@&4#=*8#$2;416A*8#$5(%(!)*0!*
4;4)0!"A*;0!)&0)4E684'(B'*6$;&"($!C
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )*+
8/9917'):';7</29=>7<675'8?@A
!"0) &#)),/ )+%$+) -( .$,2040/3 %/ #B%*.&# ,8 % C=DE #B.$#))0,/ ), (,: 1%/ )## '"%+ % C=DE
#B.$#))0,/ &,,@) &0@#> %/4 ),*# ,8 +"# -%)01 )(/+%B 0) 1,2#$#4 %) '#&&6 !"0) &#)),/ %&), )",')
(,: +"# ;01$,),8+ 6DO! P$%*#',$@ 8#%+:$#) +"%+ '#$# %44#4 +, *%@# C=DE ',$@6 !"# 8#%+:$#)
1%/ -# :)#4 0/40204:%&&(> '"01" 1%/ -# :)#8:& 0/ *%/( )1#/%$0,)6
F?"4#*"7(6*;466$!A*=$&*>(;;*24*02;4*"$9
■ N)# ,-A#1+ 0/0+0%&0Q#$)6
■ =*.&#*#/+ 0*.&010+&( +(.#4 &,1%& 2%$0%-&#)6
■ F$#%+# %/,/(*,:) +(.#)6
■ F$#%+# &%*-4% #B.$#))0,/)6
■ =*.&#*#/+ #B+#/)0,/ *#+",4)6
■ N/4#$)+%/4 +"# :)# ,8 ?:#$( #B+#/)0,/ *#+",4)6
.6"(10"4%*;466$!*"(149*GH*1(!&"46
F*+ ,-*./018;4C=DE #/%-&#) (,: +, .#$8,$* ?:#$(> )#+> %/4 +$%/)8,$* ,.#$%+0,/) '0+"0/ (,:$ .$,3$%**0/3
&%/3:%3# )(/+%B6 =+ ',$@) '0+" %/( 1,&+0,/ +"%+ 0*.&#*#/+) +"# !"#$%&'()% ,$ +"# 3#/#$01
!"#$%&'()%*+, 0/+#$8%1#> ), (,: 1%/ $:/ C=DE ?:#$0#) ,/ $#&%+0,/%& 4%+%> R;C 4%+%> %/4
.&%0/ ,&4 1,&+0,/)6
S, '"%+ 1%/ (,: 4, '0+" C=DET !"# 8,&&,'0/3 0) % )0*.&# C=DE ?:#$( +"%+ $#+:$/) +"# &0)+ ,8
1,&,$) +"%+ -#30/ '0+" +"# &#++#$ I> ),$+#46
I018;4*$?*J(6&0;*K06('*L$%4
Dim colors() =
{
"Red",
"Brown",
"Orange",
"Yellow",
"Black",
"Green",
"White",
"Violet",
"Blue"
}
Dim results as IEnumerable(Of String)=From c In colors _
Where c.StartsWith("B") _
Order By c _
Select c
F?"4#*"7(6*;466$!A*=$&*>(;;*24*02;4*"$9
■ N)# ,-A#1+ 0/0+0%&0Q#$)6
■ =*.&#*#/+ 0*.&010+&( +(.#4 &,1%& 2%$0%-&#)6
■ F$#%+# %/,/(*,:) +(.#)6
■ F$#%+# &%*-4% #B.$#))0,/)6
■ =*.&#*#/+ #B+#/)0,/ *#+",4)6
■ N/4#$)+%/4 +"# :)# ,8 ?:#$( #B+#/)0,/ *#+",4)6
.6"(10"4%*;466$!*"(149*GH*1(!&"46
')*B !"#$%&'( =/+$,4:10/3 C=DE
I018;4*$?*LM*L$%4
string[] colors =
{
"Red",
"Brown",
"Orange",
"Yellow",
"Black",
"Green",
"White",
"Violet",
"Blue"
};
IEnumerable<string> results = from c in colors
where c.StartsWith("B")
orderby c
select c;
!"# U$)+ )+%+#*#/+ 0/ +"0) #B%*.&# :)#) %$$%( 0/0+0%&0Q#$ )(/+%B +, 1$#%+# %/ %$$%( ,8 )+$0/3)>
.,.:&%+#4 '0+" 2%$0,:) 1,&,$)> 8,&&,'#4 -( +"# C=DE #B.$#))0,/6 P,1:)0/3 ,/ +"# $03"+ )04# ,8
+"# #?:%&) )03/> (,: )## +"%+ +"# C=DE #B.$#))0,/ $#)#*-&#) % SEC )+%+#*#/+> -:+ +"# -&.$
1&%:)# 0) %+ +"# -#30//0/3> %/4 +"# /%)%01 1&%:)# 0) %+ +"# #/46
<,:V$# ',/4#$0/3 '"( ;01$,),8+ ',:&4 4, ):1" % +"0/36 SEC "%) -##/ %$,:/4 8,$ % &,/3
+0*#> ), '"( 404/V+ ;01$,),8+ @##. +"# )%*# 8,$*%+ SEC "%)T !"# $#%),/ 8,$ +"# 1"%/3# 0)
+"%+ ;01$,),8+ 1,:&4 /,+ .$,204# =/+#&&0S#/)# 08 0+ @#.+ +"# #B0)+0/3 SEC 1,**%/4 &%(,:+6 I(
*,20/3 +"# -&.$ 1&%:)# +, +"# -#30//0/3> (,: )+%$+ -( /%*0/3 +"# ),:$1# ,8 (,:$ 4%+%> %/4
H0):%& S+:40, 6DO! 1%/ :)# +"%+ 0/8,$*%+0,/ +, .$,204# =/+#&&0S#/)# +"$,:3" +"# $#)+ ,8 +"#
)+%+#*#/+6
=/ +"# #B%*.&# 1,4#> (,: *03"+ -# *#/+%&&( #?:%+0/3 +"# W8$,* 1 0/ 1,&,$)X '0+" %
2.&3!'04 YFG -.&%'04Z &,,.9 0+ 0)6 D,+01# +"%+ 0 0) +"# )..5 2%$0%-&# +"%+ $#8#$#/1#) ,/# 0+#*
0/ +"# ),:$1# 1,&+0,/ 8,$ #%1" ,8 +"# 0+#$%+0,/) ,8 +"# &,,.6 ["%+ 0) 0V) +(.# %/4 '"#$#
0) 0 4#1&%$#4T !"# 2%$0%-&# 1%& 0 0) 4#1&%$#4 0/ +"# -&.$ 1&%:)#> %/4 0+) +(.# 0) 0*.&010+&(
)#+ +, /1&6"7> -%)#4 ,/ +"# ),:$1# 1,&+0,/ %) %/ %$$%( ,8 /1&6"76 =8 (,:$ ),:$1# 1,&+0,/ 0)
8&&'9:6/1> '"01" 0) % 1,&+0,/ ,8 ,-A#1+)> 0V) +(.# ',:&4 -# 0*.&010+&( )#+ +, .(;%01> #2#/ 08
8&&'9:6/1 1,/+%0/#4 ,/&( )+$0/3)6 C0@# +"# 2.&3!'04 &,,.> (,: 1%/ )#+ +"# +(.# 8,$ 0 #B.&010+&( %)
'#&&> %/4 #%1" #&#*#/+ '0&& -# 1%)+ +, +"%+ +(.# '"#/ -#0/3 %))03/#4 +, 0 %) 8,&&,')M
I018;4*$?*J(6&0;*K06('*L$%4
From c As String In colors _
I018;4*$?*LM*L$%4
from string c in colors
=/ +"0) #B%*.&#> +"# ),:$1# 1,&+0,/ 0) +(.#4> *#%/0/3 0+ 0) %/ %$$%( ,8 /1&6"7> ), +"#$# 0)
/, /##4 +, ).#108( +"# +(.# 8,$ 0 -#1%:)# +"# 1,*.0&#$ 1%/ U3:$# +"0) ,:+6
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )*C
!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# ,/ +"# ?:#$( ,-A#1+> -:+ 08 (,: 0+#$%+# ,/
+"# ?:#$( ,-A#1+ *:&+0.&# +0*#)> (,: %11#)) +"# 4%+% ),:$1# #%1" +0*#6 P,$ #B%*.&#> 0/ +"#
C=DE 1,4# #B%*.&#> % 2%$0%-&# 1%& &%/#)1/ '%) 1$#%+#4 +, $#+$0#2# %&& 1,&,$) +"%+ )+%$+ '0+" I>
),$+#46 =/ +"0) #B%*.&#> 1,4# 0) %44#4 +, &,,. ,2#$ +"# &%/#)1/ 2%$0%-&# %/4 40).&%( #%1" 1,&,$6
I&%1@ 0/ +"# ,$030/%& ),:$1# 4%+% 0) 1"%/3#4 +, S&%+#6 !"#/ 1,4# 0) %44#4 +, &,,. ,2#$ +"#
$#):&+) %3%0/ %/4 40).&%( #%1" 1,&,$6
I018;4*$?*J(6&0;*K06('*L$%4
For Each Color As String In results
txtLog.AppendText(Color + Environment.NewLine)
Next
')*D !"#$%&'( =/+$,4:10/3 C=DE
colors(4) = "Slate"
txtLog.AppendText("---------" + Environment.NewLine)
For Each Color As String In results
txtLog.AppendText(Color + Environment.NewLine)
Next
I018;4*$?*LM*L$%4
foreach (var color in results)
{
txtLog.AppendText(color + Environment.NewLine);
}
colors[4] = "Slate";
txtLog.AppendText("---------" + Environment.NewLine);
foreach (var color in results)
{
txtLog.AppendText(color + Environment.NewLine);
}
!"# )#1,/4 +0*# +"# &%/#)1/ 2%$0%-&# '%) :)#4> 0+ 40).&%(#4 ,/&( I&:# %/4 I$,'/> /,+ +"#
,$030/%& +"$## *%+1"0/3 1,&,$) YI&%1@> I&:#> %/4 I$,'/Z> -#1%:)# +"# ?:#$( '%) $#5#B#1:+#4
8,$ +"# )#1,/4 &,,. ,/ +"# :.4%+#4 1,&+0,/ 0/ '"01" I&%1@ '%) $#.&%1#4 -( % 1,&,$ +"%+
4,#) /,+ *%+1" +"# ?:#$( 1$0+#$0%6 ["#/#2#$ (,: :)# +"# &%/#)1/ 2%$0%-&# +, &,,. ,2#$ +"#
$#):&+)> +"# ?:#$( $#5#B#1:+#) ,/ +"# )%*# 4%+% ),:$1# +"%+ *03"+ "%2# -##/ 1"%/3#4 %/4>
+"#$#8,$#> *03"+ $#+:$/ :.4%+#4 4%+%6
<,: *03"+ -# +"0/@0/3 ,8 ",' +"%+ #88#1+) +"# .#$8,$*%/1# ,8 (,:$ %..&01%+0,/6 F#$+%0/&(>
.#$8,$*%/1# 0) ),*#+"0/3 +"%+ *:)+ -# 1,/)04#$#4 '"#/ 4#2#&,.0/3 %/ %..&01%+0,/6 _,'5
#2#$> (,: *03"+ -# )##0/3 +"# -#/#U+ ,8 $#+$0#20/3 :.5+,54%+# 4%+%> '"01" 0) +"# .:$.,)# ,8
4#8#$$#4 #B#1:+0,/6 P,$ :)#$) '", 4,/V+ '%/+ +, $#5$:/ +"# ?:#$( #2#$( +0*#> :)# +"# $#):&+5
0/3 ?:#$( ,-A#1+ +, .$,4:1# % 3#/#$01 &0)+ 0**#40%+#&( +"%+ (,: 1%/ :)# $#.#%+#4&( %8+#$'%$46
!"# 8,&&,'0/3 1,4# )%*.&# )",') ",' +, 1$#%+# % 8$,Q#/ &0)+6
I018;4*$?*J(6&0;*K06('*L$%4
Dim results As List(Of String) = (From c In colors _
Where c.StartsWith("B") _
Order By c _
Select c).ToList()
For Each Color As String In results
txtLog.AppendText(Color + Environment.NewLine)
Next
colors(4) = "Slate"
txtLog.AppendText("---------" + Environment.NewLine)
For Each Color As String In results
txtLog.AppendText(Color + Environment.NewLine)
Next
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )*E
I018;4*$?*LM*L$%4
List<string> results = (from string c in colors
where c.StartsWith("B")
orderby c
select c).ToList();
foreach (var color in results)
{
txtLog.AppendText(color + Environment.NewLine);
}
colors[4] = "Slate";
txtLog.AppendText("---------" + Environment.NewLine);
foreach (var color in results)
{
txtLog.AppendText(color + Environment.NewLine);
}
=/ +"0) 1,4# #B%*.&#> +"# $#):&+ ,8 +"# C=DE ?:#$( 0) 8$,Q#/ -( '$%..0/3 +"# #B.$#))0,/
0/ .%$#/+"#)#) %/4 %440/3 +"# +.:6/1AE 1%&& +, +"# #/46 !"# &%/#)1/ 2%$0%-&# /,' "%) % +(.#
,8 :6/13>-3@1&6"76 !"# +.:6/1 *#+",4 1%:)#) +"# ?:#$( +, #B#1:+# %/4 .:+ +"# $#):&+) 0/+, +"#
2%$0%-&# 1%& &%/#)1/9 +"#/ +"# &%/#)1/ 1,&+0,/ 1%/ -# :)#4 %3%0/ '0+",:+ $#5#B#1:+0/3 +"#
C=DE #B.$#))0,/6
+ ,-*P#$5(%4#6=/ +"# .$#20,:) #B%*.&#)> (,: 1%/ )## +"%+ C=DE ',$@) '0+" 6DO! P$%*#',$@ ,-A#1+) -#5
1%:)# +"# 6DO! P$%*#',$@ 1,*#) '0+" % : KM31.3>(;%01/ .$,204#$6 P03:$# `5L )",') +"# C=DE
.$,204#$) +"%+ %$# -:0&+ 0/+, +"# 6DO! P$%*#',$@6 O%1" C=DE .$,204#$ 0*.&#*#/+) 8#%+:$#)
8,1:)#4 ,/ +"# 4%+% ),:$1#6
LINQ Providers
LINQ toObjects
LINQ toDataSets
LINQ toSQL
LINQ toEntities
LINQ toXML
LINQ Enabled ADO.NET
F?G;&%'(H)' !"0) 803:$# )",') +"# C=DE .$,204#$) -:0&+ 0/+, +"# 6DO! P$%*#',$@6
!"# C=DE .$,204#$ ',$@) %) % *044&# +0#$ -#+'##/ +"# 4%+% )+,$# %/4 +"# &%/3:%3# #/205
$,/*#/+6 =/ %440+0,/ +, +"# C=DE .$,204#$) 0/1&:4#4 0/ +"# 6DO! P$%*#',$@> +"#$# %$# *%/(
+"0$45.%$+( C=DE .$,204#$)6 !, 1$#%+# % C=DE .$,204#$> (,: *:)+ 0*.&#*#/+ +"# M#%&9'()%
0/+#$8%1#6 !"0) "%) % N&.F6=%& .$,.#$+( '",)# +(.# 0) M#%&9N&.F6=%&> '"01" 0) 1%& +, 0/0+0%&5
0Q# %/4 #B#1:+# C=DE #B.$#))0,/)6
')+- !"#$%&'( =/+$,4:10/3 C=DE
O40".*Q70"*R0S4*T8*+ ,-D,' +"%+ (,:V2# )##/ % C=DE #B.$#))0,/> 0+V) +0*# +, )## '"%+ '%) %44#4 +, +"# 6DO!
P$%*#',$@ +, 1$#%+# C=DE6 O%1" ,8 +"#)# 8#%+:$#) 1%/ -# :)#4 -( 0+)#&8> -:+ %&& ,8 +"#* %$#
$#?:0$#4 +, 1$#%+# C=DE6
U234'"* !("(0;(V4#6
<,: 1%/ :)# ,-A#1+ 0/0+0%&0Q#$) +, 0/0+0%&0Q# %/( ,$ %&& ,8 %/ ,-A#1+V) .$,.#$+0#) 0/ +"# )%*#
)+%+#*#/+ +"%+ 0/)+%/+0%+#) +"# ,-A#1+> -:+ (,:V$# /,+ 8,$1#4 +, '$0+# 1:)+,* 1,/)+$:1+,$)6
<,: *03"+ "%2# )##/ 1&%))#) +"%+ "%2# *%/( 1,/)+$:1+,$) -#1%:)# +"# 4#2#&,.#$ '%)
+$(0/3 +, .$,204# % )0*.&# '%( +, 0/)+%/+0%+# %/4 0/0+0%&0Q# +"# ,-A#1+6 !, :/4#$)+%/4 +"0)> 1,/5
)04#$ +"# 8,&&,'0/3 1,4# #B%*.&# ,8 % I'& 1&%)) +"%+ "%) U2# %:+,*%+01 .$,.#$+0#) -:+ 4,#)/V+
"%2# %/( 1:)+,* 1,/)+$:1+,$)6
I018;4*$?*J(6&0;*K06('*L$%4
Public Class Car
Public Property VIN() As String
Public Property Make() As String
Public Property Model() As String
Public Property Year() As Integer
Public Property Color() As String
End Class
I018;4*$?*LM*L$%4
public class Car
{
public string VIN { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
}
!, 0/)+%/+0%+# % I'& ,-A#1+ %/4 .,.:&%+# +"# .$,.#$+0#) '0+" 4%+%> (,: *03"+ 4, ),*#+"0/3
&0@# +"# 8,&&,'0/3M
I018;4*$?*J(6&0;*K06('*L$%4
Dim c As New Car()
c.VIN = "ABC123"
c.Make = "Ford"
c.Model = "F-250"
c.Year = 2000
I018;4*$?*LM*L$%4
Car c = new Car();
c.VIN = "ABC123";
c.Make = "Ford";
c.Model = "F-250";
c.Year = 2000;
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )+)
=+ +,,@ U2# )+%+#*#/+) +, 1$#%+# %/4 0/0+0%&0Q# +"# ,-A#1+> %/4 I.).& '%)/V+ 0/0+0%&0Q#46 =8 %
1,/)+$:1+,$ '%) .$,204#4> (,: 1,:&4 0/)+%/+0%+# +"# ,-A#1+ %/4 0*.&010+&( 0/0+0%&0Q# +"# .$,.#$5
+0#) '0+" ,/# )+%+#*#/+> -:+ '"%+ ',:&4 (,: 4, 08 ),*#,/# '%/+#4 +, .%)) ,/&( +"$## .%$%*5
#+#$)T _,' %-,:+ .%))0/3 U2# .%$%*#+#$)T a, (,: 1$#%+# 1,/)+$:1+,$) 8,$ #2#$( 1,*-0/%+0,/
,8 .%$%*#+#$) (,: *03"+ '%/+ +, .%))T !"# %/)'#$ 0) +, :)# ,-A#1+ 0/0+0%&0Q#$)6
I( :)0/3 ,-A#1+ 0/0+0%&0Q#$)> (,: 1%/ 0/)+%/+0%+# +"# ,-A#1+ %/4 0/0+0%&0Q# %/( 1,*-0/%+0,/ ,8
.$,.#$+0#) '0+" ,/# )+%+#*#/+> %) )",'/ 0/ +"# 8,&&,'0/3 #B%*.&#M
I018;4*$?*J(6&0;*K06('*L$%4
Dim c As New Car() With {.VIN = "ABC123", .Make = "Ford", _
.Model = "F-250", .Year = 2000}
I018;4*$?*LM*L$%4
Car c = new Car() { VIN = "ABC123", Make = "Ford",
Model = "F-250", Year = 2000 };
F,/1#.+:%&&(> +"# I'& ,-A#1+ 0) -#0/3 0/)+%/+0%+#4> %/4 +"# 4#8%:&+ 1,/)+$:1+,$ 3#/#$%+#4
-( +"# 1,*.0&#$ 0) #B#1:+#46 O%1" ,8 +"# .$,.#$+0#) '0&& -# 0/0+0%&0Q#4 '0+" 0+) 4#8%:&+ 2%&:#6 =8
(,: %$# :)0/3 % .%$%*#+#$&#)) 1,/)+$:1+,$> %) )",'/> +"# .%$#/+"#)#) %$# ,.+0,/%&> -:+ 08 (,:
%$# #B#1:+0/3 % 1,/)+$:1+,$ +"%+ $#?:0$#) .%$%*#+#$)> +"# .%$#/+"#)#) %$# *%/4%+,$(6
F,&+0,/ 0/0+0%&0Q#$) %$# %/,+"#$ 8,$* ,8 ,-A#1+ 0/0+0%&0Q#$> -:+ 8,$ 1,&+0,/)6 F,&+0,/
0/0+0%&0Q#$) "%2# #B0)+#4 8,$ %$$%() )0/1# +"# U$)+ $#&#%)# ,8 +"# 6DO! P$%*#',$@> -:+ (,: 1%/
/,' 0/0+0%&0Q# 1,&+0,/) ):1" %) 8&&'9:6/1 %/4 3#/#$01 :6/1 :)0/3 +"# )%*# )(/+%B6 !"# 8,&5
&,'0/3 #B%*.&# .,.:&%+#) % 1,&+0,/ ,8 1%$)> :)0/3 -,+" ,-A#1+ 0/0+0%&0Q#$) %/4 1,&+0,/
0/0+0%&0Q#$)6
I018;4*$?*J(6&0;*K06('*L$%4
Private Function GetCars() As List(Of Car)
Return New List(Of Car) From
{
New Car() With {.VIN = "ABC123", .Make = "Ford",
.Model = "F-250", .Year = 2000},
New Car() With {.VIN = "DEF123", .Make = "BMW",
.Model = "Z-3", .Year = 2005},
New Car() With {.VIN = "ABC456", .Make = "Audi",
.Model = "TT", .Year = 2008},
New Car() With {.VIN = "HIJ123", .Make = "VW",
.Model = "Bug", .Year = 1956},
New Car() With {.VIN = "DEF456", .Make = "Ford",
.Model = "F-150", .Year = 1998}
}
End Function
I018;4*$?*LM*L$%4
private List<Car> GetCars()
{
return new List<Car>
{
new Car {VIN = "ABC123",Make = "Ford",
')+, !"#$%&'( =/+$,4:10/3 C=DE
Model = "F-250", Year = 2000},
new Car {VIN = "DEF123",Make = "BMW",
Model = "Z-3", Year = 2005},
new Car {VIN = "ABC456",Make = "Audi",
Model = "TT", Year = 2008},
new Car {VIN = "HIJ123",Make = "VW",
Model = "Bug", Year = 1956},
new Car {VIN = "DEF456",Make = "Ford",
Model = "F-150", Year = 1998}
};
}
!"# 1,4# #B%*.&# 1$#%+#) % 3#/#$01 :6/1 ,-A#1+ %/4 .,.:&%+#) +"# &0)+ '0+" U2# 1%$)> %&& 0/
,/# )+%+#*#/+6 D, 2%$0%-&#) %$# /##4#4 +, )#+ +"# .$,.#$+0#) ,8 #%1" 1%$ -#1%:)# 0+V) -#0/3
0/0+0%&0Q#46
_,' %$# ,-A#1+ 0/0+0%&0Q#$) :)#4 0/ C=DET !"#( #/%-&# (,: +, 1$#%+# ),*# +(.#) ,8 .$,5
A#1+0,/) 0/ C=DE6 ] 5&.;%016." 0) % )"%.0/3 ,$ +$%/)8,$*%+0,/ ,8 +"# 4%+% 0/ % C=DE ?:#$( +,
.$,4:1# '"%+ (,: /##4 0/ +"# ,:+.:+ '0+" +"# /%)%01 )+%+#*#/+ 0/)+#%4 ,8 0/1&:40/3 A:)+ +"#
'",&# ),:$1# ,-A#1+Y)Z6 P,$ #B%*.&#> 08 (,: '%/+ +, '$0+# % C=DE ?:#$( +"%+ '0&& )#%$1" % 1,&,$
&0)+ 8,$ %&& +"# 1,&,$ /%*#) +"%+ %$# U2# 1"%$%1+#$) &,/3> ),$+#4 -( +"# *%+1"0/3 1,&,$> 0/)+#%4
,8 $#+:$/0/3 %/ !"#$%&'()% ,-A#1+ ,8 /1&6"7> (,: *03"+ :)# ,-A#1+ 0/0+0%&0Q#$) +, $#+:$/ %/
!"#$%&'()% ,-A#1+ ,8 I'& 0/ '"01" +"# 1%$V) 1,&,$ 0) )#+ +, +"# *%+1"0/3 1,&,$> %) )",'/ "#$#M
I018;4*$?*J(6&0;*K06('*L$%4
Dim colors() =
{
"Red",
"Brown",
"Orange",
"Yellow",
"Black",
"Green",
"White",
"Violet",
"Blue"
}
Dim fords As IEnumerable(Of Car) = From c In colors
Where c.Length = 5
Order By c
Select New Car() With
{.Make = "Ford",
.Color = c}
For Each car As Car In fords
txtLog.AppendText(String.Format("Car: Make:{0} Color:{1}" _
& Environment.NewLine, car.Make, car.Color))
Next
I018;4*$?*LM*L$%4
string[] colors =
{
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )+(
"Red",
"Brown",
"Orange",
"Yellow",
"Black",
"Green",
"White",
"Violet",
"Blue"
};
IEnumerable<Car> fords = from c in colors
where c.Length == 5
orderby c
select new Car()
{
Make = "Ford",
Color = c
};
foreach (Car car in fords)
{
txtLog.AppendText(String.Format("Car: Make:{0} Color:{1}"
+ Environment.NewLine, car.Make, car.Color));
}
!"# '",&# 04#% -#"0/4 +"0) #B%*.&# 0) +"%+ (,: '%/+ +, 1,/)+$:1+ % 1,&+0,/ ,8 1%$)>
-:+ #%1" 1%$ '0&& "%2# % 1,&,$ 8$,* +"# 1,&+0,/ ,8 1,&,$) +"%+ *%+1"#) +"# U2#5&#++#$5&,/3
1$0+#$0,/6 !"# /%)%01 1&%:)# 1$#%+#) +"# I'& ,-A#1+ %/4 0/0+0%&0Q#) 0+) .$,.#$+0#)6 !"# /%)%01
1&%:)# 1%//,+ 1,/+%0/ *:&+0.&# )+%+#*#/+)6 [0+",:+ ,-A#1+ 0/0+0%&0Q#$)> (,: ',:&4/V+ -# %-&# +,
0/)+%/+0%+# %/4 0/0+0%&0Q# +"# I'& ,-A#1+ '0+",:+ U$)+ '$0+0/3 % 1,/)+$:1+,$ 8,$ +"# I'& 1&%)) +"%+
+%@#) J'O% %/4 I.).& .%$%*#+#$)6
18;('("*Q=84%*+$'0;*J0#(02;4*N4';0#0"($!6
a,#)/V+ 0+ )##* &0@# % 1",$# +, 4#1&%$# % 2%$0%-&# %) % ).#10U1 +(.# %/4 +"#/ 0/)+%/+0%+# +"%+
+(.# 0/ ,/# )+%+#*#/+T <,: "%2# +, ).#108( +"# +(.# +'01#> %) )",'/ 0/ +"# 8,&&,'0/3 #B%*.&#M
I018;4*$?*J(6&0;*K06('*L$%4
Dim c as Car = New Car( )
I018;4*$?*LM*L$%4
Car c = new Car( )
H0):%& I%)01 :)#$) *03"+ )",:+> W_#(> H0):%& I%)01 4,#)/V+ $#?:0$# *# +, ).#108( +"# +(.#
+'01#bX I:+ '"%+ %-,:+ +"# #B%*.&# 0/ '"01" (,: *%@# % 1%&& +, % *#+",4 +"%+ $#+:$/) %
3#/#$01 :6/13>- I'&> -:+ (,: )+0&& "%2# +, ).#108( +"# +(.# 8,$ +"# 2%$0%-&# +"%+ $#1#02#) +"# 1,&5
+0,/> %) )",'/ "#$#T
I018;4*$?*J(6&0;*K06('*L$%4
Dim cars As List(Of Car) = GetCars()
')+* !"#$%&'( =/+$,4:10/3 C=DE
I018;4*$?*LM*L$%4
List<Car> cars = GetCars();
=/ +"0) #B%*.&#> ',:&4 0+ -# -#++#$ 08 (,: 1,:&4 %)@ +"# 1,*.0&#$ '"%+ +"# +(.# 0) 8,$ +"0)
2%$0%-&# 1%& 0'&/T <,: 1%/> %) )",'/ 0/ +"0) 1,4# #B%*.&#M
I018;4*$?*J(6&0;*K06('*L$%4
Dim cars = GetCars()
I018;4*$?*LM*L$%4
var cars = GetCars();
=/)+#%4 ,8 .$,2040/3 +"# +(.# 8,$ (,:$ 2%$0%-&#> (,:V$# %)@0/3 +"# 1,*.0&#$ '"%+ +"# +(.# 0)>
-%)#4 ,/ '"%+#2#$ 0) ,/ +"# $03"+ )04# ,8 +"# #?:%&) )03/6 !"%+ *#%/) +"#$# *:)+ -# %/ #?:%&)
)03/ 0/ +"# 4#1&%$%+0,/ )+%+#*#/+> %/4 +"# $03"+ )04# *:)+ #2%&:%+# +, % +(.#4 #B.$#))0,/6 <,:
1%//,+ "%2# % /:&& 1,/)+%/+ ,/ +"# $03"+ )04# ,8 +"# #?:%&) )03/ -#1%:)# +"# 1,*.0&#$ ',:&4
/,+ @/,' '"%+ +"# +(.# )",:&4 -#6
=8 (,:V$# ',/4#$0/3 '"#+"#$ +"0) 0) +"# )%*# %) +"# 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% /#' +(.# A:)+ 8,$ ),*#+"0/3
+"%+ *03"+ -# :)#4 0/ ,/# *#+",46 !, :/4#$)+%/4 +"# .$,-&#* +"%+ %/,/(*,:) +(.#) ),&2#)>
0*%30/# +"%+ (,: %$# '$0+0/3 +"# 3$%."01%& :)#$ 0/+#$8%1# YcN=Z 8,$ (,:$ %..&01%+0,/> %/4 % 1,&5
+0,/ ,8 1%$) 0) .%))#4 +, (,: 0/ '"01" #%1" 1%$ "%) *%/( .$,.#$+0#)6 =8 (,: -0/4 +"# 1,&
+0,/ 40$#1+&( +, % 4%+% 3$04> (,:V&& )## %&& +"# .$,.#$+0#)> -:+ (,: /##4#4 +, 40).&%( ,/&( +', ,8
+"# .$,.#$+0#)> ), +"%+ %:+,*%+01 -0/40/3 0) 40).&%(0/3 *,$# 4%+% +"%/ (,: '%/+6 !"0) 0) '"#/
%/,/(*,:) +(.#) 1%/ -# :)#46
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )++
=/ +"# 8,&&,'0/3 1,4# )%*.&#> (,: '%/+ +, 1$#%+# %/ %/,/(*,:) +(.# +"%+ 1,/+%0/) ,/&(
J'O% %/4 J.=%) .$,.#$+0#) -#1%:)# +"#)# %$# +"# ,/&( .$,.#$+0#) (,: /##46
I018;4*$?*J(6&0;*K06('*L$%4
Dim x = New With {.Make = "VW", .Model = "Bug"}
txtLog.AppendText(x.Make & ", " & x.Model)
I018;4*$?*LM*L$%4
var x = new {Make = "VW", Model = "Bug"};
txtLog.AppendText(x.Make + ", " + x.Model);
=8 (,: +(.# 0/ +"0) 1,4#> (,: )## +"%+ 0/ +"# )#1,/4 )+%+#*#/+> '"#/ B 0) +(.#4 %/4 (,:
.$#)) +"# .#$0,4 @#(> +"# =/+#&&0S#/)# '0/4,' 0) 40).&%(#4 %/4 (,: )## J'O% %/4 J.=%) %)
%2%0&%-&# )#+0,/)6 !"# 2%$0%-&# 1%& G 0) 0*.&010+&( +(.#4 -#1%:)# (,: )0*.&( 4,/V+ @/,'
'"%+ +"# /%*# ,8 +"# %/,/(*,:) +(.# 0)6 !"# 1,*.0&#$> ",'#2#$> 4,#) @/,' +"# /%*# ,8 +"#
%/,/(*,:) +(.#6 !"0) 0) +"# -#/#U+ ,8 3#++0/3 =/+#&&0S#/)# 8,$ )1#/%$0,) 0/ '"01" 0*.&010+&(
+(.#4 &,1%& 2%$0%-&#) %$# $#?:0$#46
]/,/(*,:) +(.#) %$# :)#4 0/ C=DE +, .$,204# .$,A#1+0,/)6 <,: *03"+ *%@# % 1%&& +,
% *#+",4 +"%+ $#+:$/) % &0)+ ,8 1%$)> -:+ 8$,* +"%+ &0)+> (,: '%/+ +, $:/ % C=DE ?:#$( +"%+
$#+$0#2#) +"# H=D %) ,/# .$,.#$+( %/4 *%@# %/4 (#%$ 1,*-0/#4 0/+, % 4088#$#/+ .$,.#$+( 8,$
40).&%(0/3 0/ % 3$046 ]/,/(*,:) +(.#) "#&.> %) )",'/ 0/ +"0) #B%*.&#M
I018;4*$?*J(6&0;*K06('*L$%4
Dim carData = From c In GetCars()
Where c.Year >= 2000
Order By c.Year
Select New With
{
c.VIN,
.MakeAndModel = c.Make + " " + c.Model
}
dgResults.DataSource = carData.ToList()
I018;4*$?*LM*L$%4
var carData = from c in GetCars()
where c.Year >= 2000
orderby c.Year
select new
{
c.VIN,
MakeAndModel = c.Make + " " + c.Model
};
dgResults.DataSource = carData.ToList();
["#/ +"0) #B%*.&# 0) #B#1:+#4> +"# C=DE ?:#$( '0&& &,1%+# %&& +"# 1%$) +"%+ "%2# % P%'&
.$,.#$+( #?:%& +, ,$ 3$#%+#$ +"%/ JKKK6 !"0) '0&& $#):&+ 0/ U/40/3 +"$## 1%$) +"%+ %$# ),$+#4 -(
(#%$6 !"%+ $#):&+ 0) +"#/ .$,A#1+#4 +, %/ %/,/(*,:) +(.# +"%+ 3$%-) +"# H=D %/4 1,*-0/#) +"#
')+B !"#$%&'( =/+$,4:10/3 C=DE
*%@# %/4 *,4#& 0/+, % /#' .$,.#$+( 1%& J'O%8"=J.=%)6 P0/%&&(> +"# $#):&+ 0) 40).&%(#4 0/
+"# 3$04> %) )",'/ 0/ P03:$# `5J6
F?G;&%'(H,' ]/,/(*,:) +(.#) %$# 40).&%(#4 0/ +"# 3$046
+012%0*./8#466($!6
C%*-4% #B.$#))0,/) 1%/ -# :)#4 %/('"#$# 4#%+#) %$# $#?:0$#46 !"#( %$# 2#$( *:1" &0@#
%/,/(*,:) *#+",4) -:+ "%2# % *:1" %--$#20%+#4 )(/+%B +"%+ *%@#) +"#* #%)( +, :)# 0/&0/#6
F,/)04#$ +"# 3#/#$01 :6/1 1&%)) +"%+ "%) % 26"= *#+",46 !"0) *#+",4 %11#.+) % 3#/#$01
N&%=60'1% 4#%+# %) % .%$%*#+#$6 =8 (,: &,,@ :. +"# 3#/#$01 N&%=60'1% 4#%+# +(.#> (,:
U/4 +"%+ +"0) 4#%+# 0) % $#8#$#/1# +, % *#+",4 +"%+ %11#.+) % )0/3&# .%$%*#+#$ ,8 +(.# +
%/4 $#+:$/) % I,,&#%/ 2%&:#6 !"# 26"= *#+",4 "%) 1,4# +"%+ &,,.) +",:3" +"# &0)+ %/4> 8,$
#%1" 0+#*> +"# 1,4# #B#1:+#) +"# *#+",4 $#8#$#/1#4 +"$,:3" +"# N&%=60'1% .%$%*#+#$> .%))5
0/3 +"# 0+#* +, +"# *#+",4 %/4 $#1#020/3 % $#).,/)# +"%+ 0/401%+#) 8,:/4 ,$ /,+ 8,:/46 _#$#
0) %/ #B%*.&# ,8 :)0/3 +"# 26"= *#+",4 '0+" % N&%=60'1% 4#%+#M
I018;4*$?*J(6&0;*K06('*L$%4
Dim yearToFind As Integer
Private Sub PredecateDelegateToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles PredecateDelegateToolStripMenuItem.Click
yearToFind = 2000
Dim cars = GetCars()
Dim found = cars.Find(AddressOf ByYear)
txtLog.AppendText(String.Format( _
"Car VIN:{0} Make:{1} Year:{2}" & Environment.NewLine, _
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )+C
found.VIN, found.Make, found.Year))
End Sub
Private Function ByYear(ByVal c As Car) As Boolean
Return c.Year = yearToFind
End Function
I018;4*$?*LM*L$%4
int yearToFind = 2000;
private void predecateDelegateToolStripMenuItem_Click(
object sender, EventArgs e)
{
var cars = GetCars();
yearToFind = 2000;
var found = cars.Find(ByYear);
txtLog.AppendText(string.Format(
"Car VIN:{0} Make:{1} Year{2}" + Environment.NewLine,
found.VIN, found.Make, found.Year));
}
private bool ByYear(Car c)
{
return c.Year == yearToFind;
}
=/ +"0) #B%*.&#> +"# 9%'&+.26"= 2%$0%-&# 0) 4#U/#4 %+ +"# 1&%)) #& +, *%@# 0+ %11#))0-&# +,
-,+" *#+",4)6 !"%+V) +(.01%&&( /,+ 4#)0$%-&# -#1%:)# 9%'&+.26"= 0) *,$# &0@# % .%$%*#+#$ +"%+
/##4) +, -# .%))#4 +, +"# Q9P%'& *#+",46 !"# .$,-&#* 0) +"%+ +"# N&%=60'1% 4#%+# %11#.+)
,/&( ,/# .%$%*#+#$> %/4 +"%+ .%$%*#+#$ "%) +, -# +"# )%*# +(.# %) +"# &0)+V) +(.#6 ]/,+"#$
.$,-&#* '0+" +"0) 1,4# 0) +"%+ % )#.%$%+# *#+",4 '%) 1$#%+#4 A:)+ +, 4, +"# )#%$1"6 =+ ',:&4
-# -#++#$ 08 % *#+",4 '%)/V+ $#?:0$#46
!"# .$#20,:) #B%*.&# 1%/ -# $#'$0++#/ +, :)# % &%*-4% #B.$#))0,/> %) )",'/ 0/ +"# 8,&&,'5
0/3 1,4# )%*.&#M
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub LambdaExpressionsToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles LambdaExpressionsToolStripMenuItem.Click
Dim cars = GetCars()
Dim theYear = 2000
Dim found = cars.Find(Function(c) c.Year = theYear)
txtLog.AppendText(String.Format( _
"Car VIN:{0} Make:{1} Year:{2}" & Environment.NewLine, _
found.VIN, found.Make, found.Year))
End Sub
I018;4*$?*LM*L$%4
private void lambdaExpressionsToolStripMenuItem_Click(
object sender, EventArgs e)
{
')+D !"#$%&'( =/+$,4:10/3 C=DE
var cars = GetCars();
var theYear = 2000;
var found = cars.Find(c => c.Year== theYear);
txtLog.AppendText(string.Format(
"Car VIN:{0} Make:{1} Year{2}" + Environment.NewLine,
found.VIN, found.Make, found.Year));
}
<,: 1%/ +"0/@ ,8 +"# &%*-4% #B.$#))0,/ %) 0/&0/# *#+",46 !"# + .%$+ 4#1&%$#) +"#
.%$%*#+#$)> 1,**% 4#&0*0+#46 ]8+#$ +"# R, )03/> (,: "%2# +"# #B.$#))0,/6 =/ +"0) #B%*.&#>
+"# &%*-4% #B.$#))0,/ 0) ):..&0#4 0/&0/# '0+" +"# 26"= *#+",46 !"0) #&0*0/%+#) +"# /##4 8,$ %
)#.%$%+# *#+",46 ]&),> +"# 2%$0%-&# 1%& 14%P%'& 0) 4#U/#4 %) % &,1%& 2%$0%-&# 0/ +"# #/1&,)5
0/3 *#+",4> ), 0+V) %11#))0-&# +, +"# &%*-4% #B.$#))0,/6
P,$*%&&(> % &%*-4% #B.$#))0,/ 0) %/ #B.$#))0,/ +"%+ "%) ,/# 0/.:+ %/4 1,/+%0/) ,/&( %
)0/3&# )+%+#*#/+ +"%+ 0) #2%&:%+#4 +, .$,204# % )0/3&# $#+:$/ 2%&:#9 ",'#2#$> 0/ +"# 6DO!
P$%*#',$@> *:&+0.&# .%$%*#+#$) 1%/ -# .%))#4 +, % &%*-4% #B.$#))0,/> %/4 *:&+0.&# )+%+#5
*#/+) 1%/ -# .&%1#4 0/+, % &%*-4% #B.$#))0,/6 !"# 8,&&,'0/3 #B%*.&# )",') +"# *:&+05
)+%+#*#/+ &%*-4% #B.$#))0,/ )(/+%B6
I018;4*$?*J(6&0;*K06('*L$%4
Dim found = cars.Find(Function(c As Car)
Dim x As Integer
x = theYear
Return c.Year = x
End Function)
I018;4*$?*LM*L$%4
var found = cars.Find(c =>
{
int x;
x = theYear;
return c.Year == x;
});
=/ FG> 08 +"# &%*-4% #B.$#))0,/ +%@#) *:&+0.&# .%$%*#+#$)> +"# .%$%*#+#$) *:)+ -# ):$5
$,:/4#4 -( .%$#/+"#)#)> %/4 08 +"# &%*-4% #B.$#))0,/ +%@#) /, .%$%*#+#$)> (,: *:)+ .$,204#
%/ #*.+( )#+ ,8 .%$#/+"#)#) '"#$# +"# .%$%*#+#$ ',:&4 3,6
_,' %$# &%*-4% #B.$#))0,/) :)#4 '0+" C=DET ["#/ (,: +(.# (,:$ C=DE ?:#$(> -#"0/4
+"# )1#/#)> .%$+) ,8 0+ '0&& -# 1,/2#$+#4 0/+, % +$## ,8 &%*-4% #B.$#))0,/)6 ]&),> (,: *:)+ :)#
&%*-4% #B.$#))0,/) '0+" ?:#$( #B+#/)0,/ *#+",4)> '"01" %$# 1,2#$#4 $03"+ %8+#$ #B+#/)0,/
*#+",4)> '"01" 8,&&,')6
./"4!6($!*R4"7$%6
OB+#/)0,/ *#+",4) #/%-&# (,: +, %44 *#+",4) +, % +(.#> #2#/ 08 (,: 4,/V+ "%2# +"# ),:$1#
1,4# 8,$ +"# +(.#6
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )+E
!, :/4#$)+%/4 '"( (,: *03"+ '%/+ +"0)> +"0/@ ,8 +"0) )0*.&# )1#/%$0,M <,: '%/+ +, %44 %/
/K#$%&60 *#+",4 +, +"# /1&6"7 1&%))> -:+ (,: 4,/V+ "%2# +"# ),:$1# 1,4# 8,$ +"# /1&6"7 1&%))6
["%+ ',:&4 (,: 4,T
7/# ),&:+0,/ 0) +, 1$#%+# % /#' 1&%)) +"%+ 0/"#$0+) 8$,* /1&6"7> *%(-# 1%& J9@1&6"7> %/4
+"#/ %44 (,:$ /K#$%&60 *#+",4 +, +"0) 1&%))6 !"0) ),&:+0,/ "%) +', .$,-&#*)6 P0$)+> +"# /1&6"7
1&%)) 0) /%')%=> '"01" *#%/) +"%+ (,: 1%/V+ 0/"#$0+ 8$,* /1&6"76 O2#/ 08 (,: 1,:&4 0/"#$0+ 8$,*
/1&6"7 +, 1$#%+# (,:$ 1:)+,* 1&%))> (,: ',:&4 /##4 +, *%@# ):$# +"%+ #2#$(,/# :)#) 0+ %/4 /,+
+"# /1&6"7 1&%)) +"%+V) -:0&+ 0/6 <,: ',:&4 %&), /##4 +, '$0+# 1,4# +, 1,/2#$+ )+$0/3) (,: *03"+
$#1#02# '"#/ (,: *%@# 1%&&) ,:+)04# (,:$ %..&01%+0,/ 0/+, (,:$ J9@1&6"7 1&%))6
]/,+"#$ .,))0-&#> %/4 *,$# 20%-&#> ),&:+0,/ 0) +, 1$#%+# % "#&.#$ 1&%))> *%(-# 1%&
@1&6"7S%)5%&> +"%+ 1,/+%0/) %&& +"# *#+",4) (,: ',:&4 &0@# +, %44 +, +"# /1&6"7 1&%)) -:+ 1%/V+6
!"#)# *#+",4) ',:&4 +(.01%&&( -# )+%+01 *#+",4) %/4 +%@# /1&6"7 %) +"# U$)+ .%$%*#+#$6 _#$#
0) %/ #B%*.&# ,8 % @1&6"7S%)5%& 1&%)) +"%+ "%) +"# /K#$%&60 *#+",4M
I018;4*$?*J(6&0;*K06('*L$%4
Public Module StringHelper
Public Function IsNumeric(ByVal str As String) As Boolean
Dim val As Double
Return Double.TryParse(str, val)
End Function
End Module
I018;4*$?*LM*L$%4
public static class StringHelper
{
public static bool IsNumeric(string str)
{
double val;
return double.TryParse(str, out val);
}
}
!"# 8,&&,'0/3 1,4# :)#) +"# "#&.#$ 1&%)) +, +#)+ % 1,:.&# ,8 )+$0/3) +, )## '"#+"#$ +"#( %$#
/:*#$016 !"# ,:+.:+ '0&& 40).&%( -')/% 8,$ +"# U$)+ 1%&& %/4 1&#% 8,$ +"# )#1,/4 1%&&6
I018;4*$?*J(6&0;*K06('*L$%4
Dim s As String = "abc123"
txtLog.AppendText(StringHelper.IsNumeric(s) & Environment.NewLine)
s = "123"
txtLog.AppendText(StringHelper.IsNumeric(s) & Environment.NewLine)
I018;4*$?*LM*L$%4
string s = "abc123";
txtLog.AppendText(StringHelper.IsNumeric(s) + Environment.NewLine);
s = "123";
txtLog.AppendText(StringHelper.IsNumeric(s) + Environment.NewLine);
')B- !"#$%&'( =/+$,4:10/3 C=DE
["%+V) 3,,4 %-,:+ +"0) ),&:+0,/ 0) +"%+ +"# :)#$ 4,#)/V+ /##4 +, 0/)+%/+0%+# % 1:)+,* )+$0/3
1&%)) +, :)# +"# /K#$%&60 *#+",46 ["%+V) -%4 %-,:+ +"0) ),&:+0,/ 0) +"%+ +"# :)#$ /##4) +,
@/,' +"%+ +"# "#&.#$ 1&%)) #B0)+)> %/4 +"# )(/+%B 0) 1&:/@( %+ -#)+6
d$0,$ +, 6DO! P$%*#',$@ `6e> +"# "#&.#$ 1&%)) ),&:+0,/ '%) '"%+ *,)+ .#,.&# 0*.&#*#/+#4>
), (,: '0&& +(.01%&&( U/4 &,+) ,8 "#&.#$ 1&%))#) 0/ %/ %..&01%+0,/> %/4> (#)> (,: /##4 +, &,,@ 8,$
+"#* %/4 #B.&,$# +"# "#&.#$ 1&%))#) ), (,: @/,' '"%+V) 0/ +"#*6
=/ 6DO! P$%*#',$@ `6e> ;01$,),8+ 0/+$,4:1#4 #B+#/)0,/ *#+",4)6 I( :)0/3 #B+#/)0,/
*#+",4)> (,: 1%/ #B+#/4 % +(.# #2#/ '"#/ (,: 4,/V+ "%2# +"# ),:$1# 1,4# 8,$ +"# +(.#6 =/
),*# $#).#1+)> +"0) 0) 4#1#.+02#> -:+ 0+ ',$@) ',/4#$8:&&(> %) (,:V&& )##6
=/ +"# .$#20,:) )1#/%$0,> %/,+"#$ ),&:+0,/ 0) +, %44 +"# /K#$%&60 *#+",4 +, +"# /1&6"7
1&%)) -( :)0/3 %/ #B+#/)0,/ *#+",4> %440/3 % .:-&01 *,4:&# YFG .:-&01 /1'160 1&%))Z %/4 1$#%+5
0/3 .:-&01 )+%+01 *#+",4) 0/ +"0) 1&%))6 =/ H0):%& I%)01> (,: %44 +"# f!G1%"/6."AEg %++$0-:+#
-#8,$# +"# *#+",46 =/ FG> (,: %44 +"# @#(',$4 146/ 0/ 8$,/+ ,8 +"# U$)+ .%$%*#+#$ +, 0/401%+#
+"%+ (,: %$# #B+#/40/3 +"# +(.# ,8 +"0) .%$%*#+#$6
]&& (,:$ #B0)+0/3 "#&.#$ 1&%))#) 1%/ -# #%)0&( *,40U#4 +, -#1,*# #B+#/)0,/ *#+",4)> -:+
+"0) 4,#)/V+ -$#%@ #B0)+0/3 1,4#6 _#$# 0) +"# *,40U#4 "#&.#$ 1&%))> 0/ '"01" +"# /K#$%&60
*#+",4 0) /,' %/ #B+#/)0,/ *#+",4 ,/ /1&6"76
I018;4*$?*J(6&0;*K06('*L$%4
Imports System.Runtime.CompilerServices
Public Module StringHelper
<Extension()> _
Public Function IsNumeric(ByVal str As String) As Boolean
Dim val As Double
Return Double.TryParse(str, val)
End Function
End Module
I018;4*$?*LM*L$%4
public static class StringHelper
{
public static bool IsNumeric(this string str)
{
double val;
return double.TryParse(str, out val);
}
}
<,: 1%/ )## 0/ +"0) 1,4# #B%*.&# +"%+ +"# 1"%/3#) +, (,:$ "#&.#$ 1&%)) %$# *0/0*%&6 D,'
+"%+ +"# /K#$%&60 *#+",4 0) ,/ +"# /1&6"7 1&%))> (,: 1%/ 1%&& +"# #B+#/)0,/ *#+",4 %) 8,&&,')6
I018;4*$?*J(6&0;*K06('*L$%4
Dim s As String = "abc123"
txtLog.AppendText(s.IsNumeric() & Environment.NewLine)
s = "123"
txtLog.AppendText(s.IsNumeric() & Environment.NewLine)
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )B)
I018;4*$?*LM*L$%4
string s = "abc123";
txtLog.AppendText(s.IsNumeric() + Environment.NewLine);
s = "123";
txtLog.AppendText(s.IsNumeric() + Environment.NewLine);
<,: 1%/ )## +"%+ +"0) 0) *:1" 1&#%/#$ )(/+%B> -:+ +"# "#&.#$ 1&%)) )(/+%B )+0&& ',$@)> ),
(,: 1%/ 1,/2#$+ (,:$ "#&.#$ 1&%)) *#+",4) +, #B+#/)0,/ *#+",4) -:+ (,:V$# /,+ 8,$1#4 +,
1%&& +"# "#&.#$ *#+",4) #B.&010+&(6 I#1%:)# +"# 1,*.0&#$ 0) /,+ %-&# +, U/4 /K#$%&60 0/ +"#
/1&6"7 1&%))> 0+ 0) &,,@0/3 8,$ +"# #B+#/)0,/ *#+",4) +"%+ #B+#/4 /1&6"7 '0+" +"# $03"+ /%*#
%/4 +"# $03"+ )03/%+:$#6 I#"0/4 +"# )1#/#)> 0+ 0) )0*.&( 1"%/30/3 (,:$ /01# )(/+%B 0/+, 1%&&) +,
(,:$ "#&.#$ *#+",4) '"#/ (,: -:0&4 (,:$ %..&01%+0,/> ), +"# 1&:/@( )(/+%B 0) )+0&& +"#$# Y0/
+"# 1,*.0 1,4#Z> -:+ (,: 1%/V+ )## 0+6 d#$8,$*%/1# 0) #B%1+&( +"# )%*# %) '#&&6 !"# 4088#$5
#/1# 0) +"%+ +"# =/+#&&0S#/)# '0/4,' /,' )",') (,: +"# #B+#/)0,/ *#+",4) ,/ %/( /1&6"7> %)
)",'/ 0/ P03:$# `5`6 !"# 01,/ 8,$ +"# #B+#/)0,/ *#+",4 0) % -0+ 4088#$#/+ 8$,* +"# 01,/ 8,$ %
$#3:&%$ *#+",46 =/ 8%1+> +"#$# %$# %&$#%4( #B+#/)0,/ *#+",4) ,/ *%/( 8$%*#',$@ +(.#)6 =/
P03:$# `5`> +"# *#+",4 1%& :'/1 0) %&), %/ #B+#/)0,/ *#+",46
F?G;&%'(H(' OB+#/)0,/ *#+",4) 8,$ +"# /1&6"7 1&%)) %$# )",'/ 0/ +"# =/+#&&0S#/)# '0/4,'6
=/ +"# .$#20,:) 1,4# )%*.&#)> 404 (,: /,+01# +"%+ '"#/ % &0/# /##4#4 +, -# %..#/4#4
0/ +"# +%G1Q.G 1&%)) 1%& 1G1:.7> +"# )+$0/3 .%))#4 0/ 0) 1,/1%+#/%+#4 '0+" !"F6&."$%"1?
K%<:6"%T [,:&4/V+ 0+ -# 3$#%+ 08 +%G1Q.G "%4 % T&61%:6"% *#+",4T 78 1,:$)# 0+ ',:&4b =/ +"0)
#B%*.&#> % "#&.#$ 1&%)) 1%& +%G1Q.GS%)5%& 0) %44#4> %) 8,&&,')6
I018;4*$?*J(6&0;*K06('*L$%4
Imports System.Runtime.CompilerServices
Public Module TextBoxHelper
<Extension()> _
Public Sub WriteLine(ByVal txt As TextBox, ByVal line As Object)
txt.AppendText(line & Environment.NewLine)
End Sub
End Module
I018;4*$?*LM*L$%4
using System.Windows.Forms;
public static class TextBoxHelper
')B, !"#$%&'( =/+$,4:10/3 C=DE
{
public static void WriteLine(this TextBox txt, object line)
{
txt.AppendText(line + Environment.NewLine);
}
}
N)0/3 +"0) /#' #B+#/)0,/ *#+",4 ,/ +"# +%G1Q.G 1&%))> (,: 1%/ 1"%/3# +"# 1,4# 8$,* +"#
.$#20,:) #B%*.&#) +, :)# +"# /1&6"7 #B+#/)0,/ %/4 +"# +%G1Q.G #B+#/)0,/6 !"0) 1&#%/) :. (,:$
1,4#> %) )",'/ 0/ +"# 8,&&,'0/3 #B%*.
I018;4*$?*J(6&0;*K06('*L$%4
Dim s As String = "abc123"
txtLog.WriteLine(s.IsNumeric())
s = "123"
txtLog.WriteLine(s.IsNumeric())
I018;4*$?*LM*L$%4
string s = "abc123";
txtLog.WriteLine(s.IsNumeric());
s = "123";
txtLog.WriteLine(s.IsNumeric());
_#$# %$# ),*# $:&#) 8,$ ',$@0/3 '0+" #B+#/)0,/ *#+",4)M
■ OB+#/)0,/ *#+",4) *:)+ -# 4#U/#4 0/ % H0):%& I%)01 *,4:&# ,$ FG )+%+01 1&%))6
■ !"# H0):%& I%)01 *,4:&# ,$ FG )+%+01 1&%)) *:)+ -# 5#()606
■ =8 (,: 4#U/# %/ #B+#/)0,/ *#+",4 8,$ % +(.#> %/4 +"# +(.# %&$#%4( "%) +"# )%*#
*#+",4> +"# +(.#V) *#+",4 0) :)#4 %/4 +"# #B+#/)0,/ *#+",4 0) 03/,$#46
■ =/ FG> +"# 1&%)) %/4 +"# #B+#/)0,/ *#+",4) *:)+ -# /1'1606 H0):%& I%)01 *,4:&#) %/4
+"#0$ *#+",4) %$# %:+,*%+01%&&( )+%+01 YH0):%& I%)01 @4'&%=Z6
■ !"# #B+#/)0,/ *#+",4 ',$@) %) &,/3 %) 0+ 0) 0/ )1,.#6 !"0) *03"+ $#?:0$# (,: +, %44 %/
6$5.&1/ YFG #/6"7Z )+%+#*#/+ 8,$ +"# /%*#).%1# 0/ '"01" +"# #B+#/)0,/ *#+",4 0) +,
3#+ %11#)) +, +"# #B+#/)0,/ *#+",46
■ ]&+",:3" #B+#/)0,/ *#+",4) %$# 0*.&#*#/+#4 %) /1'160 YH0):%& I%)01 @4'&%=Z *#+",4)>
+"#( %$# 0/)+%/1# *#+",4) ,/ +"# +(.# (,: %$# #B+#/40/36 <,: 1%//,+ %44 )+%+01 *#+"5
,4) +, % +(.# '0+" #B+#/)0,/ *#+",4)6
-&4#=*./"4!6($!*R4"7$%6
D,' +"%+ (,:V2# )##/ #B+#/)0,/ *#+",4)> (,: *03"+ -# ',/4#$0/3 '"( ;01$,),8+ /##4#4
#B+#/)0,/ *#+",4) +, 0*.&#*#/+ C=DE6 !, 4, ),> ;01$,),8+ %44#4 #B+#/)0,/ *#+",4) +, )#25
#$%& +(.#)> -:+ *,)+ 0*.,$+%/+ %$# +"# *#+",4) +"%+ '#$# %44#4 +, +"# 3#/#$01 !"#$%&'()%
0/+#$8%1#6 OB+#/)0,/ *#+",4) 1%/ -# %44#4 +, %/( +(.#> '"01" 0) 0/+#$#)+0/3 '"#/ (,: +"0/@
,8 %440/3 1,/1$#+# #B+#/)0,/ *#+",4) Y*#+",4) +"%+ "%2# 1,4#Z +, 0/+#$8%1#)> '"01" %$#
%-)+$%1+ Y1%/V+ "%2# 1,4#Z6
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )B(
F,/)04#$ +"# 8,&&,'0/3 #B%*.&# 1,4#> 0/ '"01" %/ %$$%( ,8 )+$0/3) 1%& 0.).&/ 0) 1$#%+#4
%/4 %))03/#4 +, % 2%$0%-&# '",)# +(.# 0) !"#$%&'()% ,8 /1&6"76
I018;4*$?*J(6&0;*K06('*L$%4
Dim colors() =
{
"Red",
"Brown",
"Orange",
"Yellow",
"Black",
"Green",
"White",
"Violet",
"Blue"
}
Dim colorEnumerable As IEnumerable(Of String) = colors
I018;4*$?*LM*L$%4
string[] colors =
{
"Red",
"Brown",
"Orange",
"Yellow",
"Black",
"Green",
"White",
"Violet",
"Blue"
}
IEnumerable<string> colorEnumerable = colors;
I#1%:)# +"# 0.).&!"#$%&'()% 2%$0%-&#V) +(.# 0) !"#$%&'()% ,8 /1&6"7> '"#/ (,: +(.#
0.).&!"#$%&'()% %/4 .$#)) +"# .#$0,4 @#(> +"# =/+#&&0S#/)# '0/4,' 0) 40).&%(#4 %/4 )",') +"#
&0)+ ,8 *#+",4) %2%0&%-&# ,/ +"# 3#/#$01 !"#$%&'()% 0/+#$8%1#> %) )",'/ 0/ P03:$# `5h6 !"#)#
*#+",4) %$# @/,'/ %) U#%&93%G1%"/6."3$%14.=/6 =/ %440+0,/ +, +"# ?:#$( #B+#/)0,/ *#+",4)
+"%+ #B0)+ 8,$ !"#$%&'()%> +"# 3#/#$01 !"#$%&'()% 0/+#$8%1# %&), 1,/+%0/) ?:#$( #B+#/)0,/
*#+",4)6
F?G;&%'(H*' !"0) 803:$# )",') !G1%"/6." *#+",4) ,/ +"# !"#$%&'()% 0/+#$8%1#6
')B* !"#$%&'( =/+$,4:10/3 C=DE
S,*# ,8 +"#)# #B+#/)0,/ *#+",4) %$# *%..#4 40$#1+&( +, H0):%& I%)01 %/4 FG @#(',$4)
:)#4 0/ C=DE Y%&), @/,'/ %) C=DE ,.#$%+,$)Z6 P,$ #B%*.&#> (,:V&& U/4 T4%&% %/4 >&=%&Q9 #B5
+#/)0,/ *#+",4) +"%+ *%. 40$#1+&( +, +"# <4%&% %/4 .&=%&(9 YH0):%& I%)01 >&=%&3Q9Z @#(',$4)6
;01$,),8+ %44#4 +"#)# #B+#/)0,/ *#+",4) +, +"# !"#$%&'()% 0/+#$8%1# -( 0*.&#*#/+0/3
+"# #B+#/)0,/ *#+",4) 0/ % 1&%)) 1%& !"#$%&'()%> '"01" 0) 0/ +"# @9/1%$?:6"U /%*#).%1#6
!"0) 1&%)) 0) 0/ %/ %))#*-&( 1%& @9/1%$?I.&%?=)) +, '"01" *,)+ .$,A#1+ +#*.&%+#) %&$#%4(
"%2# % $#8#$#/1#6
-&*!' $I';J%'8?@A'"@K'A;%&3'%L$%@J?I@'M%$!IKJ
Q$*&64*+ ,-*0!%*@&4#=*4/"4!6($!*14"7$%6A*=$&#*8#$34'"*1&6"*#4?4#4!'4 !"#$%&'()*%'+,,A*
0!%A*(!*=$&#*'$%4A*=$&*1&6"*(18$#"*WLM*-#./0X*"74*!"#$%&'1./2*!014680'4C
!"# !"#$%&'()% 1&%)) %&), "%) +"$## )+%+01 *#+",4) (,: *03"+ U/4 :)#8:&M !$519> L'"7%>
%/4 L%5%'16 _#$# 0) % )",$+ 4#)1$0.+0,/ ,8 #%1" ,8 +"#)# *#+",4)6
■ %NO=P !"# 3#/#$01 !$519 *#+",4 .$,4:1#) % 3#/#$01 !"#$%&'()% ,-A#1+ '0+" /,
#&#*#/+)6
■ &>75/ !"# L'"7% *#+",4 .$,4:1#) % 1,:/+0/3 )#?:#/1# ,8 0/+#3#$ #&#*#/+)6 !"0)
1%/ -# :)#8:& '"#/ (,: '%/+ +, A,0/ % 1,:/+#$ +, %/,+"#$ #&#*#/+ )#?:#/1# +"%+
)",:&4 -# /:*-#$#46 !"0) *#+",4 +%@#) +', .%$%*#+#$)M +"# )+%$+0/3 /:*-#$ %/4 +"#
1,:/+ ,8 ",' *%/( +0*#) +, 0/1$#*#/+6 =8 (,: .%)) LKK>e +, +"0) *#+",4> 0+ '0&& .$,5
4:1# LKK> LKL> LKJ> LK`> LKh6
■ &/O/>= N)# +"# 3#/#$01 L%5%'1 *#+",4 +, .$,4:1# %/ !"#$%&'()%*6"1, ,-A#1+ +"%+
"%) +"# )%*# #&#*#/+ $#.#%+#46 !"0) *#+",4 %11#.+) +', .%$%*#+#$)M !)%$%"1 %/4
I.#"16 !"# %)%$%"1 .%$%*#+#$ 0) +"# #&#*#/+ +, -# $#.#%+#4> %/4 0.#"1 ).#10U#) ",'
*%/( +0*#) +, $#.#%+ +"# #&#*#/+6
!"# /#B+ )#1+0,/ 1,2#$) *%/( ,8 +"# ?:#$( #B+#/)0,/ *#+",4) +"%+ %$# 0*.&#*#/+#4 ,/
+"# !"#$%&'()% 1&%)) +, #B+#/4 +"# 3#/#$01 !"#$%&'()% 0/+#$8%1#6
311
!"# 8)) *#+",4 $#+:$/) 1&#% '"#/ %&& +"# #&#*#/+) 0/ +"# 1,&+0,/ *##+ % ).#10U#4 1$0+#$0,/
%/4 $#+:$/) -')/% ,+"#$'0)#6 _#$# 0) %/ #B%*.&# ,8 1"#1@0/3 '"#+"#$ %&& +"# 1%$) $#+:$/#4
8$,* +"# H%1I'&/ *#+",4 1%&& "%2# % (#%$ 3$#%+#$ +"%/ LijK6
I018;4*$?*J(6&0;*K06('*L$%4
txtLog.WriteLine(GetCars().All(Function(c) c.Year > 1960))
I018;4*$?*LM*L$%4
txtLog.WriteLine(GetCars().All(c => c.Year > 1960));
-&*! $I';J%'8?@A'"@K'A;%&3'%L$%@J?I@'M%$!IKJ
Q$*&64*+ ,-*0!%*@&4#=*4/"4!6($!*14"7$%6A*=$&#*8#$34'"*1&6"*#4?4#4!'4 !"#$%&'()*%'+,,A*,,,,
0!%A*(!*=$&#*'$%4A*=$&*1&6"*(18$#"*WLM*-#./0X*"74*!"#$%&'1./2*!014680'4C
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )B+
345
!"# 8"9 *#+",4 $#+:$/) 1&#% '"#/ %+ &#%)+ ,/# #&#*#/+ 0/ +"# 1,&+0,/ *##+) +"# ).#10U#4
1$0+#$0,/ %/4 $#+:$/) -')/% ,+"#$'0)#6 !"# 8,&&,'0/3 #B%*.&# 1"#1@) '"#+"#$ +"#$# 0) % 1%$ +"%+
"%) % (#%$ ,8 LijK ,$ #%$&0#$6
I018;4*$?*J(6&0;*K06('*L$%4
txtLog.WriteLine(GetCars().Any(Function(c) c.Year <= 1960))
I018;4*$?*LM*L$%4
txtLog.WriteLine(GetCars().Any(c => c.Year <= 1960));
3!6478693:16
!, #B.&%0/ +"# 8/!"#$%&'()% *#+",4> $#*#*-#$ +"# $:&# *#/+0,/#4 #%$&0#$ 0/ +"0) 1"%.+#$ 8,$
#B+#/)0,/ *#+",4)M
■ =8 (,: 4#U/# %/ #B+#/)0,/ *#+",4 8,$ % +(.#> %/4 +"# +(.# %&$#%4( "%) +"# )%*#
*#+",4> +"# +(.#V) *#+",4 '0&& -# :)#4> %/4 +"# #B+#/)0,/ *#+",4 0) 03/,$#46
N)# +"# 8/!"#$%&'()% *#+",4 '"#/ (,: '%/+ +, 1,/2#$+ % 1,&+0,/ +"%+ 0*.&#*#/+) +"#
3#/#$01 !"#$%&'()% 0/+#$8%1# -:+ 0) 1:$$#/+&( 1%)+ %) % 4088#$#/+ +(.#> ):1" %) M#%&9'()%> +,
+"# 3#/#$01 !"#$%&'()%6 !"0) 1%/ -# 4#)0$%-&# '"#/ +"# +(.# (,: %$# 1:$$#/+&( 1%)+0/3 "%) %
1,/1$#+# 0*.&#*#/+%+0,/ ,8 ,/# ,8 +"# #B+#/)0,/ *#+",4) (,: ',:&4 .$#8#$ +, 3#+ 1%&.
P,$ #B%*.&#> +"# +'()% 1&%)) +"%+ $#.$#)#/+) % 4%+%-%)# +%-&# 1,:&4 "%2# % T4%&% *#+",4
+"%+ +%@#) +"# .$#401%+# %$3:*#/+ %/4 #B#1:+#) % SEC ?:#$( +, +"# $#*,+# 4%+%-%)#6 =8 (,:
4,/V+ '%/+ +, #B#1:+# % 1%&& +, +"# 4%+%-%)# $#*,+#&(> (,: 1%/ :)# +"# 8/!"#$%&'()% *#+",4
+, 1%)+ +, !"#$%&'()% %/4 #B#1:+# +"# 1,$$#).,/40/3 T4%&% #B+#/)0,/ *#+",46
=/ +"0) #B%*.&#> % 1&%)) 1%& J9@1&6"7:6/1 0/"#$0+) 8$,* :6/13>-3@1&6"76 !"0) 1&%)) "%) %
)0/3&# T4%&% *#+",4 '",)# *#+",4 )03/%+:$# *%+1"#) +"# T4%&% *#+",4 ,/ +"# 3#/#$01
!"#$%&'()% 0/+#$8%1#6 !"# 1,4# 0/ +"# T4%&% *#+",4 ,8 +"# J9@1&6"7:6/1 1&%)) 0) $#+:$/0/3 %&&
#&#*#/+) -:+> -%)#4 ,/ +"# .$#401%+# +"%+V) .%))#4 0/> 0) 1,/2#$+0/3 #&#*#/+) +"%+ *%+1" +,
:..#$1%)#6
I018;4*$?*J(6&0;*K06('*L$%4
Public Class MyStringList
Inherits List(Of String)
Public Function Where(ByVal filter As Predicate(Of String)) As IEnumerable(Of
String)
Return Me.Select(Of String)(Function(s) IIf(filter(s), s.ToUpper(), s))
End Function
End Class
I018;4*$?*LM*L$%4
public class MyStringList : List<string>
{
public IEnumerable<string> Where(Predicate<string> filter)
{
return this.Select(s=>filter(s) ? s.ToUpper() : s);
')BB !"#$%&'( =/+$,4:10/3 C=DE
}
}
["#/ +"# 1,*.0&#$ &,,@) 8,$ % T4%&% *#+",4 ,/ % J9@1&6"7:6/1 ,-A#1+> 0+ U/4) %/ 0*.
*#/+%+0,/ 0/ +"# +(.# 0+)#&8 %/4 +":) 4,#) /,+ /##4 +, &,,@ 8,$ %/( #B+#/)0,/ *#+",46 !"#
8,&&,'0/3 1,4# )",') %/ #B%*.&#M
I018;4*$?*J(6&0;*K06('*L$%4
Dim strings As New MyStringList From {"orange", "apple", "grape", "pear"}
For Each item In strings.Where(Function(s) s.Length = 5)
txtLog.WriteLine(item)
Next
I018;4*$?*LM*L$%4
var strings = new MyStringList{"orange","apple","grape","pear"};
foreach (var item in strings.Where(s => s.Length == 5))
{
txtLog.WriteLine(item);
}
!"0) .$,4:1#) 8,:$ 0+#*) 0/ +"# ,:+.:+> -:+ +"# %..&# %/4 3$%.# '0&& -# :..#$1%)#6 !, 1%&&
+"# T4%&% #B+#/)0,/ *#+",4> :)# 8/!"#$%&'()% %) 8,&&,')M
I018;4*$?*J(6&0;*K06('*L$%4
For Each item In strings.AsEnumerable().Where(Function(s) s.Length = 5)
txtLog.WriteLine(item)
Next
I018;4*$?*LM*L$%4
foreach (var item in strings.AsEnumerable().Where(s => s.Length == 5))
{
txtLog.WriteLine(item);
}
!"0) .$,4:1#) ,/&( +', 0+#*)> +"# %..&# %/4 +"# 3$%.#> %/4 +"#( '0&& /,+ -# :..#$1%)#6
3!;3931161
S## Wd%$%&&#& C=DE YdC=DEZX &%+#$ 0/ +"0) 1"%.+#$6
3!<76953:16
!"# 8/M#%&9'()% #B+#/)0,/ *#+",4 1,/2#$+) %/ !"#$%&'()% ,-A#1+ +, %/ M#%&9'()% ,-A#1+6
!"0) *03"+ -# /##4#4 -#1%:)# +"# M#%&9'()% 0/+#$8%1# 0) +(.01%&&( 0*.&#*#/+#4 -( ?:#$(
.$,204#$) +, .$,204# 1:)+,* ?:#$( 1%.%-0&0+0#) ):1" %) .%))0/3 % ?:#$( -%1@ +, % 4%+%-%)# 8,$
#B#1:+0,/6
!"# M#%&9'()% 0/+#$8%1# 0/"#$0+) +"# !"#$%&'()% 0/+#$8%1# ), +"# $#):&+) ,8 % ?:#$( 1%/
-# #/:*#$%+#46 O/:*#$%+0,/ 1%:)#) %/( 1,4# %)),10%+#4 '0+" %/ M#%&9'()% ,-A#1+ +, -#
#B#1:+#46 =/ +"# 8,&&,'0/3 #B%*.&#> +"# 8/M#%&9'()% *#+",4 0) #B#1:+#4> %/4 0/8,$*%+0,/ 0)
/,' %2%0&%-&# 8,$ +"# .$,204#$6
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )BC
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub asQueryableToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles asQueryableToolStripMenuItem.Click
Dim strings As New MyStringList From {"orange", "apple", "grape", "pear"}
Dim querable = strings.AsQueryable()
txtLog.WriteLine("Element Type:{0}", querable.ElementType)
txtLog.WriteLine("Expression:{0}", querable.Expression)
txtLog.WriteLine("Provider:{0}", querable.Provider)
End Sub
I018;4*$?*LM*L$%4
private void asQueryableToolStripMenuItem_Click(object sender, EventArgs e)
{
IEnumerable<string> strings = new MyStringList
{ "orange", "apple", "grape", "pear" };
var querable = strings.AsQueryable();
txtLog.WriteLine("Element Type:{0}", querable.ElementType);
txtLog.WriteLine("Expression:{0}", querable.Expression);
txtLog.WriteLine("Provider:{0}", querable.Provider);
}
<,: 1%/ +"0/@ ,8 +"# 8/M#%&9'()% *#+",4 %) +"# ,..,)0+# ,8 +"# 8/!"#$%&'()% *#+",46
3=693>6
!"# 8F%&'7% #B+#/)0,/ *#+",4 0) %/ %33$#3%+# #B+#/)0,/ *#+",4 +"%+ 1%/ 1%&1:&%+# %/ %2#$5
%3# ,8 % /:*#$01 .$,.#$+( +"%+ #B0)+) ,/ +"# #&#*#/+) 0/ (,:$ 1,&+0,/6 =/ +"# 8,&&,'0/3
#B%*.&#> +"# 8F%&'7% *#+",4 1%&1:&%+#) +"# %2#$%3# (#%$ ,8 +"# 1%$)6
I018;4*$?*J(6&0;*K06('*L$%4
Dim averageYear = GetCars().Average(Function(c) c.Year)
txtLog.WriteLine(averageYear)
I018;4*$?*LM*L$%4
var averageYear = GetCars().Average(c => c.Year);
txtLog.WriteLine(averageYear);
(3!?
N)# +"# I'/1 #B+#/)0,/ *#+",4 '"#/ (,: '%/+ +, 1,/2#$+ #%1" ,8 +"# #&#*#/+) 0/ (,:$
),:$1# +, % 4088#$#/+ +(.#6 !"# #&#*#/+) 0/ +"# ),:$1# *:)+ -# 1,#$1#4 +, +"# +%$3#+ +(.#> ,$
%/ "F')6=I'/1!G0%516." 0) +"$,'/6
D,+# +"%+ +"# I'/1 *#+",4 0) /,+ % U&+#$6 =8 (,: '%/+ +, $#+$0#2# %&& +"# #&#*#/+) ,8 % ).#5
10U1 +(.#> :)# +"# >-+95% #B+#/)0,/ *#+",46 !"# 8,&&,'0/3 #B%*.&# 1,/2#$+) !"#$%&'()% ,8
I'& +, !"#$%&'()% ,8 >(;%016
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub castToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles castToolStripMenuItem.Click
Dim cars As IEnumerable(Of Car) = GetCars()
')BD !"#$%&'( =/+$,4:10/3 C=DE
Dim objects As IEnumerable(Of Object) = cars.Cast(Of Object)()
End Sub
I018;4*$?*LM*L$%4
private void castToolStripMenuItem_Click(object sender, EventArgs e)
{
IEnumerable<Car> cars = GetCars();
IEnumerable<Object> objects = cars.Cast<object>();
}
(@4(3?
N)# +"# I."0'1 #B+#/)0,/ *#+",4 +, 1,*-0/# +', )#?:#/1#)6 !"0) *#+",4 0) )0*0&%$ +, +"#
V"6." ,.#$%+,$> -:+ V"6." $#*,2#) 4:.&01%+#)> '"#$#%) I."0'1 4,#) /,+ $#*,2# 4:.&01%+#)6
!"# 8,&&,'0/3 #B%*.&# 1,*-0/#) +', 1,&+0,/) +, .$,4:1# % $#):&+ +"%+ 1,/+%0/) %&& #
*#/+) 8$,* -,+" 1,&+0,/)6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub concatToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles concatToolStripMenuItem.Click
Dim lastYearScores As Integer() = New Integer() {88, 56, 23, 99, 65}
Dim thisYearScores As Integer() = New Integer() {93, 78, 23, 99, 90}
Dim item As Integer
For Each item In lastYearScores.Concat(thisYearScores)
Me.txtLog.WriteLine(item)
Next
End Sub
I018;4*$?*LM*L$%4
private void concatToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] lastYearScores = { 88, 56, 23, 99, 65 };
int[] thisYearScores = { 93, 78, 23, 99, 90 };
foreach (var item in lastYearScores.Concat(thisYearScores))
{
txtLog.WriteLine(item);
}
}
Q74*#46&;"9
88
56
23
99
65
93
78
23
99
90
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )BE
(@4?3A4!
!"# I."1'6"/ #B+#/)0,/ *#+",4 4#+#$*0/#) '"#+"#$ %/ #&#*#/+ #B0)+) 0/ +"# ),:$1#6 =8 +"#
#&#*#/+ "%) +"# )%*# 2%&:#) 8,$ %&& +"# .$,.#$+0#) %) ,/# 0+#* 0/ +"# ),:$1#> I."1'6"/ $#+:$/)
-')/% 8,$ % $#8#$#/1# +(.# -:+ 1&#% 8,$ % 2%&:# +(.#6 !"# 1,*.%$0),/ 0) 4,/# -( $#8#$#/1# 8,$
1&%))#) %/4 -( 2%&:# 8,$ )+$:1+:$#)6 !"# 8,&&,'0/3 #B%*.&# 1,4# 3#+) % 1,&+0,/ ,8 1%$)> 1$#5
%+#) ,/# 2%$0%-&# +"%+ $#8#$#/1#) ,/# ,8 +"# 1%$) 0/ +"# 1,&+0,/> %/4 +"#/ 1$#%+#) %/,+"#$
2%$0%-&# +"%+ $#8#$#/1#) % /#' 1%$6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub containsToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles containsToolStripMenuItem.Click
Dim cars = Me.GetCars
Dim c1 = cars.Item(2)
Dim c2 As New Car
txtLog.WriteLine(cars.Contains(c1))
txtLog.WriteLine(cars.Contains(c2))
End Sub
I018;4*$?*LM*L$%4
private void containsToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
Car c1 = cars[2];
Car c2 = new Car();
txtLog.WriteLine(cars.Contains(c1));
txtLog.WriteLine(cars.Contains(c2));
}
Q74*#46&;"9
True
False
(@74?
!"# I.#"1 #B+#/)0,/ *#+",4 $#+:$/) +"# 1,:/+ ,8 +"# #&#*#/+) 0/ +"# ),:$1#6 !"# 8,&&,'0/3
1,4# #B%*.&# $#+:$/) +"# 1,:/+ ,8 1%$) 0/ +"# ),:$1# 1,&+0,/M
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub countToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles countToolStripMenuItem.Click
Dim cars = Me.GetCars
txtLog.WriteLine(cars.Count())
End Sub
I018;4*$?*LM*L$%4
private void countToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
txtLog.WriteLine(cars.Count());
}
')C- !"#$%&'( =/+$,4:10/3 C=DE
Q74*#46&;"9
5
B6C371?AC68;?5
N)# +"# W%-'#)1 -!$519 #B+#/)0,/ *#+",4 '"#/ (,: ):).#1+ +"%+ +"# ),:$1# 1,&+0,/ *03"+
/,+ "%2# %/( #&#*#/+)> -:+ (,: '%/+ %+ &#%)+ ,/# #&#*#/+ 1,$$#).,/40/3 +, +"# 4#8%:&+ 2%&:#
,8 +"# +(.# Y-')/% 8,$ I,,&#%/> B 8,$ /:*#$01> %/4 "#)) 8,$ % $#8#$#/1# +(.#Z6 !"0) *#+",4 $#5
+:$/) %&& #&#*#/+) 0/ +"# ),:$1# 08 +"#$# 0) %+ &#%)+ ,/# #&#*#/+ 0/ +"# ),:$1#6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub defaultIfEmptyToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles defaultIfEmptyToolStripMenuItem.Click
Dim cars As New List(Of Car)
Dim oneNullCar = cars.DefaultIfEmpty()
For Each car In oneNullCar
txtLog.WriteLine(IIf((car Is Nothing), "Null Car", "Not Null Car"))
Next
End Sub
I018;4*$?*LM*L$%4
private void defaultIfEmptyToolStripMenuItem_Click(object sender, EventArgs e)
{
List<Car> cars = new List<Car>();
IEnumerable<Car> oneNullCar = cars.DefaultIfEmpty();
foreach (var car in oneNullCar)
{
txtLog.WriteLine(car == null ? "Null Car" : "Not Null Car");
}
}
Q74*#46&;"9
Null Car
BA!?A4(?
!"# W6/16"01 #B+#/)0,/ *#+",4 $#*,2#) 4:.&01%+# 2%&:#) 0/ +"# ),:$1#6 !"# 8,&&,'0/3 1,4#
)%*.&# )",') ",' % 1,&+0,/ +"%+ "%) 4:.&01%+# 2%&:#) 0) U&+#$#4 -( :)0/3 +"# W6/16"01
*#+",46 ;%+1"0/3 +, 4#+#1+ 4:.&01%+0,/ 8,&&,') +"# )%*# $:&#) %) 8,$ I."1'6"/6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub distinctToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles distinctToolStripMenuItem.Click
Dim scores = New Integer() {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
For Each score In scores.Distinct()
txtLog.WriteLine(score)
Next
End Sub
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )C)
I018;4*$?*LM*L$%4
private void distinctToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
foreach (var score in scores.Distinct())
{
txtLog.WriteLine(score);
}
}
Q74*#46&;"9
88
56
23
99
65
93
78
90
616864?3?
N)# +"# !)%$%"181 #B+#/)0,/ *#+",4 '"#/ (,: @/,' (,: '%/+ +, $#+$0#2# +"# "+" #
*#/+ 0/ +"# ),:$1#6 =8 +"#$# 0) % 2%&04 #&#*#/+ %+ +"%+ K5-%)#4 &,1%+0,/> 0+V) $#+:$/#4 ,$ %/
8&7#$%"1>#1>-L'"7%!G0%516." 0) +"$,'/6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub elementAtToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles elementAtToolStripMenuItem.Click
Dim scores = New Integer() {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
txtLog.WriteLine(scores.ElementAt(4))
End Sub
I018;4*$?*LM*L$%4
private void elementAtToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
txtLog.WriteLine(scores.ElementAt(4));
}
Q74*#46&;"9
65
616864?3?@9B6C371?
!"# !)%$%"181>&W%-'#)1 #B+#/)0,/ *#+",4 0) +"# )%*# %) +"# !)%$%"181 #B+#/)0,/ *#+",4
#B1#.+ +"%+ %/ #B1#.+0,/ 0) /,+ +"$,'/ 08 +"# #&#*#/+ 4,#)/V+ #B0)+6 =/)+#%4> +"# 4#8%:&+ 2%&:#
8,$ +"# +(.# ,8 +"# 1,&+0,/ 0) $#+:$/#46 !"# )%*.&# 1,4# %++#*.+) +, %11#)) %/ #&#*#/+ +"%+
4,#)/V+ #B0)+6
')C, !"#$%&'( =/+$,4:10/3 C=DE
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub elementAtOrDefaultToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles elementAtOrDefaultToolStripMenuItem.Click
Dim scores = New Integer() {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
txtLog.WriteLine(scores.ElementAtOrDefault(15))
End Sub
I018;4*$?*LM*L$%4
private void elementAtOrDefaultToolStripMenuItem_Click(
object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
txtLog.WriteLine(scores.ElementAtOrDefault(15));
}
Q74*#46&;"9
0
6D(6;?
["#/ (,: "%2# % )#?:#/1# ,8 #&#*#/+) %/4 (,: '%/+ +, U/4 ,:+ '"01" #&#*#/+) 4,/V+ #B0)+
Y%) :):%&> -( $#8#$#/1# 8,$ 1&%))#) %/4 -( 2%&:# 8,$ )+$:1+:$#)Z 0/ % )#1,/4 )#?:#/1#> :)# +"#
!G0%51 #B+#/)0,/ *#+",46 !"# 8,&&,'0/3 1,4# )%*.&# $#+:$/) +"# 4088#$#/1#) -#+'##/ +',
1,&+0,/) ,8 0/+#3#$)6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub exceptToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles exceptToolStripMenuItem.Click
Dim lastYearScores As Integer() = New Integer() {88, 56, 23, 99, 65}
Dim thisYearScores As Integer() = New Integer() {93, 78, 23, 99, 90}
Dim item As Integer
For Each item In lastYearScores.Except(thisYearScores)
Me.txtLog.WriteLine(item)
Next
End Sub
I018;4*$?*LM*L$%4
private void exceptToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] lastYearScores = { 88, 56, 23, 99, 65 };
int[] thisYearScores = { 93, 78, 23, 99, 90 };
foreach (var item in lastYearScores.Except(thisYearScores))
{
txtLog.WriteLine(item);
}
}
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )C(
Q74*#46&;"9
88
56
65
CA9!?
["#/ (,: "%2# % )#?:#/1# ,8 #&#*#/+) %/4 (,: A:)+ /##4 +"# U$)+ #&#*#/+> :)# +"# 26&/1
#B+#/)0,/ *#+",46 !"0) *#+",4 4,#)/V+ 1%$# ",' *%/( #&#*#/+) %$# 0/ +"# )#?:#/1# %) &,/3
%) +"#$# 0) %+ &#%)+ ,/# #&#*#/+6 =8 /, #&#*#/+) #B0)+> %/ "F')6=>5%&'16."!G0%516." 0) +"$,'/6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub firstToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles firstToolStripMenuItem.Click
Dim scores = New Integer() {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
txtLog.WriteLine(scores.First())
End Sub
I018;4*$?*LM*L$%4
private void firstToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
txtLog.WriteLine(scores.First());
}
Q74*#46&;"9
88
CA9!?@9B6C371?
!"# 26&/1>&W%-'#)1 #B+#/)0,/ *#+",4 0) +"# )%*# %) +"# 26&/1 #B+#/)0,/ *#+",4 #B1#.+ +"%+ 08
/, #&#*#/+) #B0)+ 0/ +"# ),:$1# )#?:#/1#> +"# 4#8%:&+ 2%&:# ,8 +"# )#?:#/1# +(.# 0) $#+:$/#46
!"0) #B%*.&# '0&& %++#*.+ +, 3#+ +"# U$)+ #&#*#/+ '"#/ +"#$# %$# /, #&#*#/+)6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub firstOrDefaultToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles firstOrDefaultToolStripMenuItem.Click
Dim scores = New Integer() {}
txtLog.WriteLine(scores.FirstOrDefault())
End Sub
I018;4*$?*LM*L$%4
private void firstOrDefaultToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { };
txtLog.WriteLine(scores.FirstOrDefault());
}
Q74*#46&;"9
0
')C* !"#$%&'( =/+$,4:10/3 C=DE
>9@7;:5
!"# H&.#5Q9 #B+#/)0,/ *#+",4 $#+:$/) % )#?:#/1# ,8 H&.#56"7*+X%9C3+!)%$%"1, ,-A#1+)6
!"0) 0/+#$8%1# 0*.&#*#/+) !"#$%&'()%*+!)%$%"1, %/4 #B.,)#) % )0/3&# X%9 .$,.#$+( +"%+
$#.$#)#/+) +"# 3$,:.0/3 @#( 2%&:#6 !"# 8,&&,'0/3 1,4# )%*.&# 3$,:.) 1%$) -( +"# J'O%
.$,.#$+(6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub groupByToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles groupByToolStripMenuItem.Click
Dim cars = GetCars()
Dim query = cars.GroupBy(Function(c) c.Make)
For Each group As IGrouping(Of String, Car) In query
txtLog.WriteLine("Key:{0}", group.Key)
For Each c In group
txtLog.WriteLine("Car VIN:{0} Make:{1}", c.VIN, c.Make)
Next
Next
End Sub
I018;4*$?*LM*L$%4
private void groupByToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var query = cars.GroupBy(c => c.Make);
foreach (IGrouping<string,Car> group in query)
{
txtLog.WriteLine("Key:{0}", group.Key);
foreach (Car c in group)
{
txtLog.WriteLine("Car VIN:{0} Make:{1}", c.VIN, c.Make);
}
}
}
Q74*#46&;"9
Key:Ford
Car VIN:ABC123 Make:Ford
Car VIN:DEF456 Make:Ford
Key:BMW
Car VIN:DEF123 Make:BMW
Key:Audi
Car VIN:ABC456 Make:Audi
Key:VW
Car VIN:HIJ123 Make:VW
I#1%:)# +"#$# %$# +', P,$4)> +"#( %$# 3$,:.#4 +,3#+"#$6
!"# +.:..O#5 #B+#/)0,/ *#+",4 .$,204#) +"# )%*# $#):&+ #B1#.+ +"%+ H&.#5Q9 $#+:$/) %
4#8#$$#4 ?:#$(> '"#$#%) +.:..O#5 #B#1:+#) +"# ?:#$( 0**#40%+#&(> %/4 0+#$%+0/3 ,/ +"# $#5
):&+ %8+#$'%$4 '0&& /,+ 1"%/3# 08 +"# ),:$1# 1"%/3#)6 !"0) 0) #?:02%&#/+ +, +"# +.:6/1 #B+#/)0,/
*#+",4 0/+$,4:1#4 #%$&0#$ 0/ +"0) 1"%.+#$> -:+ 8,$ H&.#56"7 0/)+#%4 ,8 8,$ !"#$%&'()%6
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )C+
>9@7;E@A4
!"# H&.#5Y.6" #B+#/)0,/ *#+",4 0) )0*0&%$ +, +"# SEC + ,:+#$ A,0/ '"#$# 0+ %&'%() .$,4:1#)
,/# ,:+.:+ 8,$ #%1" 0/.:+ 8$,* +"# W,:+#$X )#?:#/1#6 ]/( *%+1"0/3 #&#*#/+) 8$,* +"# 0//#$
)#?:#/1# %$# 3$,:.#4 0/+, % 1,&+0,/ +"%+ 0) %)),10%+#4 '0+" +"# ,:+#$ #&#*#/+6 =/ +"# 8,&5
&,'0/3 #B%*.&# 1,4#> % 1,&+0,/ ,8 J'O%/ 0) .$,204#4 %/4 A,0/#4 +, +"# 0'&/ 1,&+0,/6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub groupToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles groupToolStripMenuItem.Click
Dim makes = New String() {"Audi", "BMW", "Ford", "Mazda", "VW"}
Dim cars = GetCars()
Dim query = makes.GroupJoin(cars, _
Function(make) make, _
Function(car) car.Make, _
Function(make, innerCars) New With {.Make = make, .Cars = innerCars})
For Each item In query
txtLog.WriteLine("Make: {0}", item.Make)
For Each car In item.Cars
txtLog.WriteLine("Car VIN:{0}, Model:{1}", car.VIN, car.Model)
Next
Next
End Sub
I018;4*$?*LM*L$%4
private void groupToolStripMenuItem_Click(object sender, EventArgs e)
{
var makes = new string[] { "Audi", "BMW", "Ford", "Mazda", "VW" };
var cars = GetCars();
var query = makes.GroupJoin(cars,
make => make, car => car.Make,
(make, innerCars) => new { Make = make, Cars = innerCars });
foreach (var item in query)
{
txtLog.WriteLine("Make: {0}", item.Make);
foreach (var car in item.Cars)
{
txtLog.WriteLine("Car VIN:{0}, Model:{1}", car.VIN, car.Model);
}
}
}
Q74*#46&;"9
Make: Audi
Car VIN:ABC456, Model:TT
Make: BMW
Car VIN:DEF123, Model:Z-3
Make: Ford
Car VIN:ABC123, Model:F-250
Car VIN:DEF456, Model:F-150
')CB !"#$%&'( =/+$,4:10/3 C=DE
Make: Mazda
Make: VW
Car VIN:HIJ123, Model:Bug
A4?69!6(?
["#/ (,: "%2# % )#?:#/1# ,8 #&#*#/+) 0/ '"01" (,: '%/+ +, U/4 ,:+ '"01" #B0)+ 0/ % )#1,/4
)#?:#/1#> :)# +"# "1%&/%01 #B+#/)0,/ *#+",46 !"# 8,&&,'0/3 1,4# #B%*.&# $#+:$/) +"# 1,*5
*,/ #&#*#/+) +"%+ #B0)+ 0/ +', 1,&+0,/) ,8 0/+#3#$)6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub intersectToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles intersectToolStripMenuItem.Click
Dim lastYearScores As Integer() = New Integer() {88, 56, 23, 99, 65}
Dim thisYearScores As Integer() = New Integer() {93, 78, 23, 99, 90}
Dim item As Integer
For Each item In lastYearScores.Intersect(thisYearScores)
Me.txtLog.WriteLine(item)
Next
End Sub
I018;4*$?*LM*L$%4
private void intersectToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] lastYearScores = { 88, 56, 23, 99, 65 };
int[] thisYearScores = { 93, 78, 23, 99, 90 };
foreach (var item in lastYearScores.Intersect(thisYearScores))
{
txtLog.WriteLine(item);
}
}
Q74*#46&;"9
23
99
E@A4
!"# Y.6" #B+#/)0,/ *#+",4 0) )0*0&%$ +, +"# SEC 0//#$ A,0/> -( '"01" 0+ .$,4:1#) ,:+.:+ ,/&(
8,$ #%1" 0/.:+ 8$,* +"# ,:+#$ )#?:#/1# '"#/ +"#$# 0) % *%+1" +, +"# 0//#$ )#?:#/1#6 P,$
#%1" *%+1"0/3 #&#*#/+ 0/ +"# 0//#$ )#?:#/1#> % $#):&+0/3 #&#*#/+ 0) 1$#%+#46 =/ +"# 8,&&,'0/3
)%*.&# 1,4#> % 1,&+0,/ ,8 J'O%/ 0) .$,204#4 %/4 A,0/#4 +, +"# 0'&/ 1,&+0,/6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub joinToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles joinToolStripMenuItem.Click
Dim makes = New String() {"Audi", "BMW", "Ford", "Mazda", "VW"}
Dim cars = GetCars()
Dim query = makes.Join(cars, _
Function(make) make, _
Function(car) car.Make, _
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )CC
Function(make, innerCar) New With {.Make = make, .Car = innerCar})
For Each item In query
txtLog.WriteLine("Make: {0}, Car:{1} {2} {3}",
item.Make, item.Car.VIN, item.Car.Make, item.Car.Model)
Next
End Sub
I018;4*$?*LM*L$%4
private void joinToolStripMenuItem_Click(object sender, EventArgs e)
{
var makes = new string[] { "Audi", "BMW", "Ford", "Mazda", "VW" };
var cars = GetCars();
var query = makes.Join(cars,
make => make, car => car.Make,
(make, innerCar) => new { Make = make, Car = innerCar });
foreach (var item in query)
{
txtLog.WriteLine("Make: {0}, Car:{1} {2} {3}",
item.Make, item.Car.VIN, item.Car.Make, item.Car.Model);
}
}
Q74*#46&;"9
Make: Audi, Car:ABC456 Audi TT
Make: BMW, Car:DEF123 BMW Z-3
Make: Ford, Car:ABC123 Ford F-250
Make: Ford, Car:DEF456 Ford F-150
Make: VW, Car:HIJ123 VW Bug
!(")$*+,
O$#*"74*4/01A*4/84'"*"$*24*"46"4%*$!*"74*50#($&6*>0=6*"$*3$(!*64@&4!'46C
13!?
["#/ (,: '%/+ +, $#+$0#2# +"# &%)+ #&#*#/+ 0/ % )#?:#/1#> :)# +"# :'/1 #B+#/)0,/ *#+",46
!"0) *#+",4 +"$,') %/ "F')6=>5%&'16."!G0%516." 08 +"#$# %$# /, #&#*#/+) 0/ +"# )#?:#/1#6
!"# 8,&&,'0/3 )%*.&# 1,4# $#+$0#2#) +"# &%)+ #&#*#/+6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub lastToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles lastToolStripMenuItem.Click
Dim scores = New Integer() {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
txtLog.WriteLine(scores.Last())
End Sub
I018;4*$?*LM*L$%4
private void lastToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
')CD !"#$%&'( =/+$,4:10/3 C=DE
txtLog.WriteLine(scores.Last());
}
Q74*#46&;"9
90
13!?@9B6C371?
!"# :'/1>&W%-'#)1 #B+#/)0,/ *#+",4 0) +"# )%*# %) +"# :'/1 #B+#/)0,/ *#+",4 #B1#.+ +"%+ 08
/, #&#*#/+) #B0)+ 0/ +"# ),:$1# )#?:#/1#> +"# 4#8%:&+ 2%&:# ,8 +"# )#?:#/1# +(.# 0) $#+:$/#46
!"0) #B%*.&# '0&& %++#*.+ +, 3#+ +"# &%)+ #&#*#/+ '"#/ +"#$# %$# /, #&#*#/+)6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub lastOrDefaultToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles lastOrDefaultToolStripMenuItem.Click
Dim scores = New Integer() {}
txtLog.WriteLine(scores.LastOrDefault())
End Sub
I018;4*$?*LM*L$%4
private void lastOrDefaultToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { };
txtLog.WriteLine(scores.LastOrDefault());
}
Q74*#46&;"9
0
1@4>(@74?
!"# :."7I.#"1 #B+#/)0,/ *#+",4 0) +"# )%*# %) +"# I.#"1 #B+#/)0,/ *#+",4 #B1#.+ +"%+
I.#"1 $#+:$/) % `J5-0+ 0/+#3#$> %/4 :."7I.#"1 $#+:$/) % jh5-0+ 0/+#3#$6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub longCountToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles longCountToolStripMenuItem.Click
Dim cars = Me.GetCars
txtLog.WriteLine(cars.LongCount())
End Sub
I018;4*$?*LM*L$%4
private void longCountToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
txtLog.WriteLine(cars.LongCount());
}
Q74*#46&;"9
5
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )CE
83D
["#/ (,:V$# ',$@0/3 '0+" % /,/5#*.+( )#?:#/1# ,8 2%&:#) %/4 (,: '%/+ +, 4#+#$*0/# '"01"
#&#*#/+ 0) 3$#%+#)+> :)# +"# J'G #B+#/)0,/ *#+",46 !"# J'G #B+#/)0,/ "%) )#2#$%& ,2#$&,%4)>
-:+ +"# 8,&&,'0/3 1,4# )%*.&# )",') +', ,8 +"# *,$# 1,**,/ ,2#$&,%4) +"%+ 4#*,/)+$%+#
+"# J'G #B+#/)0,/ *#+",4V) 1%.%-0&0+0#)6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub maxToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles maxToolStripMenuItem.Click
Dim scores = New Integer() {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
txtLog.WriteLine(scores.Max())
Dim cars = GetCars()
txtLog.WriteLine(cars.Max(Function(c) c.Year))
End Sub
I018;4*$?*LM*L$%4
private void maxToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
txtLog.WriteLine(scores.Max());
var cars = GetCars();
txtLog.WriteLine(cars.Max(c => c.Year));
}
Q74*#46&;"9
99
=/ +"0) #B%*.&#> +"# .%$%*#+#$&#)) ,2#$&,%4 0) 1%& ,/ % 1,&+0,/ ,8 0/+#3#$) %/4 $#+:$/)
+"# *%B0*:* 2%&:# ,8 ii6 !"# /#B+ ,2#$&,%4 #B%*.&# #/%-&#) (,: +, .$,204# % )#+,$ +"%+
).#10U#) % .$,.#$+( +"%+ U/4) +"# *%B0*:* 2%&:#6
8A4
["#/ (,:V$# ',$@0/3 '0+" % /,/5#*.+( )#?:#/1# ,8 2%&:#) %/4 (,: '%/+ +, 4#+#$*0/#
'"01" #&#*#/+ 0) +"# )*%&&#)+> :)# +"# J6" #B+#/)0,/ *#+",4> %) )",'/ 0/ +"# 8,&&,'0/3 1,4#
)%*.
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub maxToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles maxToolStripMenuItem.Click
Dim scores = New Integer() {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
txtLog.WriteLine(scores.Min())
End Sub
I018;4*$?*LM*L$%4
private void maxToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
txtLog.WriteLine(scores.Min());
}
')D- !"#$%&'( =/+$,4:10/3 C=DE
Q74*#46&;"9
23
@C?5;6
!"# >-+95% #B+#/)0,/ *#+",4 0) % U&+#$0/3 *#+",4 +"%+ $#+:$/) ,/&( ,-A#1+) +"%+ 1%/ -# +(.#
1%)+ +, % ).#10U1 +(.#6 !"# 8,&&,'0/3 )%*.&# 1,4# $#+$0#2#) A:)+ +"# 0/+#3#$) 8$,* +"# ,-A#1+
1,&+0,/6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub ofTypeToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ofTypeToolStripMenuItem.Click
Dim items = New Object() {55, "Hello", 22, "Goodbye"}
For Each intItem In items.OfType(Of Integer)()
txtLog.WriteLine(intItem)
Next
End Sub
I018;4*$?*LM*L$%4
private void ofTypeToolStripMenuItem_Click(object sender, EventArgs e)
{
object[] items = new object[] { 55, "Hello", 22, "Goodbye" };
foreach (var intItem in items.OfType<int>())
{
txtLog.WriteLine(intItem);
}
}
Q74*#46&;"9
55
22
@9B69:5A*@9B69:5B6!(64BA4>A*?F64:5A*F,N*?F64:5B6!(64BA4>
["#/ (,: '%/+ +, ),$+ +"# #&#*#/+) 0/ % )#?:#/1#> (,: 1%/ :)# +"# >&=%&Q9 ,$
>&=%&Q9W%/0%"=6"7 #B+#/)0,/ *#+",4)> 8,&&,'#4 -( +"# +4%"Q9 %/4 +4%"Q9W%/0%"=6"7
#B+#/)0,/ *#+",4)6 !"#)# #B+#/)0,/ *#+",4) %$# "."/1&%'$6"7> '"01" *#%/) +"%+ %&& #
*#/+) 0/ +"# )#?:#/1# *:)+ -# #2%&:%+#4 -#8,$# %/( ,:+.:+ 1%/ -# .$,4:1#46 ;,)+ #B+#/5
)0,/ *#+",4) %$# /1&%'$6"7> '"01" *#%/) +"%+ #%1" #&#*#/+ 1%/ -# #2%&:%+#4 %/4 .,+#/+0%&&(
,:+.:+ '0+",:+ "%20/3 +, #2%&:%+# %&& #&#*#/+)6
]&& +"#)# #B+#/)0,/ *#+",4) $#+:$/ %/ >&=%&%=!"#$%&'()%*+, ,-A#1+> '"01" 0/"#$0+)
8$,* !"#$%&'()%*+, %/4 #/%-&#) +"# +4%"Q9 %/4 +4%"Q9W%/0%"=6"7 ,.#$%+,$)6 +4%"Q9
%/4 +4%"Q9W%/0%"=6"7 %$# #B+#/)0,/ *#+",4) ,/ >&=%&%=!"#$%&'()%*+, 0/)+#%4 ,8 ,/
!"#$%&'()%*+,> '"01" +"# ,+"#$ #B+#/)0,/ *#+",4) #B+#/46 !"0) 1%/ ),*#+0*#) 1$#%+# :/5
#B.#1+#4 #$$,$) '"#/ :)0/3 +"# F'& @#(',$4 %/4 +(.# 0/8#$#/1#6 !"# 8,&&,'0/3 1,4# #B%*.&#
1$#%+#) % &0)+ ,8 1%$) %/4 +"#/ ),$+) +"#* -( *%@#> *,4#& 4#)1#/40/3> %/4 (#%$6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub orderByToolStripMenuItem_Click(ByVal sender As System.Object, _
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )D)
ByVal e As System.EventArgs) Handles orderByToolStripMenuItem.Click
Dim cars = GetCars().OrderBy(Function(c) c.Make) _
.ThenByDescending(Function(c) c.Model) _
.ThenBy(Function(c) c.Year)
For Each item In cars
txtLog.WriteLine("Car VIN:{0} Make:{1} Model:{2} Year:{3}", _
item.VIN, item.Make, item.Model, item.Year)
Next
End Sub
I018;4*$?*LM*L$%4
private void orderByToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars().OrderBy(c=>c.Make)
.ThenByDescending(c=>c.Model)
.ThenBy(c=>c.Year);
foreach (var item in cars)
{
txtLog.WriteLine("Car VIN:{0} Make:{1} Model:{2} Year:{3}",
item.VIN, item.Make, item.Model, item.Year);
}
}
Q74*#46&;"9
Car VIN:ABC456 Make:Audi Model:TT Year:2008
Car VIN:DEF123 Make:BMW Model:Z-3 Year:2005
Car VIN:ABC123 Make:Ford Model:F-250 Year:2000
Car VIN:DEF456 Make:Ford Model:F-150 Year:1998
Car VIN:HIJ123 Make:VW Model:Bug Year:1956
96=69!6
!"# L%F%&/% #B+#/)0,/ *#+",4 0) %/ ,$4#$0/3 *#1"%/0)* +"%+ $#2#$)#) +"# ,$4#$ ,8 +"#
)#?:#/1# #&#*#/+)6 !"0) 1,4# )%*.&# 1$#%+#) % 1,&+0,/ ,8 0/+#3#$) -:+ 40).&%() +"#* 0/
$#2#$)# ,$4#$6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub reverseToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles reverseToolStripMenuItem.Click
Dim scores = {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
For Each item In scores.Reverse()
txtLog.WriteLine(item)
Next
End Sub
I018;4*$?*LM*L$%4
private void reverseToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
foreach (var item in scores.Reverse())
{
txtLog.WriteLine(item);
')D, !"#$%&'( =/+$,4:10/3 C=DE
}
}
Q74*#46&;"9
90
99
23
78
93
65
99
23
56
88
!616(?
!"# @%)%01 #B+#/)0,/ *#+",4 $#+:$/) ,/# ,:+.:+ #&#*#/+ 8,$ #%1" 0/.:+ #&#*#/+6 ]&+",:3"
@%)%01 $#+:$/) ,/# ,:+.:+ 8,$ #%1" 0/.:+> +"# @%)%01 ,.#$%+,$ %&), #/%-&#) (,: +, .#$8,$* %
.$,A#1+0,/ +, % /#' +(.# ,8 #&#*#/+6 !"0) 1,/2#$)0,/ ,$ *%..0/3 *#1"%/0)* .&%() %/ 0*.,$5
+%/+ $,&# 0/ *,)+ C=DE ?:#$0#)6
=/ +"# 8,&&,'0/3 #B%*.&#> % 1,&+0,/ ,8 +#5)% +(.#) 0) ?:#$0#4 +, $#+$0#2# %&& +"# #&#*#/+)
'",)# *%@# Y+#5)%?61%$DZ 0) 2.&=> -:+ +"# @%)%01 #B+#/)0,/ *#+",4 +$%/)8,$*) +"#)# +#5)%
+(.#) 0/+, I'& ,-A#1+)6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub selectToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles selectToolStripMenuItem.Click
Dim vehicles As New List(Of Tuple(Of String, String, Integer)) From { _
Tuple.Create(Of String, String, Integer)("123", "VW", 1999), _
Tuple.Create(Of String, String, Integer)("234", "Ford", 2009), _
Tuple.Create(Of String, String, Integer)("567", "Audi", 2005), _
Tuple.Create(Of String, String, Integer)("678", "Ford", 2003), _
Tuple.Create(Of String, String, Integer)("789", "Mazda", 2003), _
Tuple.Create(Of String, String, Integer)("999", "Ford", 1965) _
}
Dim fordCars = vehicles.Where(Function(v) v.Item2 = "Ford") _
.Select(Function(v) New Car With { _
.VIN = v.Item1, _
.Make = v.Item2, _
.Year = v.Item3 _
})
For Each item In fordCars
txtLog.WriteLine("Car VIN:{0} Make:{1} Year:{2}", _
item.VIN, item.Make, item.Year)
Next
End Sub
I018;4*$?*LM*L$%4
private void selectToolStripMenuItem_Click(object sender, EventArgs e)
{
var vehicles = new List<Tuple<string,string,int>>
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )D(
{
Tuple.Create("123", "VW", 1999),
Tuple.Create("234","Ford",2009),
Tuple.Create("567","Audi", 2005),
Tuple.Create("678","Ford", 2003),
Tuple.Create("789","Mazda", 2003),
Tuple.Create("999","Ford",1965)
};
var fordCars = vehicles
.Where(v=>v.Item2=="Ford")
.Select(v=>new Car
{
VIN=v.Item1,
Make=v.Item2,
Year=v.Item3
});
foreach (var item in fordCars )
{
txtLog.WriteLine("Car VIN:{0} Make:{1} Year:{2}",
item.VIN, item.Make, item.Year);
}
}
Q74*#46&;"9
Car VIN:234 Make:Ford Year:2009
Car VIN:678 Make:Ford Year:2003
Car VIN:999 Make:Ford Year:1965
!616(?8345
["#/ (,: :)# +"# @%)%01 #B+#/)0,/ *#+",4> #%1" #&#*#/+ 8$,* +"# 0/.:+ )#?:#/1# 1%/ .$,5
4:1# ,/&( ,/# #&#*#/+ 0/ +"# ,:+.:+ )#?:#/1#6 !"# @%)%01J'"9 #B+#/)0,/ *#+",4 .$,A#1+)
% )0/3&# ,:+.:+ #&#*#/+ 0/+, *%/( ,:+.:+ #&#*#/+)> ), (,: 1%/ :)# +"# @%)%01J'"9 *#+",4
+, .#$8,$* % SEC 0//#$ A,0/> -:+ (,: 1%/ %&), :)# 0+ '"#/ (,: %$# ',$@0/3 '0+" % 1,&+0,/
,8 1,&+0,/)> %/4 (,: %$# ?:#$(0/3 +"# ,:+#$ 1,&+0,/ -:+ /##4 +, .$,4:1# %/ ,:+.:+ #
*#/+ 8,$ #%1" #&#*#/+ 0/ +"# 0//#$ 1,&+0,/6
=/ +"# 8,&&,'0/3 1,4# )%*.&# 0) % &0)+ ,8 $#.%0$) 0/ '"01" #%1" #&#*#/+ 0/ +"# &%5'6&/ 1,&5
+0,/ 0) % +#5)% +"%+ 1,/+%0/) +"# H=D ,8 +"# 2#"01&# %) 61%$Z %/4 % &0)+ ,8 $#.%0$) %) 61%$D6
@%)%01J'"9 #B.%/4) #%1" +#5)% 0/+, % )#?:#/1# ,8 $#.%0$)6 @%)%01 .$,A#1+) #%1" $#.%0$ %/4 +"#
%)),10%+#4 H=D 0/+, %/ %/,/(*,:) +(.# 0/)+%/1#6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub selectManyToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles selectManyToolStripMenuItem.Click
Dim repairs = New List(Of Tuple(Of String, List(Of String))) From
{
Tuple.Create("ABC123",
New List(Of String) From {"Rotate Tires", "Change oil"}),
Tuple.Create("DEF123",
New List(Of String) From {"Fix Flat", "Wash Vehicle"}),
Tuple.Create("ABC456",
')D* !"#$%&'( =/+$,4:10/3 C=DE
New List(Of String) From {"Alignment", "Vacuum", "Wax"}),
Tuple.Create("HIJ123",
New List(Of String) From {"Spark plugs", "Air filter"}),
Tuple.Create("DEF456",
New List(Of String) From {"Wiper blades", "PVC valve"})
}
Dim query = repairs.SelectMany(Function(t) _
t.Item2.Select(Function(r) New With {.VIN = t.Item1, .Repair = r}))
For Each item In query
txtLog.WriteLine("VIN:{0} Repair:{1}", item.VIN, item.Repair)
Next
End Sub
I018;4*$?*LM*L$%4
private void selectManyToolStripMenuItem_Click(object sender, EventArgs e)
{
var repairs = new List<Tuple<string, List<string>>>
{
Tuple.Create("ABC123",
new List<string>{"Rotate Tires","Change oil"}),
Tuple.Create("DEF123",
new List<string>{"Fix Flat","Wash Vehicle"}),
Tuple.Create("ABC456",
new List<string>{"Alignment","Vacuum", "Wax"}),
Tuple.Create("HIJ123",
new List<string>{"Spark plugs","Air filter"}),
Tuple.Create("DEF456",
new List<string>{"Wiper blades","PVC valve"}),
};
var query = repairs.SelectMany(t =>
t.Item2.Select(r => new { VIN = t.Item1, Repair = r }));
foreach (var item in query)
{
txtLog.WriteLine("VIN:{0} Repair:{1}", item.VIN, item.Repair);
}
}
Q74*#46&;"9
VIN:ABC123 Repair:Rotate Tires
VIN:ABC123 Repair:Change oil
VIN:DEF123 Repair:Fix Flat
VIN:DEF123 Repair:Wash Vehicle
VIN:ABC456 Repair:Alignment
VIN:ABC456 Repair:Vacuum
VIN:ABC456 Repair:Wax
VIN:HIJ123 Repair:Spark plugs
VIN:HIJ123 Repair:Air filter
VIN:DEF456 Repair:Wiper blades
VIN:DEF456 Repair:PVC valve
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )D+
!6<764(66<731
7/# )1#/%$0, (,: *03"+ $:/ 0/+, 0) '"#/ (,: "%2# +', )#?:#/1#) %/4 '%/+ +, )## '"#+"#$
+"#( 1,/+%0/ +"# )%*# #&#*#/+) 0/ +"# )%*# ,$4#$6 !"# @%U#%"0%!U#') #B+#/)0,/ *#+",4
1%/ .#$8,$* +"0) +%)@6 =+ '%&@) +"$,:3" +', )#?:#/1#) %/4 1,*.%$#) +"# #&#*#/+) 0/)04# 8,$
#?:%&0+(6 <,: 1%/ %&), ,2#$$04# +"# #?:%&0+( +#)+ -( .$,2040/3 %/ !U#')619I.$5'&%& ,-A#1+ %)
% .%$%*#+#$6 !"# 8,&&,'0/3 #B%*.&# 1,4# 1,*.%$#) +', )#?:#/1#) )#2#$%& +0*#) %/4 40).&%()
+"# $#):&+6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub sequenceEqualToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles sequenceEqualToolStripMenuItem.Click
Dim lastYearScores = New List(Of Integer) From {93, 78, 23, 99, 91}
Dim thisYearScores = New List(Of Integer) From {93, 78, 23, 99, 90}
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores))
lastYearScores(4) = 90
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores))
thisYearScores.Add(85)
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores))
lastYearScores.Add(85)
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores))
lastYearScores.Add(75)
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores))
End Sub
I018;4*$?*LM*L$%4
private void sequenceEqualToolStripMenuItem_Click(object sender, EventArgs e)
{
var lastYearScores = new List<int>{ 93, 78, 23, 99, 91 };
var thisYearScores = new List<int>{ 93, 78, 23, 99, 90 };
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores));
lastYearScores[4] = 90;
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores));
thisYearScores.Add(85);
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores));
lastYearScores.Add(85);
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores));
lastYearScores.Add(75);
txtLog.WriteLine(lastYearScores.SequenceEqual(thisYearScores));
}
Q74*#46&;"9
False
True
False
True
False
!A4>16
!"# @6"7)% #B+#/)0,/ *#+",4 )",:&4 -# :)#4 '"#/ (,: "%2# % 1,&+0,/ ,8 ,/# #&#*#/+ %/4
'%/+ +, 1,/2#$+ +"# 3#/#$01 !"#$%&'()% 0/+#$8%1# +, +"# )0/3&# #&#*#/+6 =8 +"# )#?:#/1# 1,/5
+%0/) *,$# +"%/ ,/# #&#*#/+ ,$ /, #&#*#/+)> %/ #B1#.+0,/ 0) +"$,'/6 !"# 8,&&,'0/3 #B%*.&#
')DB !"#$%&'( =/+$,4:10/3 C=DE
1,4# ?:#$0#) +, $#+$0#2# +"# 1%$ '0+" H=D _=kLJ` %/4 +"#/ :)#) +"# @6"7)% #B+#/)0,/ *#+",4
+, 1,/2#$+ !"#$%&'()% +, +"# )0/3&# I'&6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub singleToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles singleToolStripMenuItem.Click
Dim cars = GetCars()
Dim myCar As Car = cars.Where(Function(c) c.VIN = "HIJ123").Single()
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2}", _
myCar.VIN, myCar.Make, myCar.Model)
End Sub
I018;4*$?*LM*L$%4
private void singleToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
Car myCar = cars.Where(c => c.VIN == "HIJ123").Single();
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2}",
myCar.VIN, myCar.Make, myCar.Model);
}
Q74*#46&;"9
Car VIN:HIJ123, Make:VW, Model:Bug
!A4>16@9B6C371?
!"# @6"7)%>&W%-'#)1 #B+#/)0,/ *#+",4 ',$@) &0@# +"# @6"7)% #B+#/)0,/ *#+",4 #B1#.+
+"%+ 0+ 4,#)/V+ +"$,' %/ #B1#.+0,/ 08 /, #&#*#/+) %$# 0/ +"# )#?:#/1#6 =+ )+0&& +"$,') %/3
3 "F')6=>5%&'16."!G0%516." 08 *,$# +"%/ ,/# #&#*#/+ #B0)+) 0/ +"# )#?:#/1#6 !"# 8,&&,'0/3
)%*.&# 1,4# %++#*.+) +, &,1%+# % 1%$ '0+" %/ 0/2%&04 H=D> ), /, #&#*#/+) #B0)+ 0/ +"# )#5
?:#/1#9 +"#$#8,$#> +"# $9I'& 2%$0%-&# '0&& -# K.146"7 YFG "#))Z6
I018;4*$?*J(6&0;*K06('*L$%4
Private Sub singleOrDefaultToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles singleOrDefaultToolStripMenuItem.Click
Dim cars = GetCars()
Dim myCar = cars.Where(Function(c) c.VIN = "XXXXXX").SingleOrDefault()
txtLog.WriteLine(myCar Is Nothing)
End Sub
I018;4*$?*LM*L$%4
private void singleOrDefaultToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
Car myCar = cars.Where(c => c.VIN == "XXXXXX").SingleOrDefault();
txtLog.WriteLine(myCar == null);
}
Q74*#46&;"9
True
C#)),/ LM N/4#$)+%/40/3 C=DE !"#$%&'(' )DC
!GA;
!"# !"# !"#!$%&'$ (!#)'* &+$',!%- ', ./(0% '1!,- !2!(!$#% &$ #)! %'/,3! %!4/!$3!5 6)&%
(!#)'*- 7)!$ 3'(8&$!* 7&#) #)! $%!& !"#!$%&'$ (!#)'*- #90&3:229 0,'*/3!% 0:+!* ,!%/2#;
%!#% #' #)! <=>5 6)! ?'22'7&$+ %:(02! 3'*! *!('$%#,:#!% #)! /%! '? #)! !"# !"#!$%&'$
(!#)'* 7)!$ %',#&$+ %3',!% :$* #)!$ %@&00&$+ '1!, #)! 2'7!%# %3',! #' *&%02:9 #)! ,!%# '? #)!
%3',!%5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub skipToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles skipToolStripMenuItem.Click
Dim scores = {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
For Each score In scores.OrderBy(Function(i) i).Skip(1)
txtLog.WriteLine(score)
Next
End Sub
!"#$%&'(&/1&/'0%
private void skipToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
foreach (var score in scores.OrderBy(i=>i).Skip(1))
{
txtLog.WriteLine(score);
}
}
23%&4%+,$56
56
65
78
88
90
93
99
>$ #)&% !":(02!- #)! %3',! '? AB &% (&%%&$+ 8!3:/%! #)! !"# (!#)'* ./(0!* '1!, #):# !2!;
(!$#5
!"#$%"&'
6)! !"#'(")& !"#!$%&'$ (!#)'* &% %&(&2:, #' #)! !"# (!#)'* !"3!0# !"#'(")& :33!0#% :
0,!*&3:#! #):# #:@!% :$ !2!(!$# '? #)! 3'22!3#&'$ :$* ,!#/,$% : C''2!:$ 1:2/! #' *!#!,(&$!
7)!$ #' %#'0 %@&00&$+ '1!,5 6)! ?'22'7&$+ !":(02! 3'*! %@&0% '1!, #)! %3',!% :% 2'$+ :% #)!
%3',! &% 2!%% #):$ DE5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub skipWhileToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles skipWhileToolStripMenuItem.Click
Dim scores = {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
For Each score In scores.OrderBy(Function(i) i).SkipWhile(Function(s) s < 80)
txtLog.WriteLine(score)
!"" #$%&'() * >$#,'*/3&$+ F>GH
Next
End Sub
!"#$%&'(&/1&/'0%
private void skipWhileToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
foreach (var score in scores.OrderBy(i => i).SkipWhile(s => s < 80))
{
txtLog.WriteLine(score);
}
}
23%&4%+,$56
88
90
93
99
99
G'#! #):# &? #)! %3',!% 7!,! $'# %',#!*- #)! !"# (!#)'* 7'/2* $'# %@&0 '1!, :$9 !2!(!$#%
8!3:/%! #)! I,%# !2!(!$# JDDK &% +,!:#!, #):$ DE5
()
6)! *+ !"#!$%&'$ (!#)'* &% :$ :++,!+:#! ?/$3#&'$ #):# 3:$ 2''0 '1!, #)! %'/,3! %!4/!$3!
:$* 3:23/2:#! : #'#:2 %/( 8:%!* '$ #)! 2:(8*: !"0,!%%&'$ 0:%%!* &$#' #)&% (!#)'* #' %!2!3#
#)! 0,'0!,#9 #' 8! %/((!*5 >? #)! %!4/!$3! &% ,-.*+&/%0)& '? : $/(!,&3 #90!- *+ 3:$ 8!
!"!3/#!* 7&#)'/# : 2:(8*: !"0,!%%&'$5 6)! ?'22'7&$+ !":(02! 3'*! *&%02:9% #)! %/( '? :22
#)! %3',!%5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub sumToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles sumToolStripMenuItem.Click
Dim scores = {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
txtLog.WriteLine(scores.Sum())
End Sub
!"#$%&'(&/1&/'0%
private void sumToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
txtLog.WriteLine(scores.Sum());
}
23%&4%+,$56
714
F!%%'$ LM =$*!,%#:$*&$+ F>GH #$%&'() * !"+
*+!'
6)! $%!& !"#!$%&'$ (!#)'* ,!#,&!1!% : 0',#&'$ '? #)! %!4/!$3!5 N'/ 3:$ %0!3&?9 )'7 (:$9
!2!(!$#% 9'/ 7:$# 7&#) #)&% (!#)'*5 ># &% 3'(('$29 /%!* 7&#) #)! !"# (!#)'* #' 0,'1&*!
0:+&$+ :8&2	 ?', *:#: 8!&$+ *&%02:9!* &$ #)! <=>5 >? 9'/ #,9 #' #:@! (',! !2!(!$#% #):$ :,!
:1:&2:82!- #)! $%!& (!#)'* +,:3!?/229 ,!#/,$% 7):#!1!, &# 3:$ 7&#)'/# #),'7&$+ :$ !"3!0#&'$5
6)! ?'22'7&$+ 3'*! %:(02! %#:,#% 7&#) : 3'22!3#&'$ '? &$#!+!,% 3:22!* 123/&1- %',#% #)! 3'22!3;
#&'$- %@&0% #),!! !2!(!$#%- :$* #)!$ #:@!% #7' !2!(!$#%5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub takeToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles takeToolStripMenuItem.Click
Dim scores = {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
For Each item In scores.OrderBy(Function(i) i).Skip(3).Take(2)
txtLog.WriteLine(item)
Next
End Sub
!"#$%&'(&/1&/'0%
private void takeToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
foreach (var item in scores.OrderBy(i => i).Skip(3).Take(2))
{
txtLog.WriteLine(item);
}
}
23%&4%+,$5+6
65
78
*+!'$%"&'
O/%# :% #)! !"#'(")& !"#!$%&'$ (!#)'* !$:82!% 9'/ #' %@&0 7)&2! #)! 0,'1&*!* 0,!*&3:#!
,!#/,$% 4/*&- #)! $%!&'(")& !"#!$%&'$ (!#)'* !$:82!% 9'/ #' ,!#,&!1! !2!(!$#% ?,'( 9'/,
%!4/!$3! :% 2'$+ :% #)! 0,'1&*!* 0,!*&3:#! ,!#/,$% 4/*&5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub takeWhileToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles takeWhileToolStripMenuItem.Click
Dim scores = {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
For Each item In scores.OrderBy(Function(i) i).TakeWhile(Function(s) s < 80)
txtLog.WriteLine(item)
Next
End Sub
!"#$%&'(&/1&/'0%
private void takeWhileToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
!+, #$%&'() * >$#,'*/3&$+ F>GH
foreach (var item in scores.OrderBy(i => i).TakeWhile(s => s < 80))
{
txtLog.WriteLine(item);
}
}
23%&4%+,$56
23
23
56
65
78
*,+--+.
6)! $35//%6 !"#!$%&'$ (!#)'* !"!3/#!% #)! *!?!,,!* 4/!,9 :$* 3'$1!,#% #)! ,!%/2# #' : 3'$;
3,!#! :,,:9 '? #)! ',&+&$:2 %!4/!$3! &#!(P% #90!5 6)! ?'22'7&$+ 3'*! 3,!:#!% : 4/!,9 #' ,!#,&!1!
#)! !1!$ %3',!% :$* 3'$1!,#% #)! *!?!,,!* 4/!,9 #' :$ :,,:9 '? &$#!+!,% 3:22!* &7&. 23/&15 6)!
#)&,* %3',! &% 3):$+!* #' #7' J!1!$K :$*- 7)!$ #)! !1!$ %3',!% :,! *&%02:9!*- #)! #7' &% $'# &$
#)! :,,:95
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub toArrayToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles toArrayToolStripMenuItem.Click
Dim scores = {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
Dim evenScores = scores.Where(Function(s) s Mod 2 = 0).ToArray()
scores(2) = 2
For Each item In evenScores
txtLog.WriteLine(item)
Next
End Sub
!"#$%&'(&/1&/'0%
private void toArrayToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
var evenScores = scores.Where(s => s % 2 == 0).ToArray();
scores[2] = 2;
foreach (var item in evenScores)
{
txtLog.WriteLine(item);
}
}
23%&4%+,$56
88
56
78
90
F!%%'$ LM =$*!,%#:$*&$+ F>GH #$%&'() * !+!
*,/"0*",1+-.
6)! $38"24"3.%/6 !"#!$%&'$ (!#)'* !"!3/#!% #)! *!?!,,!* 4/!,9 :$* 3'$1!,#% #)! ,!%/2# #' :
*&3#&'$:,9 7&#) : @!9 #90! &$?!,,!* ?,'( #)! ,!#/,$ #90! '? #)! 2:(8*: 0:%%!* :% : 0:,:(!#!,5
6)! &#!( :%%'3&:#!* 7&#) : *&3#&'$:,9 !$#,9 &% #)! 1:2/! ?,'( #)! !$/(!,:#&'$ #):# 3'(0/#!%
#)! @!95
6)! ?'22'7&$+ 3'*! 3,!:#!% : 4/!,9 #' ,!#,&!1! #)! 3:,% :$* 3'$1!,#% #)!( #' : *&3#&'$:,9
'? 3:,% 7&#) #)! 14/".9 Q>G /%!* :% #)! 2''@/0 @!9 :$* :%%&+$% #)! *&3#&'$:,9 #' : 2%/1:6;".
1:,&:82!5 6)! 3:, 7&#) : Q>G '? R>OLAB &% ,!#,&!1!* :$* *&%02:9!*5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub toDictionaryToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles toDictionaryToolStripMenuItem.Click
Dim cars = GetCars()
Dim carsByVin = cars.ToDictionary(Function(c) c.VIN)
Dim myCar = carsByVin("HIJ123")
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Year:{3}", _
myCar.VIN, myCar.Make, myCar.Model, myCar.Year)
End Sub
!"#$%&'(&/1&/'0%
private void toDictionaryToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var carsByVin = cars.ToDictionary(c=>c.VIN);
Car myCar = carsByVin["HIJ123"];
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Year:{3}",
myCar.VIN, myCar.Make, myCar.Model, myCar.Year);
}
23%&4%+,$56
Car VIN:HIJ123, Make:VW, Model:Bug Year:1956
*,&" *
6)! $3<"14 !"#!$%&'$ (!#)'* !"!3/#!% #)! *!?!,,!* 4/!,9 :$* %#',!% !:3) &#!( &$ : <"14=$>
7)!,! $ &% #)! %:(! #90! :% #)! ',&+&$:2 %!4/!$3!5 6)! ?'22'7&$+ 3'*! 3,!:#!% : 4/!,9 #' ,!;
#,&!1! #)! !1!$ %3',!% :$* 3'$1!,#% #)! *!?!,,!* 4/!,9 #' : 2&%# '? &$#!+!,% 3:22!* &7&. 23/&15
6)! #)&,* %3',! &% 3):$+!* #' #7' J!1!$K :$*- 7)!$ #)! !1!$ %3',!% :,! *&%02:9!*- #)! #7' &%
$'# &$ #)! 2&%#5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub toListToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles toListToolStripMenuItem.Click
Dim scores = {88, 56, 23, 99, 65, 93, 78, 23, 99, 90}
Dim evenScores = scores.Where(Function(s) s Mod 2 = 0).ToList()
scores(2) = 2
For Each item In evenScores
txtLog.WriteLine(item)
Next
End Sub
!+- #$%&'() * >$#,'*/3&$+ F>GH
!"#$%&'(&/1&/'0%
private void toListToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] scores = { 88, 56, 23, 99, 65, 93, 78, 23, 99, 90 };
var evenScores = scores.Where(s => s % 2 == 0).ToList();
scores[2] = 2;
foreach (var item in evenScores)
{
txtLog.WriteLine(item);
}
}
23%&4%+,$56
88
56
78
90
*,&,,!(#
6)! $3<33!*# !"#!$%&'$ (!#)'* ,!#/,$% ,<33!*#=$?&6@A$-)&+&.4>S#):# &%- : %!4/!$3! '?
,B/3*#".9=$?&6@A$-)&+&.4> '8.!3#%5 6)&% &$#!,?:3! %0!3&I!% #):# #)! +,'/0&$+ '8.!3# !"0'%!%
: ?&6 0,'0!,#9 #):# ,!0,!%!$#% #)! +,'/0&$+ 1:2/!5 6)&% (!#)'* 3,!:#!% : $!7 3'22!3#&'$
'8.!3#- #)/% 0,'1&*&$+ : ?,'T!$ 1&!75 U):$+&$+ #)! ',&+&$:2 %'/,3! 3'22!3#&'$ 7&22 $'# :??!3#
#)&% 3'22!3#&'$5 6)! ?'22'7&$+ 3'*! %:(02! +,'/0% 3:,% 89 #)! C%!& 0,'0!,#95 V?#!, $3<33!*#
&% 3:22!*- #)! ',&+&$:2 3'22!3#&'$ &% 32!:,!*- 8/# &# ):% $' &(0:3# '$ #)! 3'22!3#&'$ 0,'*/3!* 89
#)! $3<33!*# (!#)'*5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub toLookupToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles toLookupToolStripMenuItem.Click
Dim cars = GetCars()
Dim query = cars.ToLookup(Function(c) c.Make)
cars.Clear()
For Each group As IGrouping(Of String, Car) In query
txtLog.WriteLine("Key:{0}", group.Key)
For Each c In group
txtLog.WriteLine("Car VIN:{0} Make:{1}", c.VIN, c.Make)
Next
Next
End Sub
!"#$%&'(&/1&/'0%
private void toLookupToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var query = cars.ToLookup(c => c.Make);
cars.Clear();
foreach (IGrouping<string, Car> group in query)
{
txtLog.WriteLine("Key:{0}", group.Key);
foreach (Car c in group)
F!%%'$ LM =$*!,%#:$*&$+ F>GH #$%&'() * !+*
{
txtLog.WriteLine("Car VIN:{0} Make:{1}", c.VIN, c.Make);
}
}
}
23%&4%+,$56
Key:Ford
Car VIN:ABC123 Make:Ford
Car VIN:DEF456 Make:Ford
Key:BMW
Car VIN:DEF123 Make:BMW
Key:Audi
Car VIN:ABC456 Make:Audi
Key:VW
Car VIN:HIJ123 Make:VW
C!3:/%! #)!,! :,! #7' W',*%- #)!9 :,! +,'/0!* #'+!#)!,5 6)! B/3*#:6 !"#!$%&'$ (!#)'*
0,'1&*!% #)! %:(! ,!%/2# !"3!0# #):# B/3*#:6 &% : *!?!,,!* 4/!,9- :$* $3<33!*# !"!3/#!%
#)! 4/!,9 &((!*&:#!29 #' ,!#/,$ : ?,'T!$ %!4/!$3! #):# 7'$P# 3):$+! !1!$ &? #)! ',&+&$:2
%!4/!$3! &% /0*:#!*5
(1",1
X'(!#&(!%- 9'/ 7:$# #' 3'(8&$! #7' 3'22!3#&'$% :$* 7',@ 7&#) #)! ,!%/2#5 C! 3:,!?/2Y #)&%
(&+)# $'# 8! #)! 3',,!3# %'2/#&'$5 N'/ (&+)# 7:$# #' /%! #)! D3.2%4 !"#!$%&'$ (!#)'*- 7)&3)
?/2I22% #)! ,!4/&,!(!$#% '? #)&% %3!$:,&'5 6)! E."3. !"#!$%&'$ (!#)'* 3'(8&$!% #)! !2!(!$#%
?,'( #7' %!4/!$3!% 8/# '/#0/#% #)! *&%#&$3# !2!(!$#%5 6):# &%- &# I2#!,% '/# */02&3:#!%5 6)&% &%
!4/&1:2!$# #' !"!3/#&$+ D3.2%4 :$* #)!$ 8"14".245 6)! ?'22'7&$+ 3'*! !":(02! 3'(8&$!% #7'
&$#!+!, :,,:9% 89 /%&$+ #)! E."3. (!#)'* :$* #)!$ %',#% #)! ,!%/2#5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub unionToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles unionToolStripMenuItem.Click
Dim lastYearScores = {88, 56, 23, 99, 65, 56}
Dim thisYearScores = {93, 78, 23, 99, 90, 99}
Dim allScores = lastYearScores.Union(thisYearScores)
For Each item In allScores.OrderBy(Function(s) s)
txtLog.WriteLine(item)
Next
End Sub
!"#$%&'(&/1&/'0%
private void unionToolStripMenuItem_Click(object sender, EventArgs e)
{
int[] lastYearScores = { 88, 56, 23, 99, 65, 56 };
int[] thisYearScores = { 93, 78, 23, 99, 90, 99 };
var allScores = lastYearScores.Union(thisYearScores);
foreach (var item in allScores.OrderBy(s=>s))
{
txtLog.WriteLine(item);
}
}
!+. #$%&'() * >$#,'*/3&$+ F>GH
23%&4%+,$56
23
56
65
78
88
90
93
99
$%'-'
6)! '(&/& !"#!$%&'$ (!#)'* !$:82!% 9'/ #' I2#!, : %'/,3! %!4/!$3!5 6)&% (!#)'* :3;
3!0#% : 0,!*&3:#! 2:(8*: !"0,!%%&'$5 Z)!$ 7',@&$+ 7&#) ,!2:#&'$:2 *:#:8:%!%- #)&% !"#!$%&'$
(!#)'* #90&3:229 #,:$%2:#!% #' : XHF ZR[\[ 32:/%!5 6)! ?'22'7&$+ %:(02! 3'*! *!('$%#,:#!%
#)! /%! '? #)! '(&/& (!#)'* 7&#) : %!4/!$3! '? 3:,% #):# :,! I2#!,!* '$ C%!& 8!&$+ !4/:2
#' F3/G5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub whereToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles whereToolStripMenuItem.Click
Dim cars = GetCars()
For Each myCar In cars.Where(Function(c) c.Make = "Ford")
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Year:{3}", _
myCar.VIN, myCar.Make, myCar.Model, myCar.Year)
Next
End Sub
!"#$%&'(&/1&/'0%
private void whereToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
foreach (var myCar in cars.Where(c => c.Make == "Ford"))
{
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Year:{3}",
myCar.VIN, myCar.Make, myCar.Model, myCar.Year);
}
}
23%&4%+,$56
Car VIN:ABC123, Make:Ford, Model:F-250 Year:2000
Car VIN:DEF456, Make:Ford, Model:F-150 Year:1998
2"#
6)! H"# !"#!$%&'$ (!#)'* (!,+!% #7' %!4/!$3!%5 6)&% &% $!&#)!, E."3. $', D3.2%4 8!3:/%!
#)! ,!%/2#&$+ !2!(!$# 3'/$# &% !4/:2 #' #)! (&$&(/( 3'/$# '? #)! #7' %!4/!$3!%5 [2!(!$# L
'? %!4/!$3! L &% (:#!* #' !2!(!$# L '? %!4/!$3! A- :$* 9'/ 0,'1&*! : 2:(8*: !"0,!%%&'$ #'
*!I$! 7)&3) @&$* '? '/#0/# #' 3,!:#! 8:%!* '$ #)&% (:#&$+5 [2!(!$# A '? %!4/!$3! L &% #)!$
(:#!* #' !2!(!$# A '? %!4/!$3! A :$* %' '$ /$#&2 '$! '? #)! %!4/!$3!% ,/$% '/# '? !2!(!$#%5
F!%%'$ LM =$*!,%#:$*&$+ F>GH #$%&'() * !+/
6)! ?'22'7&$+ %:(02! 3'*! %#:,#% 7&#) : $/(8!, %!4/!$3!- /%&$+ : %#:,#&$+ 1:2/! '? I :$*
:$ !$*&$+ 1:2/! '? IJJJ5 6)! %!3'$* %!4/!$3! &% : 3'22!3#&'$ '? D%/ '8.!3#%5 6)! H"# !"#!$;
%&'$ (!#)'* 0,'*/3!% :$ '/#0/# 3'22!3#&'$ '? :$'$9('/% '8.!3#% #):# 3'$#:&$ #)! &$*!"
$/(8!, :$* #)! 3:,5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub zipToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles zipToolStripMenuItem.Click
Dim numbers = Enumerable.Range(1, 1000)
Dim cars = GetCars()
Dim zip = numbers.Zip(cars, _
Function(i, c) New With {.Number = i, .CarMake = c.Make})
For Each item In zip
txtLog.WriteLine("Number:{0} CarMake:{1}", item.Number, item.CarMake)
Next
End Sub
!"#$%&'(&/1&/'0%
private void zipToolStripMenuItem_Click(object sender, EventArgs e)
{
var numbers = Enumerable.Range(1, 1000);
var cars = GetCars();
var zip = numbers.Zip(cars, (i, c) => new {
Number = i, CarMake = c.Make });
foreach (var item in zip)
{
txtLog.WriteLine("Number:{0} CarMake:{1}", item.Number, item.CarMake);
}
}
23%&4%+,$56
Number:1 CarMake:Ford
Number:2 CarMake:BMW
Number:3 CarMake:Audi
Number:4 CarMake:VW
Number:5 CarMake:Ford
6)! !$*&$+ ,:$+! '? IJJJ '$ #)! I,%# %!4/!$3! 7:% %'(!7):# :,8&#,:,9 8/# &% $'#&3!:829
)&+)!, #):$ #)! 4/:$#	 '? D%/ '8.!3#% &$ #)! %!3'$* %!4/!$3!5 Z)!$ #)! %!3'$* %!4/!$3!
,:$ '/# '? !2!(!$#%- #)! H"# (!#)'* %#'00!* 0,'*/3&$+ '/#0/#5 >? #)! !$*&$+ ,:$+! '? #)!
I,%# %!4/!$3! 7:% %!# #' B- '$29 #),!! !2!(!$#% 7'/2* 8! '/#0/# 8!3:/%! #)! I,%# %!4/!$3!
7'/2* ,/$ '/# '? !2!(!$#%5
!"#$%&$' 0123456 7489 :;<=>(5?@A456 BC?8D2CE
>$ #)&% 0,:3#&3!- 9'/ 3,!:#! : %&(02! Q!)&32! Z!8 :002&3:#&'$ 7&#) : 1!)&32!% 3'22!3#&'$ #):#
&% : +!$!,&3 2&%# '? ;&("2)&5 6)&% 2&%# 7&22 8! 0'0/2:#!* 7&#) %'(! 1!)&32!% #' /%! '8.!3# &$&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5&('4&53%&$'.!5*':A&*5@+&8%.!,+%&?',4&)*+,!$& 5,0*'&BCD2&+%55*:E+A&
+%5&,#&5'&%:!8$%&?',&5'&!8'45&53%'F%.5A&!,5'"!5*.!$$?&4%"'G%&!$$&H$%+&(4'"&?',4&3!40&
04*G%B&2'&+%$%.5&!&$'.!5*':A&+*"#$?&.3''+%&I*$%&J& !G%&9$$&!(5%4&53%'F%.5&3!+&8%%:&.4%K
!5%0B&2'&.3!:E%&53*+&+%55*:EA&.3''+%&2''$+&J&L#5*':+&J&M4'F%.5+&9:0& '$,5*':+&J& !G%&C%;&
M4'F%.5+&73%:&/4%!5%0B&73%:&53*+&'#5*':&*+&+%$%.5%0A&?',&!4%'"#5%0&('4&!&$'.!5*':&
;3%:&?',&.4%!5%&53%'F%.5B
6)!,! :,! #7' 3'$#!$# #:+%- '$! 3:22!* K&%G&/D3.4&.4 :$* '$! 3:22!* :3G6D3.4&.45
6)! :3G6D3.4&.4 #:+ 3/,,!$#29 ):% *!?:/2# (:,@/0 #' *&%02:9 : 7!23'(! (!%%:+! :$*
)!20 2&$@5
.+ >? 9'/ ):1!$P# %!!$ #)&% Z!8 V002&3:#&'$ #!(02:#! 8!?',!- 3)''%! ]!8/+ ^ X#:,#
]!8/++&$+ #' 8/&2* :$* ,/$ #)&% Z!8 :002&3:#&'$ %' #):# 9'/ 3:$ %!! #)! *!?:/2# #!(;
02:#!5 V?#!, ,/$$&$+ #)! :002&3:#&'$- +' 8:3@ #' #)! ]!?:/2#5:%0" (:,@/05
/+ ]!2!#! #)! (:,@/0 #):#P% &$ #)! :3G6D3.4&.4 #:+5
0+ _'0/2:#! #)! :3G6D3.4&.4 #:+ 7&#) #)! ?'22'7&$+ (:,@/0- 7)&3) 7&22 *&%02:9 I2#!, :$*
%',# 3,&#!,&: :$* 0,'1&*! :$ !"!3/#! 8/##'$ :$* : +,&* #' *&%02:9 1!)&32!%5
9 MN&O!4P,#
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="lblVin" runat="server" Width="100px" Text="VIN: "></asp:Label>
<asp:TextBox ID="txtVin" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblMake" runat="server" Width="100px" Text="Make: "></
!"# K;JJ;<L '$( &)MK&' BM) '$( :M#%';M<
>(&?',&0':@5&+%%&!'"#5&('4&53%&$'.!5*':A&*5@+&8%.!,+%&?',4&)*+,!$& 5,0*'&BCD2&+%55*:E+A&
+%5&,#&5'&%:!8$%&?',&5'&!8'45&53%'F%.5A&!,5'"!5*.!$$?&4%"'G%&!$$&H$%+&(4'"&?',4&3!40&
04*G%B&2'&+%$%.5&!&$'.!5*':A&+*"#$?&.3''+%&I*$%&J& !G%&9$$&!(5%4&53%'F%.5&3!+&8%%:&.4%K
!5%0B&2'&.3!:E%&53*+&+%55*:EA&.3''+%&2''$+&J&L#5*':+&J&M4'F%.5+&9:0& '$,5*':+&J& !G%&C%;&
M4'F%.5+&73%:&/4%!5%0B&73%:&53*+&'#5*':&*+&+%$%.5%0A&?',&!4%'"#5%0&('4&!&$'.!5*':&
;3%:&?',&.4%!5%&53%'F%.5B
F!%%'$ LM =$*!,%#:$*&$+ F>GH #$%&'() * !+N
asp:Label>
<asp:TextBox ID="txtMake" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblModel" runat="server" Width="100px" Text="Model: "></
asp:Label>
<asp:TextBox ID="txtModel" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblYear" runat="server" Width="100px" Text="Year: "></
asp:Label>
<asp:DropDownList ID="ddlYear" runat="server">
<asp:ListItem Text="All Years" Value="0" />
<asp:ListItem Text="> 1995" Value="1995" />
<asp:ListItem Text="> 2000" Value="2000" />
<asp:ListItem Text="> 2005" Value="2005" />
</asp:DropDownList>
<br />
<asp:Label ID="lblCost" runat="server" Width="100px" Text="Cost: "></
asp:Label>
<asp:DropDownList ID="ddlCost" runat="server">
<asp:ListItem Text="Any Cost" Value="0" />
<asp:ListItem Text="> 5000" Value="5000" />
<asp:ListItem Text="> 20000" Value="20000" />
</asp:DropDownList>
<br />
<asp:Label ID="lblSort" runat="server" Width="100px" Text="Sort Order: "></
asp:Label>
<asp:DropDownList ID="ddlSort" runat="server">
<asp:ListItem Text="" />
<asp:ListItem Text="VIN" />
<asp:ListItem Text="Make" />
<asp:ListItem Text="Model" />
<asp:ListItem Text="Year" />
<asp:ListItem Text="Cost" />
</asp:DropDownList>
<br />
<br />
<asp:Button ID="btnExecute" runat="server" Text="Execute" />
<br />
<asp:GridView ID="gvVehicles" runat="server">
</asp:GridView>
</asp:Content>
>? 9'/ 32&3@ #)! ]!%&+$ #:8 J8'##'( 2!?#K- 9'/ %)'/2* %!! #)! ,!$*!,!* %3,!!$ :% %)'7$
&$ W&+/,! B;b5
!+" #$%&'() * >$#,'*/3&$+ F>GH
B;LO)( *>/ 6)&% &% #)! ,!$*!,!* %3,!!$ %)'7&$+ ?&2#!, :$* %',# %!##&$+%5
1+ \&+)#;32&3@ #)! ]!%&+$ ', c:,@/0 7&$*'7 :$* 32&3@ Q&!7 U'*!5 6)&% #:@!% 9'/ #' #)!
3'*!;8!)&$* 0:+!5 6)!,! &% :2,!:*9 : L%9&M<3%G !1!$# ):$*2!, (!#)'*5
2+ C!?',! :**&$+ 3'*! #' #)! L%9&M<3%G (!#)'*- 9'/ (/%# :** %'(! 32:%%!% #' #)! 0,'.;
!3#5 >$ X'2/#&'$ ["02',!,- ,&+)#;32&3@ #)! Q!)&32!_,'.!3# &3'$- 32&3@ V**- :$* #)!$ 32&3@
U2:%%5 G:(! #)! 32:%% GC94HAC :$* 32&3@ V**5 V** #)! ?'22'7&$+ 3'*! #' #)&% 32:%%5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Class Vehicle
Public Property VIN As String
Public Property Make As String
Public Property Model As String
Public Property Year As Integer
Public Property Cost As Decimal
End Class
!"#$%&'(&/1&/'0%
public class Vehicle
{
public string VIN { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public decimal Cost { get; set; }
}
F!%%'$ LM =$*!,%#:$*&$+ F>GH #$%&'() * !++
3+ V** :$'#)!, 32:%%- $:(!* #?2- #):# &$)!,&#% ?,'( ;&("2)&- :% %)'7$ &$ #)! ?'22'7&$+
3'*! %:(02!M
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Class Car
Inherits Vehicle
End Class
!"#$%&'(&/1&/'0%
public class Car : Vehicle
{
}
*4+ V** :$'#)!, 32:%%- $:(!* '2DH3- #):# &$)!,&#% ?,'( ;&("2)&@ :% %)'7$ &$ #)! ?'22'7&$+
3'*! %:(02!M
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Class Truck
Inherits Vehicle
End Class
!"#$%&'(&/1&/'0%
public class Truck : Vehicle
{
}
**+ V** :$'#)!, 32:%%- $:(!* P1?8- #):# &$)!,&#% ?,'( ;&("2)&- :% %)'7$ &$ #)! ?'22'7&$+
3'*! %:(02!M
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Class Boat
Inherits Vehicle
End Class
!"#$%&'(&/1&/'0%
public class Boat : Vehicle
{
}
*,+ V8'1! L%9&M<3%G J:# #)! 32:%% 2!1!2K- :** 3'*! #' *!32:,! : 1:,&:82! 3:22!* QC94HACE
:$* &$%#:$#&:#! &# :% : $!7 :4E8 MR GC94HACE5 N'/, 3'*! %)'/2* 2''@ 2&@! #)! ?'22'7&$+
%:(02!5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Shared Vehicles As New List(Of Vehicle)
!"#$%&'(&/1&/'0%
private List<Vehicle> vehicles = new List<Vehicle>();
-,, #$%&'() * >$#,'*/3&$+ F>GH
*-+ >$ #)! L%9&M<3%G (!#)'*- :** 3'*! #' 3,!:#! : +!$!,&3 2&%# '? ;&("2)&5 _'0/2:#! #)!
2&%# 7&#) #!$ 1!)&32!%- 7)&3) 7&22 +&1! 9'/ %'(!#)&$+ 7&#) 7)&3) #' !"0!,&(!$# &$ #)&%
0,:3#&3!5 6)! L%9&M<3%G (!#)'* %)'/2* 2''@ 2&@! #)! ?'22'7&$+ !":(02!M
!"#$%&'(&)*+,!$&-!+*.&/'0%
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
If (Vehicles.Count = 0) Then
Vehicles.Add(New Truck With {.VIN = "AAA123", .Make = "Ford", _
.Model = "F-250", .Cost = 2000, .Year = 1998})
Vehicles.Add(New Truck With {.VIN = "ZZZ123", .Make = "Ford", _
.Model = "F-150", .Cost = 10000, .Year = 2005})
Vehicles.Add(New Car With {.VIN = "FFF123", .Make = "VW", _
.Model = "Bug", .Cost = 2500, .Year = 1997})
Vehicles.Add(New Boat With {.VIN = "LLL123", .Make = "SeaRay", _
.Model = "Signature", .Cost = 12000, .Year = 1995})
Vehicles.Add(New Car With {.VIN = "CCC123", .Make = "BMW", _
.Model = "Z-3", .Cost = 21000, .Year = 2005})
Vehicles.Add(New Car With {.VIN = "EEE123", .Make = "Ford", _
.Model = "Focus", .Cost = 15000, .Year = 2008})
Vehicles.Add(New Boat With {.VIN = "QQQ123", .Make = "ChrisCraft", _
.Model = "BowRider", .Cost = 102000, .Year = 1945})
Vehicles.Add(New Truck With {.VIN = "PPP123", .Make = "Ford", _
.Model = "F-250", .Cost = 1000, .Year = 1980})
Vehicles.Add(New Car With {.VIN = "TTT123", .Make = "Dodge", _
.Model = "Viper", .Cost = 95000, .Year = 2007})
Vehicles.Add(New Car With {.VIN = "DDD123", .Make = "Mazda", _
.Model = "Miata", .Cost = 20000, .Year = 2005})
End If
End Sub
!"#$%&'(&/1&/'0%
protected void Page_Load(object sender, EventArgs e)
{
if (vehicles.Count == 0)
{
vehicles.Add(new Truck {VIN = "AAA123", Make = "Ford",
Model = "F-250", Cost = 2000, Year = 1998});
vehicles.Add(new Truck {VIN = "ZZZ123", Make = "Ford",
Model = "F-150", Cost = 10000, Year = 2005});
vehicles.Add(new Car {VIN = "FFF123", Make = "VW",
Model = "Bug", Cost = 2500, Year = 1997});
vehicles.Add(new Boat {VIN = "LLL123", Make = "SeaRay",
Model = "Signature", Cost = 12000, Year = 1995});
vehicles.Add(new Car {VIN = "CCC123", Make = "BMW",
Model = "Z-3", Cost = 21000, Year = 2005});
vehicles.Add(new Car {VIN = "EEE123", Make = "Ford",
Model = "Focus", Cost = 15000, Year = 2008});
vehicles.Add(new Boat {VIN = "QQQ123", Make = "ChrisCraft",
Model = "BowRider", Cost = 102000, Year = 1945});
vehicles.Add(new Truck {VIN = "PPP123", Make = "Ford",
Model = "F-250", Cost = 1000, Year = 1980});
vehicles.Add(new Car {VIN = "TTT123", Make = "Dodge",
Model = "Viper", Cost = 95000, Year = 2007});
F!%%'$ LM =$*!,%#:$*&$+ F>GH #$%&'() * -,!
vehicles.Add(new Car {VIN = "DDD123", Make = "Mazda",
Model = "Miata", Cost = 20000, Year = 2005});
}
}
*.+ =$*!, #)! 3'*! 9'/ ./%# :**!* &$#' #)! L%9&M<3%G (!#)'*- &$%!,# 3'*! #' I2#!, #)! 2&%#
'? 1!)&32!% 8:%!* '$ #)! *:#: &$0/#5 =%! +&4(3GA2(%".".9 #' 3,!:#! '$! %#:#!(!$# #):#
0/#% #'+!#)!, :22 #)! I2#!,&$+- :% %)'7$ &$ #)! ?'22'7&$+ 3'*! %:(02!M
!"#$%&'(&)*+,!$&-!+*.&/'0%
Dim result = Vehicles _
.Where(Function(v) v.VIN.StartsWith(txtVin.Text)) _
.Where(Function(v) v.Make.StartsWith(txtMake.Text)) _
.Where(Function(v) v.Model.StartsWith(txtModel.Text)) _
.Where(Function(v) v.Cost > Decimal.Parse(ddlCost.SelectedValue)) _
.Where(Function(v) v.Year > Integer.Parse(ddlYear.SelectedValue))
!"#$%&'(&/1&/'0%
var result = vehicles
.Where(v => v.VIN.StartsWith(txtVin.Text))
.Where(v => v.Make.StartsWith(txtMake.Text))
.Where(v => v.Model.StartsWith(txtModel.Text))
.Where(v => v.Cost > Decimal.Parse(ddlCost.SelectedValue))
.Where(v => v.Year > int.Parse(ddlYear.SelectedValue));
*/+ =$*!, #)! 3'*! 9'/ ./%# :**!* &$#' #)! L%9&M<3%G (!#)'*- :** 3'*! #' 0!,?',( :
%',# '? #)! ,!%/2#%5 6)&% 3'*! 3:22% : &4N/G&/ (!#)'* #):# 7&22 8! 3,!:#!* &$ #)! $!"#
%#!05 N'/ 3'*! %)'/2* 2''@ 2&@! #)! ?'22'7&$+M
!"#$%&'(&)*+,!$&-!+*.&/'0%
result = SetOrder(ddlSort.SelectedValue, result)
!"#$%&'(&/1&/'0%
result = SetOrder(ddlSort.SelectedValue, result);
*0+ V** #)! &4N/G&/ (!#)'*- 7)&3) ):% 3'*! #' :** :$ N/G&/:6 4/!,9 !"#!$%&'$ (!#);
'* 8:%!* '$ #)! %!2!3#&'$ 0:%%!* &$#' #)&% (!#)'*5 N'/, 3'*! %)'/2* 2''@ 2&@! #)!
?'22'7&$+M
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Function SetOrder(ByVal order As String, _
ByVal query As IEnumerable(Of Vehicle)) As IEnumerable(Of Vehicle)
Select Case order
Case "VIN"
Return query.OrderBy(Function(v) v.VIN)
Case "Make"
Return query.OrderBy(Function(v) v.Make)
Case "Model"
Return query.OrderBy(Function(v) v.Model)
Case "Year"
Return query.OrderBy(Function(v) v.Year)
Case "Cost"
Return query.OrderBy(Function(v) v.Cost)
-,- #$%&'() * >$#,'*/3&$+ F>GH
Case Else
Return query
End Select
End Function
!"#$%&'(&/1&/'0%
private IEnumerable<Vehicle> SetOrder(string order,
IEnumerable<Vehicle> query)
{
switch (order)
{
case "VIN":
return query.OrderBy(v => v.VIN);
case "Make":
return query.OrderBy(v => v.Make);
case "Model":
return query.OrderBy(v => v.Model);
case "Year":
return query.OrderBy(v => v.Year);
case "Cost":
return query.OrderBy(v => v.Cost);
default:
return query;
}
}
*1+ W&$:229- :** 3'*! &$#' #)! 8'##'( '? #)! L%9&M<3%G (!#)'* #' %!2!3# :$ :$'$9('/%
#90! #):# &$32/*!% :$ &$*!" :$* :22 #)! 0,'0!,#&!% &$ #)! ;&("2)& 32:%% :$* 8&$* #)!
,!%/2# #' 97;&("2)&15 N'/ 3'*! %)'/2* 2''@ 2&@! #)! ?'22'7&$+ !":(02!M
!"#$%&'(&)*+,!$&-!+*.&/'0%
gvVehicles.DataSource = result.Select(Function(v, i) New With
{.Index = i, v.VIN, v.Make, v.Model, v.Year, v.Cost})
gvVehicles.DataBind()
!"#$%&'(&/1&/'0%
gvVehicles.DataSource = result.Select((v, i)=> new
{Index = i, v.VIN, v.Make, v.Model, v.Year, v.Cost});
gvVehicles.DataBind();
*2+ U)''%! C/&2* ^ C/&2* X'2/#&'$ #' 8/&2* #)! :002&3:#&'$5 >? 9'/ ):1! !,,',%- 9'/ 3:$
*'/82!;32&3@ #)! !,,', #' +' #' #)! !,,', 2&$! :$* 3',,!3#5
*3+ U)''%! ]!8/+ ^ X#:,# ]!8/++&$+ #' ,/$ #)! :002&3:#&'$5 Z)!$ #)! :002&3:#&'$ %#:,#%-
9'/ %)'/2* %!! : Z!8 0:+! 7&#) 9'/, <=> 3'$#,'2% #):# !$:82!% 9'/ #' %0!3&?9 I2#!,
:$* %',# 3,&#!,&:5 >? 9'/ #90! #)! 2!##!, B &$#' #)! c:@! #!"# 8'" :$* 32&3@ ["!3/#!- #)!
+,&* 7&22 8! 0'0/2:#!* '$29 7&#) &#!(% #):# 8!+&$ 7&#) W5 >? 9'/ %!# #)! %',# ',*!, :$*
32&3@ #)! ["!3/#! 8/##'$ :+:&$- 9'/ 7&22 %!! #)! %',#!* ,!%/2#%5
F!%%'$ LM =$*!,%#:$*&$+ F>GH #$%&'() * -,*
Q%++':& ,""!4?6)&% 2!%%'$ 0,'1&*!* *!#:&2!* &$?',(:#&'$ :8'/# #)! ?!:#/,!% #):# 3'(0,&%! F>GH5
■ `8.!3# &$&#&:2&T!,% !$:82! 9'/ #' &$&#&:2&T! 0/82&3 0,'0!,#&!% :$* I!2*% 7&#)'/# 3,!:#&$+
:$ !"02&3&# 3'$%#,/3#',5
■ >(02&3 #90!* 2'3:2 1:,&:82!% !$:82! 9'/ #' *!32:,! : 1:,&:82! 7&#)'/# %0!3&?9&$+ &#%
#90!- :$* #)! 3'(0&2!, 7&22 &$?!, #)! #90! ?', 9'/5
■ >$ (:$9 3:%!%- /%&$+ &(02&3 #90!* 2'3:2 1:,&:82!% &% :$ '0#&'$- 8/#- 7)!$ 7',@&$+
7&#) :$'$9('/% #90!%- &#P% : ,!4/&,!(!$#5
■ V$'$9('/% #90!% !$:82! 9'/ #' 3,!:#! : #90! &$2&$!5 6)&% !$:82!% 9'/ #' +,'/0 *:#:
7&#)'/# 3,!:#&$+ : 32:%%5
■ F:(8*: !"0,!%%&'$% 0,'1&*! : (/3) (',! :88,!1&:#!* %9$#:" #):$ : (!#)'* ',
:$'$9('/% (!#)'* :$* 3:$ 8! /%!* 7)!,!1!, : *!2!+:#! &% !"0!3#!*5
■ ["#!$%&'$ (!#)'*% !$:82! 9'/ #' :** (!#)'*% #' : #90! !1!$ 7)!$ 9'/ *'$P# ):1!
#)! %'/,3! 3'*! ?', #)! #90!5
■ ["#!$%&'$ (!#)'*% !$:82! 9'/ #' 3,!:#! 3'$3,!#! (!#)'*% '$ &$#!,?:3!%Y #):# &%- :22
#90!% #):# &(02!(!$# #)! &$#!,?:3! 7&22 +!# #)!%! (!#)'*%5
■ H/!,9 !"#!$%&'$ (!#)'*% :,! !"#!$%&'$ (!#)'*% 0,&(:,&29 &(02!(!$#!* '$ #)! +!;
$!,&3 ,-.*+&/%0)& &$#!,?:3!5
■ 6)! -.*+&/%0)& 32:%% 3'$#:&$% #)! 4/!,9 !"#!$%&'$ (!#)'*% :$* %#:#&3 (!#)'*% 3:22!*
-+#46- O%.9&- :$* O&#&%45
Q%++':&R%G*%;N'/ 3:$ /%! #)! ?'22'7&$+ 4/!%#&'$% #' #!%# 9'/, @$'72!*+! '? #)! &$?',(:#&'$ &$ F!%%'$ L-
d=$*!,%#:$*&$+ F>GH5e 6)! 4/!%#&'$% :,! :2%' :1:&2:82! '$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,&:82! 7)'%! #90! &%
<"14ANPAD%/5 R'7 3:$ 9'/ 3'$1!,# #)! ,-.*+&/%0)& '? D%/ #' <"14ANPAD%/f
#+ =%! D$6#& JUg 2%14K5
5+ ># 3:$P# 8! *'$!5
$+ =%! #)! $3<"14JK 4/!,9 !"#!$%&'$ (!#)'*5
6+ O/%# (:@! #)! :%%&+$(!$#5
F!%%'$ AM =%&$+ F>GH H/!,&!% #$%&'() * -,/
:CEE15 -S OE456 :;<= =DC24CE
6)! 0,!1&'/% %!3#&'$% 3'1!,!* '8.!3# &$&#&:2&T!,%- &(02&3 #90!* 2'3:2 1:,&:82!%- :$'$9('/%
#90!%- 2:(8*: !"0,!%%&'$%- :$* !"#!$%&'$ (!#)'*%5 6)!%! ?!:#/,!% 7!,! 3,!:#!* #' %/00',#
#)! &(02!(!$#:#&'$ '? F>GH5 G'7 #):# 9'/P1! %!!$ :22 #)!%!- 2''@ :# )'7 F>GH &% )%.9*%9&A
".4&9/%4&G5
9(5%4&53*+&$%++':A&?',&;*$$&8%&!8$%&5'6
■ >*!$#&?9 #)! F>GH @!97',*%5
■ U,!:#! : F>GH 4/!,9 #):# 0,'1&*!% I2#!,&$+5
■ U,!:#! : F>GH 4/!,9 #):# 0,'1&*!% %',#!* ,!%/2#%5
■ U,!:#! : F>GH 4/!,9 #' 0!,?',( :$ &$$!, .'&$ '$ #7' !2!(!$# %!4/!$3!%5
■ U,!:#! : F>GH 4/!,9 #' 0!,?',( :$ '/#!, .'&$ '$ #7' !2!(!$# %!4/!$3!%5
■ >(02!(!$# +,'/0&$+ :$* :++,!+:#&'$ &$ : F>GH 4/!,95
■ U,!:#! : F>GH 4/!,9 #):# *!I$!% :**&#&'$ 2''0 1:,&:82!% /%&$+ #)! )&4 @!97',*5
■ U,!:#! : F>GH 4/!,9 #):# &(02!(!$#% 0:+&$+5
D+5*"!5%0&$%++':&5*"%6&WX&"*:,5%+
?:5!TK-!+%0&!:0&O%53'0K-!+%0&Y,%4*%+W', 8:%&3 4/!,&!%- /%&$+ F>GH &$ Q&%/:2 C:%&3 ', Ug &% 1!,9 !:%9 :$* &$#/&#&1! 8!3:/%! 8'#) 2:$;
+/:+!% 0,'1&*! @!97',*% #):# (:0 *&,!3#29 #' ?!:#/,!% #):# ):1! 8!!$ :**!* #),'/+) !"#!$;
%&'$ (!#)'*%5 6)! 8!$!I# &% #):# 9'/ 3:$ 7,&#! #90!* 4/!,&!% &$ : 1!,9 XHF;2&@! 7:9- +!##&$+
>$#!22&X!$%! %/00',# :22 :2'$+ #)! 7:95
>$ #)! ?'22'7&$+ %3!$:,&'- 9'/, %3)!*/2! 3'$#:&$% : 2&%# '? *:9% 7)!$ 9'/ :,! 8/%9- :$* 9'/
7:$# #' I$* '/# 7)!#)!, 9'/ :,! 8/%9 '$ : %0!3&I3 *:95 6)! ?'22'7&$+ 3'*! *!('$%#,:#!% #)!
&(02!(!$#:#&'$ '? : F>GH 4/!,9 #' *&%3'1!, #)&%5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Function GetDates() As List(Of DateTime)
Return New List(Of DateTime) From
{
New DateTime(11, 1, 1),
New DateTime(11, 2, 5),
New DateTime(11, 3, 3),
New DateTime(11, 1, 3),
New DateTime(11, 1, 2),
New DateTime(11, 5, 4),
New DateTime(11, 2, 2),
New DateTime(11, 7, 5),
New DateTime(11, 6, 30),
New DateTime(11, 10, 14),
New DateTime(11, 11, 22),
9(5%4&53*+&$%++':A&?',&;*$$&8%&!8$%&5'6
■ >*!$#&?9 #)! F>GH @!97',*%5
■ U,!:#! : F>GH 4/!,9 #):# 0,'1&*!% I2#!,&$+5
■ U,!:#! : F>GH 4/!,9 #):# 0,'1&*!% %',#!* ,!%/2#%5
■ U,!:#! : F>GH 4/!,9 #' 0!,?',( :$ &$$!, .'&$ '$ #7' !2!(!$# %!4/!$3!%5
■ U,!:#! : F>GH 4/!,9 #' 0!,?',( :$ '/#!, .'&$ '$ #7' !2!(!$# %!4/!$3!%5
■ >(02!(!$# +,'/0&$+ :$* :++,!+:#&'$ &$ : F>GH 4/!,95
■ U,!:#! : F>GH 4/!,9 #):# *!I$!% :**&#&'$ 2''0 1:,&:82!% /%&$+ #)! )&4 @!97',*5)&4
■ U,!:#! : F>GH 4/!,9 #):# &(02!(!$#% 0:+&$+5
D+5*"!5%0&$%++':&5*"%6&WX&"*:,5%+
-,F #$%&'() * >$#,'*/3&$+ F>GH
New DateTime(11, 12, 1),
New DateTime(11, 5, 22),
New DateTime(11, 6, 7),
New DateTime(11, 1, 4)
}
End Function
Private Sub BasicQueriesToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles BasicQueriesToolStripMenuItem.Click
Dim schedule = GetDates()
Dim areYouAvailable = new DateTime(11, 7, 10)
Dim busy = From d In schedule
Where d = areYouAvailable
Select d
For Each busyDate In busy
txtLog.WriteLine("Sorry, but I am busy on {0:MM/dd/yy}", busyDate)
Next
End Sub
!"#$%&'(&/1&/'0%
private List<DateTime> GetDates()
{
return new List<DateTime>
{
new DateTime(11, 1, 1),
new DateTime(11, 2, 5),
new DateTime(11, 3, 3),
new DateTime(11, 1, 3),
new DateTime(11, 1, 2),
new DateTime(11, 5, 4),
new DateTime(11, 2, 2),
new DateTime(11, 7, 5),
new DateTime(11, 6, 30),
new DateTime(11, 10, 14),
new DateTime(11, 11, 22),
new DateTime(11, 12, 1),
new DateTime(11, 5, 22),
new DateTime(11, 6, 7),
new DateTime(11, 1, 4)
};
}
private void basicLINQToolStripMenuItem_Click(object sender, EventArgs e)
{
var schedule = GetDates();
var areYouAvailable = new DateTime(11,7, 5);
var busy = from d in schedule
where d == areYouAvailable
select d;
foreach(var busyDate in busy)
F!%%'$ AM =%&$+ F>GH H/!,&!% #$%&'() * -,N
{
txtLog.WriteLine("Sorry, but I am busy on {0:MM/dd/yy}", busyDate);
}
}
>$ #)! %:(02! 3'*!- : F>GH 4/!,9 I2#!,!* #)! *:#:- 7)&3) ,!#/,$!* :$
,-.*+&/%0)&=8%4&$"+&> '8.!3# :% #)! ,!%/2#5 >% #)!,! : %&(02!, 7:9 #' 0!,?',( #)&% 4/!,9f
N'/ 3'/2* :,+/! #):# /%&$+ #)! '(&/& !"#!$%&'$ (!#)'* 7'/2* %:1! %'(! 3'*&$+ :$* 7'/2*
8! %&(02!,- :% %)'7$ &$ #)&% (!#)'*;8:%!* 3'*! %:(02!M
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub MethodbasedQueryToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MethodbasedQueryToolStripMenuItem.Click
Dim schedule = GetDates()
Dim areYouAvailable = New DateTime(11,7,5)
For Each busyDate In schedule.Where(Function(d) d = areYouAvailable)
txtLog.WriteLine("Sorry, but I am busy on {0:MM/dd/yy}", busyDate)
Next
End Sub
!"#$%&'(&/1&/'0%
private void methodbasedQueryToolStripMenuItem_Click(object sender, EventArgs e)
{
var schedule = GetDates();
var areYouAvailable = new DateTime(11,7,5);
foreach (var busyDate in schedule.Where(d=>d==areYouAvailable))
{
txtLog.WriteLine("Sorry, but I am busy on {0:MM/dd/yy}", busyDate);
}
}
6)&% !":(02! !2&(&$:#!% #)! F>GH 4/!,9 :$* :**% #)! '(&/& !"#!$%&'$ (!#)'* &$ #)!
2''05 6)&% 3'*! 82'3@ &% %(:22!, :$* (',! 3'$3&%!- 8/# 7)&3) &% (',! ,!:*:82!f ]!3&*! ?',
9'/,%!2?5 W', : %(:22 4/!,9 %/3) :% #)&%- #)! !"#!$%&'$ (!#)'* (&+)# 8! I$!- 8/# ?', 2:,+!,
4/!,&!%- 9'/ 0,'8:829 7&22 I$* &# 8!##!, #' /%! #)! F>GH 4/!,95 _!,?',(:$3! &% #)! %:(! 8!;
3:/%! 8'#) 4/!,&!% *' #)! %:(! #)&$+5
`$29 : %(:22 %/8%!# '? #)! 4/!,9 !"#!$%&'$ (!#)'*% (:0 #' 2:$+/:+! @!97',*%- %' #90&;
3:229 9'/ 7&22 I$* 9'/,%!2? (&"&$+ F>GH 4/!,&!% 7&#) !"#!$%&'$ (!#)'*%- :% %)'7$ &$ #)!
?'22'7&$+ ,!7,&#! '? #)! 0,!1&'/% !":(02!%M
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub MixingLINQAndMethodsToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MixingLINQAndMethodsToolStripMenuItem.Click
Dim schedule = GetDates()
-," #$%&'() * >$#,'*/3&$+ F>GH
Dim areYouAvailable = New DateTime(11, 7, 5)
Dim count = (From d In schedule
Where d = areYouAvailable
Select d).Count()
If count > 0 Then
txtLog.WriteLine("Sorry, but I am busy on {0:MM/dd/yy}", areYouAvailable)
Else
txtLog.WriteLine("Yay! I am available on {0:MM/dd/yy}", areYouAvailable)
End If
End Sub
!"#$%&'(&/1&/'0%
private void mixingLINQAndMethodsToolStripMenuItem_Click(
object sender, EventArgs e)
{
var schedule = GetDates();
var areYouAvailable = new DateTime(11, 7, 5);
var count = (from d in schedule
where d == areYouAvailable
select d).Count();
if (count > 0)
txtLog.WriteLine("Sorry, but I am busy on {0:MM/dd/yy}",
areYouAvailable);
else
txtLog.WriteLine("Yay! I am available on {0:MM/dd/yy}",
areYouAvailable);
}
>$ #)! 0,!1&'/% !":(02!- #)! D3*.4 !"#!$%&'$ (!#)'* !2&(&$:#!% #)! P3/&%2( 2''05 >$ #)&%
!":(02!- :$ "Ph4(&.h&)1& %#:#!(!$# &% :**!* #' %)'7 :1:&2:8&2_ V2%'- 0:,!$#)!%!% :,! :**!*
#' 02:3! #)! 3:22 #' #)! D3*.4 (!#)'* :?#!, #)! 1&)&24 32:/%!5
Q>CY&Z%?;'40+6)! F>GH;0,'1&*!* @!97',*% 3:$ (:@! 9'/, F>GH 4/!,&!% 2''@ 32!:$ :$* %&(02!5 6:82! B;L
0,'1&*!% #)! 2&%# '? :1:&2:82! @!97',*%- 7&#) : %)',# *!%3,&0#&'$ '? !:3)5 c:$9 '? #)!%! @!9;
7',*% :,! 3'1!,!* &$ (',! *!#:&2 &$ #)&% %!3#&'$5
'%P:( *>! Q&%/:2 C:%&3 :$* Ug F>GH a!97',*%
T(U0M)V V(J#);&';M<
P/3+ X0!3&I!% : *:#: %'/,3! :$* : ,:$+! 1:,&:82!
R(&/& W&2#!,% %'/,3! !2!(!$#% 8:%!* '$ '$! ', (',! C''2!:$
!"0,!%%&'$%
1&)&24 X0!3&I!% #)! #90! :$* %):0! #)! !2!(!$#% &$ #)! ,!#/,$!* %!;
4/!$3! ):1! 7)!$ #)! 4/!,9 &% !"!3/#!*
F!%%'$ AM =%&$+ F>GH H/!,&!% #$%&'() * -,+
9/3*# <,'/0% 4/!,9 ,!%/2#% :33',*&$+ #' : %0!3&I!* @!9 1:2/!
".43 _,'1&*!% :$ &*!$#&I!, #):# 3:$ %!,1! :% : ,!?!,!$3! #' #)! ,!%/2#%
'? : S3".- 9/3*#- ', 1&)&24 32:/%!
3/G&/06
TQ&%/:2 C:%&3MAN/G&/A:6K
X',#% 4/!,9 ,!%/2#% &$ :%3!$*&$+ ', *!%3!$*&$+ ',*!,
S3". O'&$% #7' *:#: %'/,3!% 8:%!* '$ :$ !4/:2	 3'(0:,&%'$ 8!;
#7!!$ #7' %0!3&I!* (:#3)&$+ 3,&#!,&:
)&4 >$#,'*/3!% : ,:$+! 1:,&:82! #' %#',! %/8!"0,!%%&'$ ,!%/2#% &$ :
4/!,9 !"0,!%%&'$
". U'$#!"#/:2 @!97',* &$ : P/3+ ', S3". 32:/%! #' %0!3&?9 #)! *:#:
%'/,3!
3. U'$#!"#/:2 @!97',* &$ : S3". 32:/%! #' %0!3&?9 #)! .'&$ 3,&#!,&:
&U*%)1 U'$#!"#/:2 @!97',* &$ : S3". 32:/%! #' .'&$ #7' %'/,3!%
06 U'$#!"#/:2 @!97',* &$ : 9/3*# 32:/%! #' %0!3&?9 #)! +,'/0&$+
3,&#!,&:
%12&.G".9 U'$#!"#/:2 @!97',* &$ :$ 3/G&/06 32:/%!
G&12&.G".9 U'$#!"#/:2 @!97',* &$ :$ 3/G&/06 32:/%!
>$ :**&#&'$ #' #)! @!97',*% 2&%#!* &$ 6:82! B;L- #)! Q&%/:2 C:%&3 #!:( 0,'1&*!* @!97',*%
#):# Ug *&* $'# &(02!(!$#5 6)!%! @!97',*% :,! %)'7$ &$ 6:82! B;A 7&#) : %)',# *!%3,&0#&'$ '?
!:3)5
'%P:( *>- Q&%/:2 C:%&3 a!97',*% 6):# V,! G'# >(02!(!$#!* &$ Ug
T(U0M)V V(J#);&';M<
8"14".24 W&2#!,% */02&3:#! !2!(!$#%
!"#V !"#A'(")& O/(0% '1!, !2!(!$#% 8!?',! ,!#/,$&$+ ,!%/2#%
$%!&V$%!&A'(")& _,'1&*!% : (!:$% #' 2&(&# )'7 (:$9 !2!(!$#% 7&22 8! ,!#,&!1!*
599/&9%4& >$32/*!% :++,!+:#! ?/$3#&'$% &$ 9'/, 4/!,&!%
,.43 U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# %0!3&I!% 7):# #'
*' 7&#) #)! ,!%/2# '? #)! :++,!+:#!
5)) U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# *!#!,(&$!%
7)!#)!, :22 !2!(!$#% (!!# #)! %0!3&I!* 3,&#!,&'$
5.6 U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# *!#!,(&$!%
7)!#)!, :$9 '? #)! !2!(!$#% (!!# #)! %0!3&I!* 3,&#!,&'$
57&/%9& U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# 3:23/2:#!% #)!
:1!,:+! 1:2/!
-!, #$%&'() * >$#,'*/3&$+ F>GH
D3*.4 U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# 0,'1&*!% #)!
3'/$# '? !2!(!$#% #):# (!!# #)! %0!3&I!* 3,&#!,&'$
B/3*# U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# 0,'1&*!% :33!%%
#' #)! ,!%/2#% '? : 9/3*#A06 ', 9/3*#AS3". 32:/%!
<3.9D3*.4 U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# 0,'1&*!% #)!
3'/$# J%1A)3.9K '? !2!(!$#% #):# (!!# #)! %0!3&I!* 3,&#!,&'$
C%Q U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# 0,'1&*!% #)!
(:"&(/( 1:2/!
C". U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# 0,'1&*!% #)!
(&$&(/( 1:2/!
*+ U'$#!"#/:2 @!97',* &$ #)! 599/&9%4& 32:/%! #):# 0,'1&*!% #)! %/(
'? #)! !2!(!$#%
V22 #)! 4/!,9 !"#!$%&'$ (!#)'*% :,! :1:&2:82! &$ 8'#) 2:$+/:+!% !1!$ &? #)!,! &%$P# : 2:$;
+/:+! @!97',* (:00&$+ #' #)! 4/!,9 !"#!$%&'$ (!#)'*5
M4'F%.5*':+_,'.!3#&'$% !$:82! 9'/ #' #,:$%?',( #)! '/#0/# '? 9'/, F>GH 4/!,9 89 /%&$+ $:(!* ',
:$'$9('/$% #90!%5 6)! ?'22'7&$+ 3'*! !":(02! *!('$%#,:#!% 0,'.!3#&'$% &$ : F>GH 4/!,9 89
/%&$+ :$'$9('/% #90!%5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub LINQProjectionsToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LINQProjectionsToolStripMenuItem.Click
Dim cars = GetCars()
Dim vinsAndMakes = From c In cars
Select New With
{
c.VIN,
.CarModel = c.Make
}
For Each item In vinsAndMakes
txtLog.WriteLine("VIN:{0} Make:{1}", item.VIN, item.CarModel)
Next
End Sub
!"#$%&'(&/1&/'0%
private void lINQProjectionsToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var vinsAndMakes = from c in cars
select new { c.VIN, CarModel = c.Model };
foreach (var item in vinsAndMakes)
{
txtLog.WriteLine("VIN:{0} Make:{1}", item.VIN, item.CarModel);
F!%%'$ AM =%&$+ F>GH H/!,&!% #$%&'() * -!!
}
}
=+*:E&53%&&34&Z%?;'40&5'&[%$#&;*53&M4'F%.5*':+N'/ 3:$ /%! #)! )&4 @!97',* #' 3,!:#! : #!(0',:,9 1:,&:82! 7&#)&$ #)! F>GH 4/!,95 6)&$@ '?
#)! )&4 @!97',* :% : 1:,&:$# '? #)! 1&)&24 @!97',* /%!* 7&#)&$ #)! 4/!,95 6)! ?'22'7&$+ 3'*!
%:(02! %)'7% )'7 #)! )&4 @!97',* 3:$ )!20 7&#) I2#!,&$+ :$* %):0&$+ #)! *:#:5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub LINQLetToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LINQLetToolStripMenuItem.Click
Dim cars = GetCars()
Dim vinsAndMakes = From c In cars
Let makeModel = c.Make & " " & c.Model
Where makeModel.Contains("B")
Select New With
{
c.VIN,
.MakeModel = makeModel
}
For Each item In vinsAndMakes
txtLog.WriteLine("VIN:{0} Make and Model:{1}", item.VIN, item.MakeModel)
Next
End Sub
!"#$%&'(&/1&/'0%
private void lINQLetToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var vinsAndMakes = from c in cars
let makeModel = c.Make + " " + c.Model
where makeModel.Contains('B')
select new { c.VIN, MakeModel=makeModel };
foreach (var item in vinsAndMakes)
{
txtLog.WriteLine("VIN:{0} Make and Model:{1}", item.VIN, item.MakeModel);
}
}
23%&4%+,$56
VIN:DEF123 Make and Model:BMW Z-3
VIN:HIJ123 Make and Model:VW Bug
#%.*(?*:E&!&I*$5%4C'#) Ug :$* Q&%/:2 C:%&3 ):1! #)! R(&/& @!97',* #):# (:0% *&,!3#29 #' #)! '(&/& 4/!,9
!"#!$%&'$ (!#)'*5 N'/ 3:$ %0!3&?9 : 0,!*&3:#! J:$ !"0,!%%&'$ #):# !1:2/:#!% #' : C''2!:$
1:2/!K #' *!#!,(&$! #)! !2!(!$#% #' 8! ,!#/,$!*5 6)! ?'22'7&$+ 3'*! %:(02! *!('$%#,:#!%
#)! R(&/& 32:/%! 7&#) : 6&%/O%.9& 1:,&:82! 8!&$+ /%!* :% : 0:,:(!#!, &$#' #)! 4/!,95
-!- #$%&'() * >$#,'*/3&$+ F>GH
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub LINQWhereToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LINQWhereToolStripMenuItem.Click
Dim yearRange = 2000
Dim cars = GetCars()
Dim oldCars = From c In cars
Where c.Year < yearRange
Select c
For Each myCar In oldCars
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Year:{3}",
myCar.VIN, myCar.Make, myCar.Model, myCar.Year)
Next
End Sub
!"#$%&'(&/1&/'0%
private void lINQWhereToolStripMenuItem_Click(object sender, EventArgs e)
{
int yearRange = 2000;
var cars = GetCars();
var oldCars = from c in cars
where c.Year < yearRange
select c;
foreach (var myCar in oldCars)
{
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Year:{3}",
myCar.VIN, myCar.Make, myCar.Model, myCar.Year);
}
}
23%&4%+,$56
Car VIN:HIJ123, Make:VW, Model:Bug Year:1956
Car VIN:DEF456, Make:Ford, Model:F-150 Year:1998
#%.*(?*:E&!& '45&L40%4>#P% 1!,9 !:%9 #' %',# /%&$+ : F>GH 4/!,95 6)! 3/G&/06 @!97',* !$:82!% 9'/ #' %',# &$ :%;
3!$*&$+ ', *!%3!$*&$+ ',*!,5 >$ :**&#&'$- 9'/ 3:$ %',# '$ (/2#&02! 0,'0!,#&!% #' 0!,?',( :
3'(0'/$* %',#5 6)! ?'22'7&$+ 3'*! %:(02! %)'7% #)! %',#&$+ '? 3:,% 89 C%!& :%3!$*&$+ :$*
#)!$ 89 C3G&) *!%3!$*&$+5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub LINQSortToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LINQSortToolStripMenuItem.Click
Dim cars = GetCars()
Dim sorted = From c In cars
Order By c.Make Ascending, c.Model Descending
Select c
For Each myCar In sorted
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Year:{3}",
myCar.VIN, myCar.Make, myCar.Model, myCar.Year)
F!%%'$ AM =%&$+ F>GH H/!,&!% #$%&'() * -!*
Next
End Sub
!"#$%&'(&/1&/'0%
private void lINQSortToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var sorted = from c in cars
orderby c.Make ascending, c.Model descending
select c;
foreach (var myCar in sorted)
{
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Year:{3}",
myCar.VIN, myCar.Make, myCar.Model, myCar.Year);
}
}
23%&4%+,$56
Car VIN:ABC456, Make:Audi, Model:TT Year:2008
Car VIN:DEF123, Make:BMW, Model:Z-3 Year:2005
Car VIN:ABC123, Make:Ford, Model:F-250 Year:2000
Car VIN:DEF456, Make:Ford, Model:F-150 Year:1998
Car VIN:HIJ123, Make:VW, Model:Bug Year:1956
M!E*:E6)! :8&2	 #' 2''@ :# *:#: '$! 0:+! :# : #&(! &% :27:9% : ,!4/&,!(!$# 7)!$ : 2:,+! :('/$# '?
*:#: &% 8!&$+ ,!#,&!1!*5 F>GH %&(02&I!% #)&% #:%@ 7&#) #)! !"# :$* $%!& !"#!$%&'$ (!#)'*%5 >$
:**&#&'$- Q&%/:2 C:%&3 '??!,% #)!%! 4/!,9 !"#!$%&'$ (!#)'*% :% @!97',*%5
6)! ?'22'7&$+ 3'*! !":(02! ,!#,&!1!% Ab ,'7% '? *:#: :$* #)!$ 0,'1&*!% 0:+&$+ 3:0:8&2&;
#&!% #' !$:82! 0:+&$+ #!$ ,'7% :# : #&(!5
#$%&'"()
I'4&53%&%T!"A&8%&+,4%&53!5&?',&(,$$?&,:0%4+5!:0&3';&5'&#%4('4"&#!E*:EB
!"#$%&'(&)*+,!$&-!+*.&/'0%
Private Sub LINQPagingToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LINQPagingToolStripMenuItem.Click
Dim pageSize = 10
'create 5 copies of the cars - total 25 rows
Dim cars = Enumerable.Range(1, 5) _
.SelectMany(Function(i) GetCars() _
.Select(Function(c) New With _
{.BatchNumber = i, c.VIN, c.Make, c.Model, c.Year}))
'calculate page count
Dim pageCount = (cars.Count() / pageSize)
If (pageCount * pageSize < cars.Count()) Then pageCount += 1
-!. #$%&'() * >$#,'*/3&$+ F>GH
For i = 0 To pageCount
txtLog.WriteLine("-----Printing Page {0}------", i)
'Dim currentPage = cars.Skip(i * pageSize).Take(pageSize)
Dim currentPage = From c In cars
Skip (i * pageSize)
Take pageSize
Select c
For Each myCar In currentPage
txtLog.WriteLine("#{0} Car VIN:{1}, Make:{2}, Model:{3} Year:{4}", _
myCar.BatchNumber, myCar.VIN, myCar.Make, myCar.Model, myCar.Year)
Next
Next
End Sub
!"#$%&'(&/1&/'0%
private void lINQPagingToolStripMenuItem_Click(object sender, EventArgs e)
{
int pageSize = 10;
//create 5 copies of the cars - total 25 rows
var cars = Enumerable.Range(1,5)
.SelectMany(i=>GetCars()
.Select(c=>(new {BatchNumber=i, c.VIN, c.Make, c.Model, c.Year})));
//calculate page count
int pageCount = (cars.Count() / pageSize);
if (pageCount * pageSize < cars.Count()) pageCount++;
for(int i=0; i < pageCount; i++)
{
txtLog.WriteLine("-----Printing Page {0}------", i);
var currentPage = cars.Skip(i * pageSize).Take(pageSize);
foreach (var myCar in currentPage)
{
txtLog.WriteLine("#{0} Car VIN:{1}, Make:{2}, Model:{3} Year:{4}",
myCar.BatchNumber, myCar.VIN, myCar.Make, myCar.Model, myCar.Year);
}
}
}
23%&4%+,$56
-----Printing Page 0------
#1 Car VIN:ABC123, Make:Ford, Model:F-250 Year:2000
#1 Car VIN:DEF123, Make:BMW, Model:Z-3 Year:2005
#1 Car VIN:ABC456, Make:Audi, Model:TT Year:2008
#1 Car VIN:HIJ123, Make:VW, Model:Bug Year:1956
#1 Car VIN:DEF456, Make:Ford, Model:F-150 Year:1998
#2 Car VIN:ABC123, Make:Ford, Model:F-250 Year:2000
#2 Car VIN:DEF123, Make:BMW, Model:Z-3 Year:2005
#2 Car VIN:ABC456, Make:Audi, Model:TT Year:2008
#2 Car VIN:HIJ123, Make:VW, Model:Bug Year:1956
#2 Car VIN:DEF456, Make:Ford, Model:F-150 Year:1998
-----Printing Page 1------
F!%%'$ AM =%&$+ F>GH H/!,&!% #$%&'() * -!/
#3 Car VIN:ABC123, Make:Ford, Model:F-250 Year:2000
#3 Car VIN:DEF123, Make:BMW, Model:Z-3 Year:2005
#3 Car VIN:ABC456, Make:Audi, Model:TT Year:2008
#3 Car VIN:HIJ123, Make:VW, Model:Bug Year:1956
#3 Car VIN:DEF456, Make:Ford, Model:F-150 Year:1998
#4 Car VIN:ABC123, Make:Ford, Model:F-250 Year:2000
#4 Car VIN:DEF123, Make:BMW, Model:Z-3 Year:2005
#4 Car VIN:ABC456, Make:Audi, Model:TT Year:2008
#4 Car VIN:HIJ123, Make:VW, Model:Bug Year:1956
#4 Car VIN:DEF456, Make:Ford, Model:F-150 Year:1998
-----Printing Page 2------
#5 Car VIN:ABC123, Make:Ford, Model:F-250 Year:2000
#5 Car VIN:DEF123, Make:BMW, Model:Z-3 Year:2005
#5 Car VIN:ABC456, Make:Audi, Model:TT Year:2008
#5 Car VIN:HIJ123, Make:VW, Model:Bug Year:1956
#5 Car VIN:DEF456, Make:Ford, Model:F-150 Year:1998
6)&% 3'*! %:(02! %#:,#% 89 *!I$&$+ #)! 0:+! %&T! :% LE5 W&1! 3'0&!% '? #)! 3:,% :,! #)!$
3,!:#!*- 7)&3) 9&!2*% Ab 3:,%5 6)! I1! 3'0&!% :,! 3,!:#!* 89 /%&$+ #)! -.*+&/%0)& 32:%% #'
+!$!,:#! : ,:$+! '? 1:2/!%- L #' b5 [:3) '? #)!%! 1:2/!% &% /%!* 7&#) #)! &)&24C%.6 4/!,9
!"#!$%&'$ (!#)'* #' 3,!:#! : 3'09 '? #)! 3:,%5 U:23/2:#&$+ #)! 0:+! 3'/$# &% :33'(02&%)!*
89 *&1&*&$+ #)! 3'/$# '? #)! 3:,% 89 #)! 0:+! %&T!- 8/# &? #)!,! &% : ,!(:&$*!,- #)! 0:+! 3'/$#
&% &$3,!(!$#!*5 W&$:229- : P3/ 2''0 3,!:#!% : 4/!,9 ?', !:3) '? #)! 0:+!% :$* #)!$ 0,&$#% #)!
3/,,!$# 0:+!5
>$ #)! Q&%/:2 C:%&3 !":(02!- #)! 4/!,9 ?', #)! 0:+! 7:% 7,&##!$ I,%# #' (:#3) #)! Ug 1!,;
%&'$- 8/# #):# 3'*! &% 3'((!$#!* '/# :$* #)! 4/!,9 &% ,!7,&##!$ /%&$+ #)! Q&%/:2 C:%&3 !"#
:$* $%!& @!97',*%5
\'*:+Z)!$ 7',@&$+ 7&#) *:#:8:%!%- 9'/ 3'(('$29 7:$# #' 3'(8&$! *:#: ?,'( (/2#&02! #:82!%
#' 0,'*/3! : (!,+!* ,!%/2# %!#5 F>GH !$:82!% 9'/ #' .'&$ #7' +!$!,&3 ,-.*+&/%0)& !2!(!$#
%'/,3!%- !1!$ &? #)!%! %'/,3!% :,! $'# ?,'( : *:#:8:%!5 6)!,! :,! #),!! #90!% '? .'&$%M &$$!,
.'&$%- '/#!, .'&$%- :$* 3,'%% .'&$%5 >$$!, .'&$% :$* '/#!, .'&$% #90&3:229 (:#3) '$ : ?',!&+$ @!9
&$ : 3)&2* %'/,3! (:#3)&$+ #' : /$&4/! @!9 &$ : 0:,!$# %'/,3!5 6)&% %!3#&'$ !":(&$!% #)!%! .'&$
#90!%5
>::%4&\'*:+
>$$!, .'&$% 0,'*/3! '/#0/# '$29 &? #)!,! &% : (:#3) 8!#7!!$ 8'#) .'&$ %'/,3!%5 >$ #)! ?'22'7;
&$+ 3'*! %:(02!- : 3'22!3#&'$ '? 3:,% &% .'&$!* #' : 3'22!3#&'$ '? ,!0:&,%- 8:%!* '$ #)! Q>G '?
#)! 3:,5 6)! ,!%/2#&$+ '/#0/# 3'(8&$!% %'(! '? #)! 3:, &$?',(:#&'$ 7&#) %'(! '? #)! ,!0:&,
&$?',(:#&'$5
!"#$%&'(&)*+,!$&-!+*.&/'0%
Public Class Repair
Public Property VIN() As String
Public Property Desc() As String
Public Property Cost As Decimal
-!F #$%&'() * >$#,'*/3&$+ F>GH
End Class
Private Function GetRepairs() As List(Of Repair)
Return New List(Of Repair) From
{
New Repair With {.VIN = "ABC123", .Desc = "Change Oil", .Cost = 29.99},
New Repair With {.VIN = "DEF123", .Desc = "Rotate Tires", .Cost = 19.99},
New Repair With {.VIN = "HIJ123", .Desc = "Replace Brakes", .Cost = 200},
New Repair With {.VIN = "DEF456", .Desc = "Alignment", .Cost = 30},
New Repair With {.VIN = "ABC123", .Desc = "Fix Flat Tire", .Cost = 15},
New Repair With {.VIN = "DEF123", .Desc = "Fix Windshield", .Cost = 420},
New Repair With {.VIN = "ABC123", .Desc = "Replace Wipers", .Cost = 20},
New Repair With {.VIN = "HIJ123", .Desc = "Replace Tires", .Cost = 1000},
New Repair With {.VIN = "DEF456", .Desc = "Change Oil", .Cost = 30}
}
End Function
Private Sub LINQInnerJoinToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles LINQInnerJoinToolStripMenuItem.Click
Dim cars = GetCars()
Dim repairs = GetRepairs()
Dim carsWithRepairs = From c In cars
Join r In repairs
On c.VIN Equals r.VIN
Order By c.VIN, r.Cost
Select New With
{
c.VIN,
c.Make,
r.Desc,
r.Cost
}
For Each item In carsWithRepairs
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Description:{2} Cost:{3:C}",
item.VIN, item.Make, item.Desc, item.Cost)
Next
End Sub
!"#$%&'(&/1&/'0%
public class Repair
{
public string VIN { get; set; }
public string Desc { get; set; }
public decimal Cost { get; set; }
}
private List<Repair> GetRepairs()
{
return new List<Repair>
{
new Repair {VIN = "ABC123", Desc = "Change Oil", Cost = 29.99m},
F!%%'$ AM =%&$+ F>GH H/!,&!% #$%&'() * -!N
new Repair {VIN = "DEF123", Desc = "Rotate Tires", Cost =19.99m},
new Repair {VIN = "HIJ123", Desc = "Replace Brakes", Cost = 200},
new Repair {VIN = "DEF456", Desc = "Alignment", Cost = 30},
new Repair {VIN = "ABC123", Desc = "Fix Flat Tire", Cost = 15},
new Repair {VIN = "DEF123", Desc = "Fix Windshield", Cost =420},
new Repair {VIN = "ABC123", Desc = "Replace Wipers", Cost = 20},
new Repair {VIN = "HIJ123", Desc = "Replace Tires", Cost = 1000},
new Repair {VIN = "DEF456", Desc = "Change Oil", Cost = 30}
};
}
private void lINQInnerJoinToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var repairs = GetRepairs();
var carsWithRepairs = from c in cars
join r in repairs
on c.VIN equals r.VIN
orderby c.VIN, r.Cost
select new
{
c.VIN,
c.Make,
r.Desc,
r.Cost
};
foreach (var item in carsWithRepairs)
{
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Description:{2} Cost:{3:C}",
item.VIN, item.Make, item.Desc, item.Cost);
}
}
!"#$"%&'()
Car VIN:ABC123, Make:Ford, Description:Fix Flat Tire Cost:$15.00
Car VIN:ABC123, Make:Ford, Description:Replace Wipers Cost:$20.00
Car VIN:ABC123, Make:Ford, Description:Change Oil Cost:$29.99
Car VIN:DEF123, Make:BMW, Description:Rotate Tires Cost:$19.99
Car VIN:DEF123, Make:BMW, Description:Fix Windshield Cost:$420.00
Car VIN:DEF456, Make:Ford, Description:Alignment Cost:$30.00
Car VIN:DEF456, Make:Ford, Description:Change Oil Cost:$30.00
Car VIN:HIJ123, Make:VW, Description:Replace Brakes Cost:$200.00
Car VIN:HIJ123, Make:VW, Description:Replace Tires Cost:$1,000.00
!"#$%&'()*%$#!+,#$-!%$./%'-"+0$+1$-!%$ !"#$%$.*'##$'02$-!%$./%'-"+0$+1$'$&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4-)4-$%:%0$"1$-!%$.'/$!'#$0+$
/%)'"/#<$A+4$(4#-$)%/1+/($'0$+4-%/$7+"08
;0+-!%/$,'A$-+$)%/1+/($'0$"00%/$7+"0$"#$-+$4#%$-!%$8.$1$@4%/A$%&-%0#"+0$(%-!+2<$,!".!$,'#$
.+:%/%2$%'/*"%/$"0$-!"#$.!')-%/8
*&("$#+,-.%
L4-%/$7+"0#$)/+24.%$+4-)4-$1+/$%:%/A$%*%(%0-$"0$-!%$+4-%/$#+4/.%$%:%0$"1$-!%/%$"#$0+$('-.!$-+$
-!%$"00%/$#+4/.%8$ +$)%/1+/($'0$+4-%/$7+"0$6A$4#"05$'$=>9?$@4%/A<$4#%$-!%$$1'.$.*'4#%$,"-!$-!%$
0.$1$.*'4#%$MD"#4'*$E'#".$&%.3"98.$1N8$ !%$$1'.$.*'4#%$./%'-%#$'0$"2%0-"B%/$-!'-$.'0$#%/:%$'#$'$
/%1%/%0.%$-+$-!%$/%#4*-#$+1$'$0.$1<$:%.3"<$+/$(!4!)'$.*'4#%8$>0$-!"#$#.%0'/"+<$-!%$$1'.$.*'4#%$/%1%/3
%0.%#$-!%$7+"0$'02$"#$'##"50%2$-+$-!%$:'/"'6*%$'!/"8$ !%$"00%/$:'/"'6*%$%!"$"#$+4-$+1$#.+)%<$64-$
'$0%,$-%./$.*'4#%$"#$)/+:"2%2$-+$5%-$-!%$:'/"'6*%$%<$,!".!$/%1%/%0.%#$'$/%)'"/<$1/+($'!/"8$ !%$
;!-#34'<-=/"'>$(%-!+2$'##"50#$1344$-+$%$"1$0+$('-.!$.'0$6%$('2%$-+$'$/%)'"/8
/012'"#,3#4-%&0'#50%-6#7,8"
Private Sub LINQOuterJoinToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles LINQOuterJoinToolStripMenuItem.Click
Dim cars = GetCars()
Dim repairs = GetRepairs()
Dim carsWithRepairs = From c In cars
Group Join rep In repairs
On c.VIN Equals rep.VIN Into temp = Group
From r In temp.DefaultIfEmpty()
Order By c.VIN, If(r Is Nothing, 0, r.Cost)
Select New With
{
c.VIN,
c.Make,
.Desc = If(r Is Nothing, _
"***No Repairs***", r.Desc),
.Cost = If(r Is Nothing, _
0, r.Cost)
}
For Each item In carsWithRepairs
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Description:{2} Cost:{3:C}",
item.VIN, item.Make, item.Desc, item.Cost)
Next
End Sub
/012'"#,3#79#7,8"
private void lINQOuterJoinToolStripMenuItem_Click(object sender, EventArgs e)
{
$ =%##+0$OP$Q#"05$=>9?$?4%/"%#$ $%&'()* + !",
var cars = GetCars();
var repairs = GetRepairs();
var carsWithRepairs = from c in cars
join r in repairs
on c.VIN equals r.VIN into g
from r in g.DefaultIfEmpty()
orderby c.VIN, r==null?0:r.Cost
select new
{
c.VIN,
c.Make,
Desc = r==null?"***No Repairs***":r.Desc,
Cost = r==null?0:r.Cost
};
foreach (var item in carsWithRepairs)
{
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Description:{2} Cost:{3:C}",
item.VIN, item.Make, item.Desc, item.Cost);
}
}
!"#$"%&'()
Car VIN:ABC123, Make:Ford, Description:Fix Flat Tire Cost:$15.00
Car VIN:ABC123, Make:Ford, Description:Replace Wipers Cost:$20.00
Car VIN:ABC123, Make:Ford, Description:Change Oil Cost:$29.99
Car VIN:ABC456, Make:Audi, Description:***No Repairs*** Cost:$0.00
Car VIN:DEF123, Make:BMW, Description:Rotate Tires Cost:$19.99
Car VIN:DEF123, Make:BMW, Description:Fix Windshield Cost:$420.00
Car VIN:DEF456, Make:Ford, Description:Alignment Cost:$30.00
Car VIN:DEF456, Make:Ford, Description:Change Oil Cost:$30.00
Car VIN:HIJ123, Make:VW, Description:Replace Brakes Cost:$200.00
Car VIN:HIJ123, Make:VW, Description:Replace Tires Cost:$1,000.00
!%$.'/$,"-!$D>9$R$;EFIJK$"#$"0.*42%2$"0$-!%$/%#4*-<$%:%0$-!+45!$"-$!'#$0+$/%)'"/#8$;0+-!%/$
,'A$-+$)%/1+/($'$*%1-$+4-%/$7+"0$"#$-+$4#%$-!%$&%.3"8.$1$@4%/A$%&-%0#"+0$(%-!+2<$2"#.4##%2$
%'/*"%/$"0$-!"#$.!')-%/8
7$,%%#+,-.%
;$./+##$7+"0$"#$'$F'/-%#"'0$)/+24.-$6%-,%%0$-,+$%*%(%0-$#+4/.%#8$;$F'/-%#"'0$)/+24.-$,"**$7+"0$
%'.!$/%.+/2$"0$-!%$+4-%/$%*%(%0-$#+4/.%$,"-!$'**$%*%(%0-#$"0$-!%$"00%/$#+4/.%8$9+$7+"0$C%A#$'/%$
/%@4"/%2$,"-!$-!"#$-A)%$+1$7+"08$F/+##$7+"0#$'/%$'..+()*"#!%2$6A$4#"05$-!%$-%./$.*'4#%$(4*-")*%$
-"(%#$,"-!+4-$)/+:"2"05$'0A$*"0C$6%-,%%0$%*%(%0-$#+4/.%#8$ !"#$"#$+1-%0$2+0%$6A$("#-'C%8
>0$-!%$1+**+,"05$.+2%$#'()*%<$-!%/%$"#$'9).4.%($%*%(%0-$#+4/.%$'02$'$)#%($%*%(%0-$#+4/.%8$
!%$).4.%($#+4/.%$/%)/%#%0-#$-!%$':'"*'6*%$)'"0-$.+*+/#<$'02$-!%$)#%($#+4/.%$/%)/%#%0-#$-!%$.'/#$
-!'-$%&"#-8$ !%$2%#"/%2$+4-.+(%$"#$-+$.+(6"0%$-!%$.+*+/#$,"-!$-!%$.'/#$-+$#!+,$%:%/A$.+(6"3
0'-"+0$+1$.'/$'02$.+*+/$':'"*'6*%8
/012'"#,3#4-%&0'#50%-6#7,8"
Private Sub LINQCrossJoinToolStripMenuItem_Click( _
ByVal sender As System.Object, _
!!- $%&'()* + >0-/+24."05$=>9?
ByVal e As System.EventArgs) _
Handles LINQCrossJoinToolStripMenuItem.Click
Dim cars = GetCars()
Dim colors() = {"Red", "Yellow", "Blue", "Green"}
Dim carsWithRepairs = From car In cars
From color In colors
Order By car.VIN, color
Select New With
{
car.VIN,
car.Make,
car.Model,
.Color = color
}
For Each item In carsWithRepairs
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Color:{3}",
item.VIN, item.Make, item.Model, item.Color)
Next
End Sub
/012'"#,3#79#7,8"
private void lINQCrossJoinToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var colors = new string[]{"Red","Yellow","Blue","Green" };
var carsWithRepairs = from car in cars
from color in colors
orderby car.VIN, color
select new
{
car.VIN,
car.Make,
car.Model,
Color=color
};
foreach (var item in carsWithRepairs)
{
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Model:{2} Color:{3}",
item.VIN, item.Make, item.Model, item.Color);
}
}
!"#$"%&'()
Car VIN:ABC123, Make:Ford, Model:F-250 Color:Blue
Car VIN:ABC123, Make:Ford, Model:F-250 Color:Green
Car VIN:ABC123, Make:Ford, Model:F-250 Color:Red
Car VIN:ABC123, Make:Ford, Model:F-250 Color:Yellow
Car VIN:ABC456, Make:Audi, Model:TT Color:Blue
Car VIN:ABC456, Make:Audi, Model:TT Color:Green
Car VIN:ABC456, Make:Audi, Model:TT Color:Red
Car VIN:ABC456, Make:Audi, Model:TT Color:Yellow
Car VIN:DEF123, Make:BMW, Model:Z-3 Color:Blue
Car VIN:DEF123, Make:BMW, Model:Z-3 Color:Green
$ =%##+0$OP$Q#"05$=>9?$?4%/"%#$ $%&'()* + !!"
Car VIN:DEF123, Make:BMW, Model:Z-3 Color:Red
Car VIN:DEF123, Make:BMW, Model:Z-3 Color:Yellow
Car VIN:DEF456, Make:Ford, Model:F-150 Color:Blue
Car VIN:DEF456, Make:Ford, Model:F-150 Color:Green
Car VIN:DEF456, Make:Ford, Model:F-150 Color:Red
Car VIN:DEF456, Make:Ford, Model:F-150 Color:Yellow
Car VIN:HIJ123, Make:VW, Model:Bug Color:Blue
Car VIN:HIJ123, Make:VW, Model:Bug Color:Green
Car VIN:HIJ123, Make:VW, Model:Bug Color:Red
Car VIN:HIJ123, Make:VW, Model:Bug Color:Yellow
!%$./+##$7+"0$)/+24.%#$'0$+4-)4-$1+/$%'.!$.+(6"0'-"+0$+1$"0)4-#<$,!".!$(%'0#$-!'-$-!%$
+4-)4-$.+40-$"#$-!%$B/#-$"0)4-S#$.+40-$+0%$(4*-")*"%2$6A$-!%$#%.+02$"0)4-S#$.+40-8
;0+-!%/$,'A$-+$"()*%(%0-$'$./+##$7+"0$"#$-+$4#%$-!%$?!4!)'@#1>$@4%/A$%&-%0#"+0$(%-!+2<$
.+:%/%2$%'/*"%/$"0$-!"#$.!')-%/8
:$,&2-.;#0.8#<;;$";0(-,.T+4$,"**$+1-%0$,'0-$-+$.'*.4*'-%$'0$'55/%5'-"+0$#4.!$'#$-!%$-+-'*$.+#-$+1$A+4/$/%)'"/#$1+/$%'.!$
+1$A+4/$.'/#8$=>9?$%0'6*%#$A+4$-+$.'*.4*'-%$'55/%5'-%#$1+/$%'.!$"-%($6A$4#"05$-!%$:%.3"9A>$
.*'4#%8$ !%$1+**+,"05$.+2%$%&'()*%$2%(+0#-/'-%#$-!%$4#%$+1$-!%$:%.3"9A>$.*'4#%$,"-!$-!%$?3/$
'55/%5'-%$140.-"+0$-+$+4-)4-$-!%$D>9$'02$-!%$-+-'*$.+#-$+1$/%)'"/#8
/012'"#,3#4-%&0'#50%-6#7,8"
Private Sub LINQGroupByToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LINQGroupByToolStripMenuItem.Click
Dim repairs = From r In GetRepairs()
Group By VIN = r.VIN
Into grouped = Group, TotalCost = Sum(r.Cost)
For Each item In repairs
txtLog.WriteLine("Car VIN:{0}, TotalCost:{1:C}",
item.VIN, item.TotalCost)
Next
End Sub
/012'"#,3#79#7,8"
private void lINQGroupByToolStripMenuItem_Click(object sender, EventArgs e)
{
var repairs = from r in GetRepairs()
group r by r.VIN into grouped
select new
{
VIN = grouped.Key,
TotalCost = grouped.Sum(c => c.Cost)
};
foreach (var item in repairs)
{
txtLog.WriteLine("Car VIN:{0}, Total Cost:{1:C}",
item.VIN, item.TotalCost);
}
}
!!! $%&'()* + >0-/+24."05$=>9?
!"#$"%&'()
Car VIN:ABC123, Total Cost:$64.99
Car VIN:DEF123, Total Cost:$439.99
Car VIN:HIJ123, Total Cost:$1,200.00
Car VIN:DEF456, Total Cost:$60.00
!"#$@4%/A$)/+24.%2$-!%$-+-'*$.+#-$1+/$-!%$/%)'"/#$1+/$%'.!$.'/$-!'-$!'2$/%)'"/#<$64-$+0%$.'/$
!'2$0+$/%)'"/#<$#+$"-S#$0+-$*"#-%28$ +$*"#-$'**$-!%$.'/#<$A+4$(4#-$*%1-$7+"0$-!%$.'/#$-+$-!%$/%)'"/#$
'02$-!%0$.'*.4*'-%$-!%$#4($+1$-!%$/%)'"/#8$;*#+<$A+4$("5!-$,'0-$-+$'22$-!%$('C%$+1$-!%$.'/$
-+$-!%$+4-)4-$'02$"0.*42%$.'/#$-!'-$!':%$0+$/%)'"/#8$ !"#$/%@4"/%#$A+4$-+$)%/1+/($'$7+"0$'02$
5/+4)$+0$(4*-")*%$)/+)%/-"%#8$ !%$1+**+,"05$%&'()*%$#!+,#$!+,$A+4$.'0$'.!"%:%$-!%$/%#4*-8
/012'"#,3#4-%&0'#50%-6#7,8"
Private Sub LINQGroupBy2ToolStripMenuItem_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles LINQGroupBy2ToolStripMenuItem.Click
Dim cars = GetCars()
Dim repairs = GetRepairs()
Dim carsWithRepairs = From c In cars
Group c By Key = New With {c.VIN, c.Make}
Into grouped = Group
Group Join r In repairs On Key.VIN Equals r.VIN
Into joined = Group
Select New With
{
.VIN = Key.VIN,
.Make = Key.Make,
.TotalCost = joined.Sum(Function(x) x.Cost)
}
For Each item In carsWithRepairs
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Total Cost:{2:C}", _
item.VIN, item.Make, item.TotalCost)
Next
End Sub
/012'"#,3#79#7,8"
private void lINQGroupBy2ToolStripMenuItem_Click(object sender, EventArgs e)
{
var cars = GetCars();
var repairs = GetRepairs();
var carsWithRepairs = from c in cars
join rep in repairs
on c.VIN equals rep.VIN into temp
from r in temp.DefaultIfEmpty()
group r by new { c.VIN, c.Make } into grouped
select new
{
VIN = grouped.Key.VIN,
Make = grouped.Key.Make,
TotalCost =
$ =%##+0$OP$Q#"05$=>9?$?4%/"%#$ $%&'()* + !!+
grouped.Sum(c => c == null ? 0 : c.Cost)
};
foreach (var item in carsWithRepairs)
{
txtLog.WriteLine("Car VIN:{0}, Make:{1}, Total Cost:{2:C}",
item.VIN, item.Make, item.TotalCost);
}
}
!"#$"%&'()
Car VIN:ABC123, Make:Ford, Total Cost:$64.99
Car VIN:DEF123, Make:BMW, Total Cost:$439.99
Car VIN:ABC456, Make:Audi, Total Cost:$0.00
Car VIN:HIJ123, Make:VW, Total Cost:$1,200.00
Car VIN:DEF456, Make:Ford, Total Cost:$60.00
=0$0''"'#>?@A#B=>?@ACU'/'**%*$=>9?<$'*#+$C0+,0$'#$U=>9?<$"#$'$)'/'**%*$"()*%(%0-'-"+0$+1$=>9?$-+$+67%.-#8$U=>9?$
"()*%(%0-#$'**$-!%$=>9?$@4%/A$%&-%0#"+0$(%-!+2#$'02$!'#$'22"-"+0'*$+)%/'-+/#$1+/$)'/'**%*$
+)%/'-"+0#8$ !%$2%5/%%$+1$.+0.4//%0.A$1+/$U=>9?$@4%/"%#$"#$6'#%2$+0$-!%$.')'6"*"-"%#$+1$-!%$
.+()4-%/$/400"05$-!%$@4%/A8
>0$('0A<$64-$0+-$'**<$#.%0'/"+#<$U=>9?$.'0$)/+:"2%$'$#"50"B.'0-$"0./%'#%$"0$#)%%2$6A$4#3
"05$'**$':'"*'6*%$FUQ#$+/$FUQ$.+/%#8$;$U=>9?$@4%/A$.'0$)/+:"2%$)%/1+/('0.%$5'"0#$,!%0$
A+4$!':%$FUQ3"0-%0#":%$+)%/'-"+0#$-!'-$.'0$6%$)'/'**%*%2<$+/$2":"2%2<$'./+##$%'.!$FUQ$+/$
FUQ$.+/%8$ !%$(+/%$.+()4-'-"+0'**A$%&)%0#":%$-!%$,+/C$"#<$-!%$5/%'-%/$-!%$+))+/-40"-A$1+/$
)%/1+/('0.%$5'"08$V+/$%&'()*%<$"1$-!%$,+/C*+'2$-'C%#$WXX$("**"#%.+02#$-+$%&%.4-%<$'$#%@4%03
-"'*$@4%/A$+:%/$IXX$%*%(%0-#$,"**$-'C%$IX$#%.+02#$-+$.+()*%-%$-!%$,+/C<$,!%/%'#$'$)'/'**%*$
@4%/A$+0$'$.+()4-%/$,"-!$%"5!-$.+/%#$("5!-$-'C%$+0*A$J$#%.+02#8$ !"#$A"%*2#$'$#)%%24)$+1$YJ$
#%.+02#8
L0%$)/+6*%($,"-!$H"02+,#$'))*".'-"+0#$"#$-!'-$,!%0$A+4$-/A$-+$4)2'-%$'$.+03
-/+*$+0$A+4/$1+/($1/+($'$-!/%'2$+-!%/$-!'0$-!%$-!/%'2$-!'-$./%'-%2$-!%$.+0-/+*<$'099<1B#4$6C"!%#'$.1=D)!"'$.1$"#$-!/+,0$,"-!$-!%$(%##'5%<$ZF/+##3-!/%'2$+)%/'-"+0$0+-$:'*"2P$
F+0-/+*$[-&-=+5S$'..%##%2$1/+($'$-!/%'2$+-!%/$-!'0$-!%$-!/%'2$"-$,'#$./%'-%2$+08\$ +$,+/C$,"-!$
-!/%'2"05<$4)2'-%$"0$'$-!/%'23#'1%$,'A$-!%$1+**+,"05$%&-%0#"+0$(%-!+2$1+/$E!D'F.D$-+$-!%$
E!D'F.DG!4"!%$.*'##8
/012'"#,3#4-%&0'#50%-6#7,8"
<Extension()> _
Public Sub WriteLine(ByVal txt As TextBox, _
ByVal format As String, _
ByVal ParamArray parms As Object())
Dim line As String = String.Format((format & Environment.NewLine), parms)
If txt.InvokeRequired Then
txt.BeginInvoke(New Action(Of String)(AddressOf txt.AppendText), _
New Object() {line})
Else
txt.AppendText(line)
!!. $%&'()* + >0-/+24."05$=>9?
End If
End Sub
/012'"#,3#79#7,8"
public static void WriteLine(this TextBox txt,
string format, params object[] parms)
{
string line = string.Format(format + Environment.NewLine, parms);
if (txt.InvokeRequired)
{
txt.BeginInvoke((Action<string>)txt.AppendText, line);
}
else
{
txt.AppendText(line);
}
}
T+4$4#%$-!%$<1B.H!$+/$F!:$1<1B.H!$(%-!+2$+0$-!%$E!D'F.D$.*'##$-+$('/#!'*$-!%$.'**6'.C$-+$
-!%$-!/%'2$-!'-$,'#$4#%2$-+$./%'-%$-!%$Q>$.+0-/+*8$ !%$F!:$1<1B.H!$(%-!+2$)+#-#$'0$"0-%/0'*$
2%2".'-%2$H"02+,#$(%##'5%$-+$-!%$Q>$-!/%'2$(%##'5%$@4%4%$'02$/%-4/0#$"((%2"'-%*A<$,!".!$
!%*)#$':+"2$-!/%'2$2%'2*+.C$#"-4'-"+0#8
!"#$%&-%0#"+0$(%-!+2$.!%.C#$-!%$E!D'F.D$+67%.-$-+$#%%$,!%-!%/$('/#!'*"05$"#$/%@4"/%28$>1$
('/#!'*"05$"#$/%@4"/%2$M"8%8<$,!%0$-!%$.'**"05$-!/%'2$"#$0+-$-!%$+0%$4#%2$-+$./%'-%$-!%$E!D'F.D$
+67%.-N<$-!%$F!:$1<1B.H!$(%-!+2$"#$%&%.4-%28$>1$('/#!'*"05$"#$0+-$/%@4"/%2<$-!%$5""!16E!D'$
(%-!+2$"#$.'**%2$2"/%.-*A$+0$-!%$E!D'F.D$+67%.-8$ !%$F!:$1<1B.H!$(%-!+2$-'C%#$;!4!:#'!$'#$
'$)'/'(%-%/<$#+$'D'I5""!16E!D'$"#$.'#-$-+$'0$'.-"+0$+1$?'%$1:<$'$5%0%/'*3)4/)+#%$2%*%5'-%$
-!'-$%&"#-#$"0$-!%$1/'(%,+/C<$,!".!$/%)/%#%0-#$'$.'**$-+$'$(%-!+2$-!'-$-'C%#$'$('%$1:$)'/'(3
%-%/8$9+,$-!'-$-!%/%$"#$'$-!/%'23#'1%$,'A$-+$2"#)*'A$"01+/('-"+0$"0-+$-!%$E!D'F.D$.*'##<$-!%$
$5(J#%#44!4$%&'()*%$.'0$6%$)%/1+/(%2$,"-!+4-$/"#C"05$-!/%'2"053/%*'-%2$%&.%)-"+0#8
!"#$#%%&%#DE(".%-,.#F"(!,8
!%$5(J#%#44!4$%&-%0#"+0$(%-!+2$2":"2%#$,+/C$+0-+$%'.!$)/+.%##+/$+/$)/+.%##+/$.+/%8$ !%$
1+**+,"05$.+2%$#'()*%$#-'/-#$'$#-+),'-.!$"0$-!%9?>('!/I;$#:1.('$)($0'(%#)'.%$-+$#!+,$A+4$
-!%$%*')#%2$-"(%$,!%0$.+()*%-%2<$'02$-!%0$-!%$=13/!%#A4!$.*'##$)/+24.%#$'$#%@4%0.%$+1$
"0-%5%/#<$1/+($W$-+$WX8$ !%$5(J#%#44!4$(%-!+2$.'**$"#$'22%2$-+$-!%$#+4/.%8$ !"#$.'4#%#$-!%$
"-%/'-"+0#$-+$6%$#)/%'2$'./+##$-!%$':'"*'6*%$)/+.%##+/$'02$)/+.%##+/$.+/%#8$ !%0$'$=>9?$
@4%/A$/%-/"%:%#$'**$-!%$%:%0$04(6%/#<$64-$"0$-!%$=>9?$@4%/A<$-!%$K,!%!$.*'4#%$"#$.'**"05$'$
*./"3'!$(%-!+2<$,!".!$!'#$'$+0%3#%.+02$2%*'A$4#"05$-!%$E,%!#6$.*'##<$,!".!$"#$"0$-!%$
$?>('!/I9E,%!#6$1:$0'(%#)'.%8$V"0'**A<$'$-.%!#),$*++)$2"#)*'A#$-!%$/%#4*-#8
/012'"#,3#4-%&0'#50%-6#7,8"
Private Sub AsParallelToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles AsParallelToolStripMenuItem.Click
Dim sw As New Stopwatch
sw.Start()
$ =%##+0$OP$Q#"05$=>9?$?4%/"%#$ $%&'()* + !!/
Dim source = Enumerable.Range(1, 10).AsParallel()
Dim evenNums = From num In source
Where Compute(num) Mod 2 = 0
Select num
For Each ev In evenNums
txtLog.WriteLine("{0} on Thread {1}", _
New Object() {ev, Thread.CurrentThread.GetHashCode})
Next
sw.Stop()
txtLog.WriteLine("Done {0}", New Object() {sw.Elapsed})
End Sub
Public Function Compute(ByVal num As Integer) As Integer
txtLog.WriteLine("Computing {0} on Thread {1}", _
New Object() {num, Thread.CurrentThread.GetHashCode})
Thread.Sleep(1000)
Return num
End Function
/012'"#,3#79#7,8"
private void asParallelToolStripMenuItem_Click(
object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
var source = Enumerable.Range(1, 10).AsParallel();
var evenNums = from num in source
where Compute(num) % 2 == 0
select num;
foreach (var ev in evenNums)
{
txtLog.WriteLine("{0} on Thread {1}", ev,
Thread.CurrentThread.GetHashCode());
}
sw.Stop();
txtLog.WriteLine("Done {0}", sw.Elapsed);
}
public int Compute(int num)
{
txtLog.WriteLine("Computing {0} on Thread {1}", num,
Thread.CurrentThread.GetHashCode());
Thread.Sleep(1000);
return num;
}
!'()*&$#+%&#$"%&'(%G#%!,H-.;#"I".#.&1J"$%G#(,(0'#(-1"G#0.8#6,12&(-.;#1"(!,8)
6 on Thread 10
2 on Thread 10
4 on Thread 10
8 on Thread 10
10 on Thread 10
Done 00:00:05.0393262
Computing 1 on Thread 12
!!0 $%&'()* + >0-/+24."05$=>9?
Computing 2 on Thread 11
Computing 3 on Thread 12
Computing 4 on Thread 11
Computing 5 on Thread 11
Computing 6 on Thread 12
Computing 7 on Thread 12
Computing 8 on Thread 11
Computing 9 on Thread 12
Computing 10 on Thread 11
!%$+4-)4-$1/+($-!%$*./"3'!$.'**#$'*,'A#$#!+,#$'1-%/$-!%$-.%!#),$MD"#4'*$E'#".$L.%9=#),N$
*++)$+4-)4-$6%.'4#%$F!:$1<1B.H!$('/#!'**#$.'**#$-+$-!%$Q>$-!/%'2$1+/$%&%.4-"+0$,!%0$-!%$
Q>$-!/%'2$"#$':'"*'6*%8$ !%$-.%!#),$*++)$"#$/400"05$+0$-!%$Q>$-!/%'2<$#+$-!%$-!/%'2$"#$64#A$
40-"*$-!%$*++)$.+()*%-%#8$ !%$/%#4*-#$'/%$0+-$+/2%/%28$T+4/$/%#4*-$,"**$:'/A$'#$,%**<$'02<$"0$
#+(%$.'#%#<$-!%$/%#4*-#$("5!-$6%$+/2%/%28$>0$-!%$%&'()*%<$A+4$.'0$#%%$-!'-$-!%$-.%!#),$*++)$
2"#)*'A%2$-!%$%:%0$04(6%/#<$4#"05$-!%$('"0$-!/%'2$+1$-!%$'))*".'-"+0<$,!".!$,'#$-!/%'2$WX$
+0$-!"#$.+()4-%/8$ !%$*./"3'!$(%-!+2$,'#$%&%.4-%2$+0$'$2"11%/%0-$-!/%'2<$64-$-!%$-!/%'2$
"#$%"-!%/$WW$+/$WO$6%.'4#%$-!"#$"#$'$-,+3.+/%$)/+.%##+/8$;*-!+45!$-!%$*./"3'!$(%-!+2$!'#$'$
+0%3#%.+02$2%*'A<$"-$-++C$B:%$#%.+02#$-+$%&%.4-%$6%.'4#%$+0*A$-,+$-!/%'2#$,%/%$'**+.'-%2<$
+0%$1+/$%'.!$.+/%8
>0$'0$%11+/-$-+$5%-$'$.*%'/%/$)".-4/%$+1$U=>9?<$-!%$,/"-"05$-+$'$E!D'F.D$!'#$6%%0$/%)*'.%2$
"0$-!%$1+**+,"05$.+2%8$>0#-%'2$+1$4#"05$E!D'F.D<$;!A3:I+%$'!M$1!$"#$4#%2<$,!".!$/%(+:%#$-!%$
/%@4"/%(%0-$-+$('/#!'**$.'**#$6'.C$-+$-!%$Q>$-!/%'28
/012'"#,3#4-%&0'#50%-6#7,8"
Private Sub AsParallel2ToolStripMenuItem_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles AsParallel2ToolStripMenuItem.Click
Dim sw As New Stopwatch
sw.Start()
Dim source = Enumerable.Range(1, 10).AsParallel()
Dim evenNums = From num In source
Where Compute2(num) Mod 2 = 0
Select num
For Each ev In evenNums
Debug.WriteLine(String.Format("{0} on Thread {1}", _
New Object() {ev, Thread.CurrentThread.GetHashCode}))
Next
sw.Stop()
Debug.WriteLine(String.Format("Done {0}", New Object() {sw.Elapsed}))
End Sub
/012'"#,3#79#7,8"
private void asParallel2ToolStripMenuItem_Click(
object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
var source = Enumerable.Range(1, 10).AsParallel();
var evenNums = from num in source
$ =%##+0$OP$Q#"05$=>9?$?4%/"%#$ $%&'()* + !!1
where Compute2(num) % 2 == 0
select num;
foreach (var ev in evenNums)
{
Debug.WriteLine(string.Format("{0} on Thread {1}", ev,
Thread.CurrentThread.GetHashCode()));
}
sw.Stop();
Debug.WriteLine(string.Format("Done {0}", sw.Elapsed));
}
public int Compute2(int num)
{
Debug.WriteLine(string.Format("Computing {0} on Thread {1}", num,
Thread.CurrentThread.GetHashCode()));
Thread.Sleep(1000);
return num;
}
!"#$"%&'()
Computing 2 on Thread 10
Computing 1 on Thread 6
Computing 3 on Thread 10
Computing 4 on Thread 6
Computing 5 on Thread 10
Computing 6 on Thread 6
Computing 7 on Thread 10
Computing 8 on Thread 6
Computing 9 on Thread 10
Computing 10 on Thread 6
2 on Thread 9
4 on Thread 9
6 on Thread 9
8 on Thread 9
10 on Thread 9
Done 00:00:05.0632071
!%$/%#4*-<$,!".!$"#$"0$-!%$D"#4'*$]-42"+$89^ $L4-)4-$,"02+,<$#!+,#$-!'-$-!%/%$"#$0+$,'"-3
"05$1+/$-!%$Q>$-!/%'28$L0.%$'5'"0<$A+4/$/%#4*-$,"**$:'/A$6'#%2$+0$A+4/$!'/2,'/%$.+0B54/'-"+08$
,-$ %%#DE(".%-,.#F"(!,8
H!%0$-!%$@4%/A$"#$"-%/'-%2$6A$4#"05$'$-.%!#),$MD"#4'*$E'#".$L.%9=#),N$*++)<$%'.!$"-%/'-"+0$"#$
#A0.!/+0"_%2$"0$-!%$#'(%$-!/%'2<$-+$6%$-/%'-%2$+0%$'1-%/$-!%$+-!%/$"0$-!%$+/2%/$+1$-!%$#%3
@4%0.%8$>1$A+4$74#-$,'0-$-+$)%/1+/($%'.!$"-%/'-"+0$"0$)'/'**%*<$,"-!+4-$'0A$#)%."B.$+/2%/<$4#%$
-!%$L.%544$(%-!+28$>-$!'#$-!%$#'(%$%11%.-$'#$)%/1+/("05$%'.!$"-%/'-"+0$"0$'$2"11%/%0-$-!/%'28$
;0'*A_%$-!"#$-%.!0"@4%$-+$:%/"1A$-!'-$A+4$5%-$-!%$)%/1+/('0.%$5'"0$A+4$%&)%.-8$ !%$1+**+,"05$
%&'()*%$#!+,#$-!%$4#%$+1$-!%$L.%544$(%-!+2$"0#-%'2$+1$-!%$L.%9=#),$MFG$-.%!#),N$*++)8
/012'"#,3#4-%&0'#50%-6#7,8"
Private Sub ForAllToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
!!# $%&'()* + >0-/+24."05$=>9?
Handles ForAllToolStripMenuItem.Click
Dim sw As New Stopwatch
sw.Start()
Dim source = Enumerable.Range(1, 10).AsParallel()
Dim evenNums = From num In source
Where Compute2(num) Mod 2 = 0
Select num
evenNums.ForAll(Sub(ev) Debug.WriteLine(string.Format(
"{0} on Thread {1}", ev, _
Thread.CurrentThread.GetHashCode())))
sw.Stop()
Debug.WriteLine((string.Format("Done {0}", New Object() {sw.Elapsed}))
End Sub
/012'"#,3#79#7,8"
private void forAllToolStripMenuItem_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
var source = Enumerable.Range(1, 10).AsParallel();
var evenNums = from num in source
where Compute(num) % 2 == 0
select num;
evenNums.ForAll(ev => Debug.WriteLine(string.Format(
"{0} on Thread {1}", ev,
Thread.CurrentThread.GetHashCode())));
sw.Stop();
Debug.WriteLine(string.Format("Done {0}", sw.Elapsed));
}
,-$ %%#$"%&'(G#%!,H-.;#"I".#.&1J"$%G#(,(0'#(-1"G#0.8#6,12&(-.;#1"(!,8)
Computing 1 on Thread 9
Computing 2 on Thread 10
Computing 3 on Thread 9
2 on Thread 10
Computing 4 on Thread 10
Computing 5 on Thread 9
4 on Thread 10
Computing 6 on Thread 10
Computing 7 on Thread 9
6 on Thread 10
Computing 8 on Thread 10
Computing 9 on Thread 9
8 on Thread 10
Computing 10 on Thread 10
10 on Thread 10
!"#$%%&%%&%'(%'')''*
="C%$-!%$)/%:"+4#$%&'()*%<$-!%$/%#4*-#$'/%$0+-$54'/'0-%%2$-+$6%$+/2%/%2<$'02$-!%/%$"#$0+$
'--%()-$-+$)4-$-!%$/%#4*-#$"0$'$)'/-".4*'/$+/2%/8$ !"#$-%.!0"@4%$.'0$5":%$A+4$6%--%/$)%/1+/3
('0.%$'#$*+05$'#$-!"#$6%!':"+/$"#$'..%)-'6*%8$
$ =%##+0$OP$Q#"05$=>9?$?4%/"%#$ $%&'()* + !!,
!.$/&$&/#DE(".%-,.#F"(!,8
]+(%-"(%#<$A+4$(4#-$('"0-'"0$-!%$+/2%/$"0$A+4/$@4%/A<$64-$A+4$#-"**$,'0-$)'/'**%*$%&%.4-"+08$
;*-!+45!$-!"#$,"**$.+(%$'-$'$.+#-<$"-S#$2+'6*%$6A$4#"05$-!%$5(C%6!%!6$%&-%0#"+0$(%-!+28$ !%$
1+**+,"05$%&'()*%$#!+,#$!+,$A+4$.'0$'22$-!"#$(%-!+2$.'**$/"5!-$'1-%/$-!%$5(J#%#44!4$(%-!+2$
-+$('"0-'"0$+/2%/8
/012'"#,3#4-%&0'#50%-6#7,8"
Private Sub AsOrderedToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles AsOrderedToolStripMenuItem.Click
Dim sw As New Stopwatch
sw.Start()
Dim source = Enumerable.Range(1, 10).AsParallel().AsOrdered()
Dim evenNums = From num In source
Where Compute2(num) Mod 2 = 0
Select num
evenNums.ForAll(Sub(ev) Debug.WriteLine(string.Format(
"{0} on Thread {1}", ev, _
Thread.CurrentThread.GetHashCode())))
sw.Stop()
Debug.WriteLine(string.Format("Done {0}", New Object() {sw.Elapsed}))
End Sub
/012'"#,3#79#7,8"
private void asOrderedToolStripMenuItem_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
var source = Enumerable.Range(1, 10).AsParallel().AsOrdered();
var evenNums = from num in source
where Compute2(num) % 2 == 0
select num;
evenNums.ForAll(ev => Debug.WriteLine(string.Format(
"{0} on Thread {1}", ev,
Thread.CurrentThread.GetHashCode())));
sw.Stop();
Debug.WriteLine(string.Format("Done {0}", sw.Elapsed));
}
!.$/&$&/#$"%&'(G#%!,H-.;#"I".#.&1J"$%G#(,(0'#(-1"G#0.8#6,12&(-.;#1"(!,8)
Computing 2 on Thread 11
Computing 1 on Thread 10
2 on Thread 11
Computing 4 on Thread 11
Computing 3 on Thread 10
4 on Thread 11
Computing 6 on Thread 11
Computing 5 on Thread 10
6 on Thread 11
Computing 8 on Thread 11
Computing 7 on Thread 10
8 on Thread 11
!+- $%&'()* + >0-/+24."05$=>9?
Computing 9 on Thread 11
Computing 10 on Thread 10
10 on Thread 10
Done 00:00:05.2374586
!%$/%#4*-#$'/%$+/2%/%2<$'-$*%'#-$1+/$-!%$%:%0$04(6%/#<$,!".!$"#$,!'-$-!%$5(C%6!%!69%&-%03
#"+0$(%-!+2$"#$54'/'0-%%"058
!"#$%&$' 2345678 96:; <6=>377?>:?@ <A:A $BA==?=
>0$-!"#$)/'.-".%<$A+4$.+0:%/-$-!%$H%6$'))*".'-"+0$1/+($=%##+0$W$-+$4#%$=>9?$@4%/"%#$"0#-%'2$+1$
@4%/A$%&-%0#"+0$(%-!+2#8$ !%$/%#4*-$+1$-!"#$)/'.-".%$140.-"+0#$-!%$#'(%$,'A<$64-$A+4$,"**$#%%$
!+,$4#"05$=>9?$@4%/"%#$.'0$"()/+:%$/%'2'6"*"-A8
>1$A+4$%0.+40-%/$'$)/+6*%($.+()*%-"05$'0$%&%/."#%<$-!%$.+()*%-%2$)/+7%.-#$.'0$6%$"03
#-'**%2$1/+($-!%$F+2%$1+*2%/$+0$-!%$.+()'0"+0$F`8
'('"$&)' * 7,.I"$(-.;#3$,1#A&"$K#DE(".%-,.#F"(!,8%#(,#>?@A#A&"$-"%
>0$-!"#$%&%/."#%<$A+4$(+2"1A$-!%$H%6$'))*".'-"+0$A+4$./%'-%2$"0$=%##+0$W$-+$4#%$=>9?$@4%/"%#8
*+$ >0$D"#4'*$]-42"+$89^ $OXWX<$.!++#%$V"*%$a$L)%0$a$U/+7%.-8$L)%0$-!%$)/+7%.-$1/+($=%##+0$
W$+/$*+.'-%$'02$+)%0$-!%$#+*4-"+0$"0$-!%$E%5"0$1+*2%/$1+/$-!"#$*%##+08
,+$ >0$]+*4-"+0$^&)*+/%/<$/"5!-3.*".C$-!%$`%1'4*-8'#)&$B*%$'02$#%*%.-$D"%,$F+2%$-+$+)%0$-!%$
.+2%36%!"02$B*%$.+0-'"0"05$-!%$.+2%$1/+($=%##+0$W8
-+$ >0$-!%$J#:!NM.#6$(%-!+2<$*+.'-%$-!%$#-'-%(%0-$-!'-$.+0-'"0#$'**$-!%$+,!%!$(%-!+2$
.'**#$'#$1+**+,#P
/012'"#,3#4-%&0'#50%-6#7,8"
Dim result = Vehicles _
.Where(Function(v) v.VIN.StartsWith(txtVin.Text)) _
.Where(Function(v) v.Make.StartsWith(txtMake.Text)) _
.Where(Function(v) v.Model.StartsWith(txtModel.Text)) _
.Where(Function(v) v.Cost > Decimal.Parse(ddlCost.SelectedValue)) _
.Where(Function(v) v.Year > Integer.Parse(ddlYear.SelectedValue))
/012'"#,3#79#7,8"
var result = vehicles
.Where(v => v.VIN.StartsWith(txtVin.Text))
.Where(v => v.Make.StartsWith(txtMake.Text))
.Where(v => v.Model.StartsWith(txtModel.Text))
.Where(v => v.Cost > Decimal.Parse(ddlCost.SelectedValue))
.Where(v => v.Year > int.Parse(ddlYear.SelectedValue));
.+$ F+0:%/-$-!%$)/%:"+4#$.+2%$-+$4#%$'$=>9?$@4%/A8$T+4/$.+2%$#!+4*2$*++C$*"C%$-!%$
$1+**+,"05P
/012'"#,3#4-%&0'#50%-6#7,8"
Dim result = From v In Vehicles
Where v.VIN.StartsWith(txtVin.Text) _
And v.Make.StartsWith(txtMake.Text) _
$ =%##+0$OP$Q#"05$=>9?$?4%/"%#$ $%&'()* + !+"
And v.Model.StartsWith(txtModel.Text) _
And v.Cost > Decimal.Parse(ddlCost.SelectedValue) _
And v.Year > Integer.Parse(ddlYear.SelectedValue) _
Select v
/012'"#,3#79#7,8"
var result = from v in vehicles
where v.VIN.StartsWith(txtVin.Text)
&& v.Make.StartsWith(txtMake.Text)
&& v.Model.StartsWith(txtModel.Text)
&& v.Cost > Decimal.Parse(ddlCost.SelectedValue)
&& v.Year > int.Parse(ddlYear.SelectedValue)
select v;
E%!"02$-!%$#.%0%#<$-!%#%$@4%/"%#$2+$-!%$#'(%$-!"05$'#$-!%$)/%:"+4#$.+2%<$,!".!$"()*%3
(%0-%2$('0A$+,!%!$.'**#$6A$4#"05$(%-!+2$.!'"0"058
/+$ =+.'-%$-!%$?!'C%6!%$(%-!+28$b%)*'.%$-!%$.+2%$"0$-!"#$(%-!+2$-+$4#%$=>9?$%&)/%##"+0#8$
T+4/$.+2%$#!+4*2$*++C$*"C%$-!%$1+**+,"05P
/012'"#,3#4-%&0'#50%-6#7,8"
Private Function SetOrder(ByVal order As String, _
ByVal query As IEnumerable(Of Vehicle)) As IEnumerable(Of Vehicle)
Select Case order
Case "VIN"
Return From v In query Order By v.VIN Select v
Case "Make"
Return From v In query Order By v.Make Select v
Case "Model"
Return From v In query Order By v.Model Select v
Case "Year"
Return From v In query Order By v.Year Select v
Case "Cost"
Return From v In query Order By v.Cost Select v
Case Else
Return query
End Select
End Function
/012'"#,3#79#7,8"
private IEnumerable<Vehicle> SetOrder(string order,
IEnumerable<Vehicle> query)
{
switch (order)
{
case "VIN":
return from v in query orderby v.VIN select v;
case "Make":
return from v in query orderby v.Make select v;
case "Model":
return from v in query orderby v.Model select v;
case "Year":
return from v in query orderby v.Year select v;
case "Cost":
!+! $%&'()* + >0-/+24."05$=>9?
return from v in query orderby v.Cost select v;
default:
return query;
}
}
0+$ =+.'-%$-!%$2'-'36"02"05$.+2%8$ !"#$.+2%$4#%#$-!%$?!4!)'$@4%/A$%&-%0#"+0$(%-!+2$-+$
"0#-'0-"'-%$'0$'0+0A(+4#$-A)%<$,!".!$"#$-!%0$6+402$-+$-!%$5/"2$'#$1+**+,#P
/012'"#,3#4-%&0'#50%-6#7,8"
gvVehicles.DataSource = result.Select(Function(v, i) New With
{.Index = i, v.VIN, v.Make, v.Model, v.Year, v.Cost})
gvVehicles.DataBind()
/012'"#,3#79#7,8"
gvVehicles.DataSource = result.Select((v, i)=> new
{Index = i, v.VIN, v.Make, v.Model, v.Year, v.Cost});
gvVehicles.DataBind();
F'0$A+4$.+0:%/-$-!%$)/%:"+4#$.+2%$-+$'$=>9?$@4%/Ac$ !%$=>9?$(!4!)'$C%A,+/2$2+%#0S-$
#4))+/-$-!%$"02%&$)'/'(%-%/$:'*4%$-!"#$.+2%$4#%#8$T+4$.+4*2$#)%02$-"(%$-/A"05$-+$B02$
'$,'A$-+$.+0:%/-$-!"#$.+2%<$64-$"-S#$6%--%/$-+$*%':%$-!"#$.+2%$'#$"#8
1+$ F!++#%$E4"*2$a$E4"*2$]+*4-"+0$-+$64"*2$-!%$'))*".'-"+08$>1$A+4$!':%$%//+/#<$A+4$.'0$
2+46*%3.*".C$-!%$%//+/$-+$5+$-+$-!%$%//+/$*"0%$'02$.+//%.-8
2+$ F!++#%$`%645$a$]-'/-$`%6455"05$-+$/40$-!%$'))*".'-"+08
H!%0$-!%$'))*".'-"+0$#-'/-#<$A+4$#!+4*2$#%%$'$H%6$)'5%$,"-!$A+4/$dQ>$.+0-/+*#$-!'-$
%0'6*%#$A+4$-+$#)%."1A$B*-%/$'02$#+/-$./"-%/"'8$>1$A+4$-A)%$-!%$*%--%/$C$"0-+$-!%$e'C%$
-%&-$6+&$'02$.*".C$^&%.4-%<$-!%$5/"2$,"**$6%$)+)4*'-%2$+0*A$,"-!$"-%(#$-!'-$6%5"0$,"-!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02,%#"+,,%2,%+.*3-!.%42$0%+$$326<$!,@%
+,%,0*4-%2-%$0!%1*""*42->%#*.!%,+/="!U
G%&;/"#(<#M+*)%/#N%*+3#A(2"
<Global.System.Data.Linq.Mapping.TableAttribute(Name:="dbo.Customers"), _
Global.System.Runtime.Serialization.DataContractAttribute()> _
Partial Public Class Customer
Implements System.ComponentModel.INotifyPropertyChanging,
System.ComponentModel.INotifyPropertyChanged
' more code here
End Class
G%&;/"#(<#AO#A(2"
[global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.Customers")]
[global::System.Runtime.Serialization.DataContractAttribute()]
public partial class Customer : INotifyPropertyChanging, INotifyPropertyChanged
{
//mode code here
}
70!%83,$%+$$326<$!%2,%@!:5&A"",(:*"&@%402#0%&'()%$*% )&%<,!,%$*%2.!-$21D%$0!%$+6"!%2-% )&%
!3G!3%$0+$%$02,%#"+,,%3!=3!,!-$,5%702,%/!+-,%$0+$%@!:5&A"",(:*"&%"2-;,%$0!%#*)"$+&,%#"+,,%$*%$0!%
.6*5K<,$*/!3,%$+6"!%2-%$0!%.+$+6+,!%6!#+<,!%$0!%0!+&%=3*=!3$D%,=!#28!,%$0!%!9+#$%-+/!%*1%
$0!%.+$+6+,!%$+6"!5%'1%-*%0!+&%=3*=!3$D%2,%,<=="2!.@%&'()%$*% )&%+,,</!,%$0!%.+$+6+,!%$+6"!%
0+,%$0!%,+/!%-+/!%+,%$0!%#"+,,5%L-"D%2-,$+-#!,%*1%#"+,,!,%.!#"+3!.%+,%$+6"!,%+3!%,$*3!.%2-%$0!%
.+$+6+,!5%'-,$+-#!,%*1%$0!,!%$D=!,%*1%#"+,,!,%+3!%;-*4-%+,%&%"("(&)5%70!%#"+,,!,%$0!/,!"G!,%+3!%
;-*4-%+,%&%"("/B'5!))&)5
70!%,!#*-.%+$$326<$!%2,% !"!#$%",!'"A"",(:*"&@%402#0%!-+6"!,%,!32+"2X+$2*-%*1%$0!%#*)"$+&,%
#"+,,%40!-%<,!.%42$0%V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3%!+#0%#*"</-%2-%$0!%
.+$+6+,!%$+6"!5%70!%1*""*42->%#*.!%,+/="!%,0*4,%$0!%#*)"$+&,1 5
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private _CustomerID As String
<Global.System.Data.Linq.Mapping.ColumnAttribute(Storage:="_CustomerID", _
DbType:="NChar(5) NOT NULL", CanBeNull:=False, IsPrimaryKey:=True), _
Global.System.Runtime.Serialization.DataMemberAttribute(Order:=1)> _
Public Property CustomerID() As String
Get
Return Me._CustomerID
End Get
Set(ByVal value As String)
If (String.Equals(Me._CustomerID, value) = False) Then
Me.OnCustomerIDChanging(value)
Me.SendPropertyChanging()
Me._CustomerID = value
Me.SendPropertyChanged("CustomerID")
Me.OnCustomerIDChanged()
End If
End Set
End Property
G%&;/"#(<#AO#A(2"
private string _CustomerID;
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CustomerID",
DbType="NChar(5) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
[global::System.Runtime.Serialization.DataMemberAttribute(Order=1)]
public string CustomerID
{
get
{
return this._CustomerID;
}
set
{
if ((this._CustomerID != value))
{
this.OnCustomerIDChanging(value);
this.SendPropertyChanging();
this._CustomerID = value;
this.SendPropertyChanged("CustomerID");
this.OnCustomerIDChanged();
}
}
}
'-%$0!%#*.!%!9+/="!@%$0!%#*)"$+&,1 %=<6"2#%=3*=!3$D%2,%+.*3-!.%42$0%#$5*+%A"",(:*"&5%
702,%+$$326<$!%2.!-$28!,%!+#0%=!3,2,$+6"!%=3*=!3$D5%V2$0*<$%$02,%+$$326<$!@%#*)"$+&,1 %42""%-*$%
6!%,+G!.%$*%$0!%.+$+6+,!5%#$5*+%A"",(:*"&%0+,%,!G!3+"%=3*=!3$2!,%$0+$%#+-%6!%,!$%$*%#0+->!%
$0!%=!3,2,$!-#!%6!0+G2*3%,"2>0$"D5%'-%$0!%#*.!%!9+/="!@%$0!%;"$,!F&%=3*=!3$D%2.!-$28!,%$0!%
"43< #*$2/!%"3 &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.!3,%3!"+$!.%$*%+%#<,$*/!35
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private _Orders As EntitySet(Of [Order])
<Global.System.Data.Linq.Mapping.AssociationAttribute(Name:="Customer_Order", _
Storage:="_Orders", ThisKey:="CustomerID", OtherKey:="CustomerID"), _
Global.System.Runtime.Serialization.DataMemberAttribute(Order:=12, _
EmitDefaultValue:=False)> _
Public Property Orders() As EntitySet(Of [Order])
Get
If (Me.serializing _
AndAlso (Me._Orders.HasLoadedOrAssignedValues = False)) Then
Return Nothing
End If
Return Me._Orders
End Get
Set(ByVal value As EntitySet(Of [Order]))
Me._Orders.Assign(value)
End Set
End Property
G%&;/"#(<#AO#A(2"
private EntitySet<Order> _Orders;
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Customer_Order", Storage="_
Orders", ThisKey="CustomerID", OtherKey="CustomerID")]
[global::System.Runtime.Serialization.DataMemberAttribute(Order=12,
EmitDefaultValue=false)]
public EntitySet<Order> Orders
{
get
{
if ((this.serializing && (this._Orders.HasLoadedOrAssignedValues == false)))
{
return null;
}
% &!,,*-%TU%V0+$%',%&'()%$*% )&W% #*$2/!%"3" 43=
return this._Orders;
}
set
{
this._Orders.Assign(value);
}
}
C$%83,$%>"+-#!@%$02,%#*.!%"**;,%,2/2"+3%$*%$0!%#*.!%!9+/="!%1*3%#*)"$+&,1 @%6<$%
%#$5*+%A"",(:*"&%0+,%6!!-%3!="+#!.%6D%A))$'(!"($%A"",(:*"&5%702,%+$$326<$!%2.!-$28!,%
%K<,$*/!3,`L3.!3%+,%$0!%3!"+$2*-,02=%$0+$%-+G2>+$!,%13*/%$0!%K<,$*/!3,%$+6"!%$*%$0!%L3.!3,%
$+6"!5%70!%+$$326<$!%+",*%2.!-$28!,%$0!%;!D:,?%<,!.%*-%$0!%K<,$*/!3,%+-.%L3.!3,%$+6"!,5
70!%.+$+%$D=!%1*3%L3.!3,%2,%+%>!-!32#%!-$2$D%,!$%*1%6,4&,5%70!%>!-!32#%9%"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2>-% !"!#$%",!'"%+-.% !"!-&+:&,%+$$326<$!,%
$*%$0!%#"+,,%+-.%2$,%=3*=!3$2!,%6D%#0+->2->%$0!%;&,(!5(C!"($%B-$4&%=3*=!3$D%13*/%0$%&%$*%
2%(4(,&'"($%!55
&**;2->%+$%$0!%0$,"=>(%4 !"!#$%"&?"%#"+,,%$0+$%4+,%=3*.<#!.%6D%$0!%&'()%$*% )&%.!E
,2>-!3@%$0!%1*""*42->%#*.!%!9+/="!%,0*4,%$0!%#"+,,%.!8-2$2*-U
G%&;/"#(<#M+*)%/#N%*+3#A(2"
<Global.System.Data.Linq.Mapping.DatabaseAttribute(Name:="Northwind")> _
Partial Public Class NorthwindDataContext
Inherits System.Data.Linq.DataContext
Private Shared mappingSource As System.Data.Linq.Mapping.MappingSource = _
New AttributeMappingSource()
'more members here
End Class
G%&;/"#(<#AO#A(2"
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="Northwind")]
public partial class NorthwindDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = _
new AttributeMappingSource();
//more members here
}
702,%#"+,,%2,%+.*3-!.%42$0% !"!:!)&A"",(:*"&@%6D%402#0%D*<%,=!#21D%$0!%-+/!%*1%$0!%.+$+E
6+,!%$*%402#0%D*<%42""%#*--!#$5%702,%#"+,,%2-0!32$,%13*/% !"!#$%"&?"5%
702,%#"+,,%+",*%0+,%+%,$+$2#%8!".%#+""!.%+!33(%F;$*,'&@%402#0%.!1+<"$,%$*%+-%2-,$+-#!%*1%$0!%
A"",(:*"&-!33(%F;$*,'&%#"+,,5%702,%8!".%0*".,%$0!%/+==2->%6!$4!!-%$0!%#"+,,!,%2-%$0!%.*/+2-%
+-.%$0!%.+$+6+,!%+,%,=!#28!.%6D%+$$326<$!,%*-%$0!%!-$2$D%#"+,,!,5%P*<%#*<".%*=$%$*%3!="+#!%
$02,%*6]!#$%42$0%+-%2-,$+-#!%*1%I+5-!33(%F;$*,'&@%402#0%4*<".%!-+6"!%D*<%$*%!9$!3-+"2X!%$0!%
/+==2->,%$*%+-%AB&%8"!5
% &!,,*-%TU%V0+$%',%&'()%$*% )&W% #*$2/!%"3" 43?
70!%0$,"=>(%4 !"!#$%"&?"%#"+,,%#*-$+2-,%+%=<6"2#%=3*=!3$D%=!3%$D=!%*1%!-$2$D%#"+,,5%70!%
1*""*42->%#*.!%,+/="!%,0*4,%$0!%#*)"$+&,)%=3*=!3$DU
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Public ReadOnly Property Customers() As System.Data.Linq.Table(Of Customer)
Get
Return Me.GetTable(Of Customer)()
End Get
End Property
G%&;/"#(<#AO#A(2"
public System.Data.Linq.Table<Customer> Customers
{
get
{
return this.GetTable<Customer>();
}
}
(*$2#!%$0+$%$0!%=3*=!3$D%$D=!%2,%$0!%>!-!32#%@!:5&%#"+,,%*1%#*)"$+&,5%70!%@!:5&%#"+,,%=3*E
G2.!,%1<-#$2*-+"2$D%1*3%I<!3D2->@%2-,!3$2->@%<=.+$2->@%+-.%.!"!$2->5
70!%0$,"=>(%4 !"!#$%"&?"%#"+,,%+",*%#*-$+2-,%=+3$2+"%/!$0*.,%$0+$%D*<%#*<".%2/="!/!-$%
1*3%0**;2->%2-$*%(%)&,"@%*34!"&@%+-.%4&5&"&%*6]!#$,%2-%+-D%*1%$0!%$+6"!,J%=3*=!3$2!,%*-%$02,%#"+,,5
F%$%,+$,#B()4#@%-%1%*"#A($$"3-+($#%$2#A($-"8-#P*+$,# !"!#$%"&'"702,%,!#$2*-%!9+/2-!,%$0!%#*--!#$2*-%,$32->%+-.%0*4%$0!% !"!#$%"&?"%*6]!#$%<,!,%$0!%#*-E
-!#$2*-%,$32->%$*%#*--!#$%$*%$0!%.+$+6+,!5
Q(0#KI?R#-(#GRK#A($$"3-*#-(#B()4#@%-%1%*"
V0!-%D*<%+..!.%2$!/,%13*/% !3G!3%H9="*3!3@%D*<%+<$*/+$2#+""D%+..!.%$0!%.+$+6+,!%#*--!#E
$2*-%,$32->%$*%D*<3%=3*]!#$%+,%4!""5%'1%D*<%"**;%2-%D*<3%#*-8>%8"!@%D*<%42""%8-.%$0!%1*""*42->%
#*--!#$2*-%,$32->%,!$$2->U
A($<+,#:+/"
<connectionStrings>
<add name="LinqToSqlSampleCode.Properties.Settings.NorthwindConnectionString"
connectionString="Data Source=.;Initial Catalog=Northwind;Integrated
Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
&'()%$*% )&%<,!,%$0!%$3+.2$2*-+"%COL5(H7%;J5#$%%&'"($%%#"+,,%$*%*=!-%+%#*--!#$2*-%$*%
$0!% )&% !3G!3%.+$+6+,!5%'-%$02,%!9+/="!@%$0!%.+$+%,*<3#!%=3*=!3$D%2,%,!$%$*%+%=!32*.@%402#0%
/!+-,%$*%#*--!#$%$*%$0!%"*#+"% )&% !3G!3%2-,$+-#!5%'1%D*<%0+G!%*-"D% I"H9=3!,,%2-,$+""!.@%D*<3%
.+$+%,*<3#!%42""%6!%,!$%$*%5N )&HAY^H @%402#0%/!+-,%D*<%4+-$%$*%#*--!#$%$*%$0!% I"H9=3!,,%
2-,$+-#!%*1% )&% !3G!3%*-%D*<3%"*#+"%/+#02-!5
"4;@ #*$2/!%"3 &'()%$*% )&
#$%&'"()
:(4#-!"#"8%&9#C$(0#-!%-#'()#&)*-#1"#($#GRK#G"4D"4#STTT#(4#/%-"4#-(#)*"#KI?R#-(#GRK#1"H
3%)*"#'()#0+//#1"#-"*-"2#($#-!"#4"U)+4"&"$-*#-(#)*"#KI?R#-(#GRK6#B()#&)*-#1"#)*+$,#6?E #
:4%&"0(4C#V6W#(4#/%-"4#%*#0"//9#%$2#GRK#G"4D"4#STTT#!%*#&%$'#/+&+-%-+($*6
70!% !"!#$%"&?"%*6]!#$%0+,%+%#$%%&'"($%%=3*=!3$D@%+-.%,*/!%*1%$0!%#*-,$3<#$*3,%*1%$0!%
0$,"=>(%4 !"!#$%"&?"%+##!=$%+%#*--!#$2*-%,$32->5%70!%1*""*42->%#*.!%,+/="!%,0*4,%$0!%
=+3+/!$!3"!,,%#*-,$3<#$*3%1*3%$0!%0$,"=>(%4 !"!#$%"&?"%#"+,,U
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Public Sub New()
MyBase.New(Global.LinqToSqlSampleCode.MySettings.Default.NorthwindConnectionString, _
mappingSource)
OnCreated()
End Sub
G%&;/"#(<#AO#A(2"
public NorthwindDataContext() :
base(global::LinqToSqlSampleCode.Properties.Settings.Default.
NorthwindConnectionString,
mappingSource)
{
OnCreated();
}
'-%$02,%#*.!%!9+/="!@%$0!%=+3+/!$!3"!,,%#*-,$3<#$*3%/+;!,%+%#+""%$*%$0!%6+,!%#"+,,%
:% !"!#$%"&?"?%#*-,$3<#$*3%6<$%2,%=+,,2->%0$,"=>(%4#$%%&'"($%;",(%F@%402#0%2,%2-%$0!%#*-8><E
3+$2*-%8"!5%702,%/!+-,%$0+$%D*<%#+-%2-,$+-$2+$!%$0!%0$,"=>(%4 !"!#$%"&?"%42$0*<$%=+,,2->%
+-D%=+3+/!$!3@%+-.%D*<%+<$*/+$2#+""D%<,!%$0!%#*--!#$2*-%,$32->%$0+$J,%2-%D*<3%#*-8>%8"!5%C",*@%
D*<%#+-%!+,2"D%#0+->!%$0!%#*--!#$2*-%,$32->%2-%$0!%#*-8>%8"!%42$0*<$%3!I<232->%+%3!6<2".%*1%
$0!%+=="2#+$2*-5
>!%-J*#G"$-#-(#GRK#G"4D"49#%$2#>!"$#I*#I-#G"$-X
P*<%/2>0$%6!%4*-.!32->%40+$%;2-.%*1%I<!3D%2,%,!-$%$*% )&% !3G!35%',%$0!%I<!3D%!18#2!-$W%
V0!-%2,%$0!%I<!3D%,!-$%$*% )&% !3G!3W%702,%,!#$2*-%!9="*3!,%+%,2/="!%&'()%$*% )&%I<!3D%$*%
+-,4!3%$0!,!%I<!,$2*-,5
'-%$0!%1*""*42->%#*.!%,+/="!@%+%,2/="!%&'()%I<!3D%2,%=3!,!-$!.%$0+$%3!$32!G!,%+%"2,$%*1%
!/="*D!!,%40*,!%"+,$%-+/!,%,$+3$%42$0%ZO[%+-.%62-.,%$0!%3!,<"$%$*%+%V2-.*4,%Y3!,!-$+$2*-%
F*<-.+$2*-%:VYF?%.+$+%>32.5
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuSimpleLinq_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim employees = From emp In ctx.Employees
Where emp.LastName.StartsWith("D")
Select emp
% &!,,*-%TU%V0+$%',%&'()%$*% )&W% #*$2/!%"3" 4;5
dg.ItemsSource = employees
End Sub
G%&;/"#(<#AO#A(2"
private void mnuSimpleLinq_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var employees = from emp in ctx.Employees
where emp.LastName.StartsWith("D")
select emp;
dg.ItemsSource = employees;
}
702,%!9+/="!%,0*4,%$0!%<,!%*1%$0!%=+3+/!$!3"!,,%#*-,$3<#$*3%$*%#3!+$!%$0!%
%0$,"=>(%4 !"!#$%"&?"%*6]!#$5%70!3!%2,%-*%3!1!3!-#!%$*%+%#*--!#$2*-%2-%$02,%#*.!5%
%0$,"=>(%4 !"!#$%"&?"%0+,%+-%9+35$/&&)%=3*=!3$D%$0+$%#+-%6!%<,!.%2-%D*<3%&'()%I<!3D5%70!%
&'()%I<!3D%$0+$%1*""*4,%#3!+$!,%$0!%1K*&,/!:5&L9+35$/&&M%I<!3D%*6]!#$c%0*4!G!3@%3!/!/6!3%
$0+$%&'()%I<!3D%!9!#<$2*-%2,%.!1!33!.%<-$2"%$0!%3!,<"$%*1%$0!%I<!3D%2,%!-</!3+$!.5%70!%"+,$%
,$+$!/!-$%+,,2>-,%$0!%!/="*D!!,%I<!3D%*6]!#$%$*%$0!%1"&+);$*,'&%=3*=!3$D%*-%$0!%VYF%.+$+%
>32.5%70!%.+$+%>32.%42""%!-</!3+$!%$0!%!/="*D!!,%I<!3D%*6]!#$@%402#0%42""%#+<,!%$0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,%.218#<"$%$*%,!!%$0!%40*"!%I<!3D%42$02-%$0!%,/+""%
$**"%$2=5
!"#" (-+A"/8"9A("1! '."B-9'$(-C!%
B()#3%$#.$2#D%4+()*#KI?R#-(#GRK#2"1),#D+*)%/+Y"4*#($#-!"#I$-"4$"-6#L<-"4#+$*-%//+$,#($"#(<#
-!"*"#D+*)%/+Y"4*9#'()#0+//#*""#%#&%,$+<'+$,#,/%**#0!"$#!(D"4+$,#(D"4#-!"#D%4+%1/"6#A/+3C+$,#
-!"#&%,$+<'+$,#,/%**#-';+3%//'#2+*;/%'*#%#;(;H);#0+$2(0#0+-!#-!"#U)"4'#+$#%#&)3!#&(4"#
4"%2%1/"#<(4&%-6
C-*$0!3%4+D%$*%8-.%$0!%+-,4!3,%2,%$*%<,!%$0!%G$F%=3*=!3$D%*-%0$,"=>(%4 !"!#$%"&?"5%
702,%=3*=!3$D%+##!=$,%+%@&?"O,("&,%*6]!#$%+-.%42""%432$!%*<$%+""%I<!32!,%,*%D*<%#+-%#3!+$!%
+%%;",&!+O,("&,%*6]!#$%$0+$%3!1!3!-#!,%+%8"!%,*%D*<%#+-%432$!%!G!3D$02->%$*%+%8"!5%P*<%#+-%
+",*%+,,2>-%+%;",(%FO,("&,%$*%$0!%G$F%=3*=!3$D@%402#0%42""%,!-.%$0!% )&%I<!32!,%$*%+%/!/*3D%
,$3!+/@%+-.%$0!-%D*<%#+-%.2,="+D%$0!%#*-$!-$,5%70!%1*""*42->%#*.!%,+/="!%,0*4,%$0!%#3!+$2*-%
*1%+%;",(%FO,("&,%$0+$%2,%+,,2>-!.%$*%$0!%G$F%=3*=!3$D@%+-.%2$,%#*-$!-$,%+3!%.2,="+D!.%+1$!3%$0!%
I<!3D%2,%!9!#<$!.5
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuSimpleLinq_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim employees = From emp In ctx.Employees
Where emp.LastName.StartsWith("D")
Select emp
dg.ItemsSource = employees
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
G%&;/"#(<#AO#A(2"
private void mnuSimpleLinq_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var employees = from emp in ctx.Employees
where emp.LastName.StartsWith("D")
select emp;
dg.ItemsSource = employees;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
C1$!3%3<--2->%$02,%#*.!%,+/="!@%+%/!,,+>!%6*9%2,%.2,="+D!.@%+,%,0*4-%2-%F2><3!%QEe5%702,%
I<!3D%2,%3!$32!G2->%+""%#*"</-,%13*/%$0!%H/="*D!!,%$+6"!@%6<$%$0!%I<!3D%2-#"<.!,%+%>=&,&%
!"# (-+A"/8"9A("1! '."B-9'$(-C!%
B()#3%$#.$2#D%4+()*#KI?R#-(#GRK#2"1),#D+*)%/+Y"4*#($#-!"#I$-"4$"-6#L<-"4#+$*-%//+$,#($"#(<#
-!"*"#D+*)%/+Y"4*9#'()#0+//#*""#%#&%,$+<'+$,#,/%**#0!"$#!(D"4+$,#(D"4#-!"#D%4+%1/"6#A/+3C+$,#
-!"#&%,$+<'+$,#,/%**#-';+3%//'#2+*;/%'*#%#;(;H);#0+$2(0#0+-!#-!"#U)"4'#+$#%#&)3!#&(4"#
4"%2%1/"#<(4&%-6
% &!,,*-%TU%V0+$%',%&'()%$*% )&W% #*$2/!%"3" 4;7
#"+<,!%$*%=3*G2.!%$0!%8"$!32->%+$%$0!%.+$+6+,!5% )&% !3G!3%$0!-%=!31*3/,%$0!%8"$!32->%+-.%
3!$<3-,%$4*%3*4,%$*%D*<3%+=="2#+$2*-@%$0<,%=3*G2.2->%!18#2!-$% )&%1*3%D*<3%&'()%$*% )&%I<!3D5
&-.'%!"36="S!3!%2,%$0!% )&%I<!3D%$0+$%2,%,!-$%$*% )&% !3G!35
F2-+""D@%+-*$0!3%4+D%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*<%-!!.%$*%$02-;%+6*<$%=!31*3/+-#!%+-.%40!-%D*<%42""%D*<%$+;!%$0!%
=!31*3/+-#!%02$5%'-%*-!%!9$3!/!@%21%!G!3D%=3*=!3$D%4!3!%"+XD%"*+.!.@%$0!3!%4*<".%6!%+%#*,$%
+,,*#2+$!.%42$0%!,$+6"2,02->%$0!%#*--!#$2*-%!+#0%$2/!%+-.%$3+-,1!332->%$0!%.+$+5%7*%$0!%<,!3@%
$02,%/2>0$%/+;!%$0!%+=="2#+$2*-%1!!"%#0*==D%*3%!33+$2#5%'1%D*<J3!%1+23"D%#!3$+2-%$0+$%D*<%42""%<,!%
$0!%.+$+@%40D%-*$%=<""%$0!%=3*=!3$2!,%2-%*-!%#+""W%P*<%$+;!%+%62>%02$@%/+D6!%40!-%+%=+>!%2,%
.2,="+D!.%$*%$0!%<,!3@%6<$%$0!%=+>!%1!!",%#32,=%+1$!34+3.5%70!%#0*2#!%D*<%/+;!%.!=!-.,%*-%
$0!%0*4%/<#0%.+$+%42""%6!%$3+-,1!33!.%+-.%0*4%#!3$+2-%D*<%+3!%$0+$%D*<%42""%<,!%$0!%.+$+5%
V2$0%"+XD%"*+.2->@%D*<J3!%/+;2->%$0!%.!#2,2*-%$*%2-#<3%$0!%=!31*3/+-#!%#*,$%$*%3!$32!G!%$0!%
.+$+%40!-%D*<%-!!.%2$%6!#+<,!%D*<J3!%1+23"D%#!3$+2-%D*<%4*-J$%-!!.%$0!%.+$+%+-D4+D5%'-%
% &!,,*-%TU%V0+$%',%&'()%$*% )&W% #*$2/!%"3" 4;;
F2><3!%QEh@%$0!%Y0*$*%!-$3D%*-%$0!%9+35$/&&%!-$2$D%2,%,!$%$*% &5!/BG$!4&45%70!%1*""*42->%#*.!%
!9+/="!%,0*4,%$0!%!11!#$%*1%,!$$2->% &5!/BG$!4&4%$*%",*&U
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuLazyLoading_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim employee = (From emp In ctx.Employees
Where emp.LastName.StartsWith("D")
Select emp).First()
MessageBox.Show(sw.GetStringBuilder().ToString())
sw = New StringWriter()
ctx.Log = sw
Dim photo = New MemoryStream(Employee.Photo.ToArray())
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
G%&;/"#(<#AO#A(2"
private void mnuLazyLoading_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var employee = (from emp in ctx.Employees
where emp.LastName.StartsWith("Davolio")
select emp).First();
MessageBox.Show(sw.GetStringBuilder().ToString());
sw = new StringWriter();
ctx.Log = sw;
var photo = new MemoryStream(employee.Photo.ToArray());
MessageBox.Show(sw.GetStringBuilder().ToString());
}
702,%#*.!%,+/="!%3!$32!G!,%+%,2->"!%!/="*D!!%+-.%.2,="+D,%$0!% )&%,$+$!/!-$%$0+$%4+,%
>!-!3+$!.5%70!%#*.!%2,%$0!-%+6"!%$*%+##!,,%$0!%E=$"$%=3*=!3$D%,<##!,,1<""D@%+-.%$0!%I<!3D%$0+$%
4+,%3<-%2,%.2,="+D!.5%F2><3!%QETi%,0*4,%$0!%I<!32!,%$0+$%4!3!%!9!#<$!.%40!-%$02,%!9+/="!%
#*.!%0+,%6!!-%3<-5
"4;< #*$2/!%"3 &'()%$*% )&
&-.'%!"365@" 70!% )&%,$+$!/!-$,%+3!%,0*4-%$0+$%3!$32!G!%$0!%!/="*D!!%-+/!%+-.%$0!-%3!$32!G!%$0!%!/="*D!!J,%=0*$*5
70!%83,$%I<!3D%$0+$%3+-%.2.-J$%2-#"<.!%E=$"$@%!G!-%$0*<>0%$0!%&'()%!9=3!,,2*-%3!I<!,$!.%
$0!%40*"!%!/="*D!!%*6]!#$5%70!%E=$"$%=3*=!3$D%4+,%-*$%2-#"<.!.%6!#+<,!%$0!% &5!/BG$!4&4%
=3*=!3$D%4+,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
G%&;/"#(<#M+*)%/#N%*+3#A(2"
private void mnuBasicQuery_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var customers = from c in ctx.Customers
where c.CompanyName.Contains("Restaurant")
orderby c.PostalCode
select c;
dg.ItemsSource = customers;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
G%&;/"#(<#AO#A(2"
private void mnuBasicQuery_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
L<-"4#-!+*#/"**($9#'()#0+//#1"#%1/"#-(]
■ Y!31*3/%&'()%$*% )&%I<!32!,%42$0%8"$!32->%+-.%,*3$2->5
■ V32$!%&'()%$*% )&%,$+$!/!-$,%$0+$%2/="!/!-$%=3*]!#$2*-,5
■ Y!31*3/%2--!3%]*2-,%42$0%&'()%$*% )&5
■ Y!31*3/%*<$!3%]*2-,%42$0%&'()%$*% )&5
■ K3!+$!%+-.%!9!#<$!%>3*<=2->%+-.%+>>3!>+$2*-%42$0%&'()%$*% )&5
E*-+&%-"2#/"**($#-+&"]#^W#&+$)-"*
% &!,,*-%RU%H9!#<$2->%)<!32!,%_,2->%&'()%$*% )&% #*$2/!%"3" 4<5
var customers = from c in ctx.Customers
where c.CompanyName.Contains("Restaurant")
orderby c.PostalCode
select c;
dg.ItemsSource = customers;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
GRK#R)"4'
SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle],
[t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].
[Phone], [t0].[Fax]
FROM [dbo].[Customers] AS [t0]
WHERE [t0].[CompanyName] LIKE @p0
ORDER BY [t0].[PostalCode]
-- @p0: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [%Restaurant%]
70!%&'()%$*% )&%I<!3D%,!-.,%+%I<!3D%$*% )&% !3G!3%$0+$%2-#"<.!,%+%>=&,&%#"+<,!%+-.%+-%
$,4&,B:/%#"+<,!5%&**;2->%+$%$0!%,+/="!%#*.!@%$02,%"**;,%"2;!%+%G!3D%6+,2#%&'()%I<!3D@%<,2->%$0!%
#*)"$+&,)%=3*=!3$D%*-%$0!%0$,"=>(%4 !"!#$%"&?"%*6]!#$5%70!%;!D%0!3!%2,%$0+$%$0!%&'()%$*%
)&%=3*G2.!3%2,%#+=+6"!%*1%#*-,$3<#$2->%+-%!18#2!-$%I<!3D%$*%,!-.%$*% )&% !3G!35
74(5"3-+($*L-!%*1%$0!%=*$!-$2+"%=3*6"!/,%42$0%$0!%=3!G2*<,%I<!3D%2,%$0+$%+""%$0!%#*"</-%G+"<!,%13*/%
$0!%K<,$*/!3,%$+6"!%+3!%3!$<3-!.@%6<$%D*<%/2>0$%0+G!%-!!.!.%$*%3!$32!G!%*-"D%K<,$*/!3'O@%
K*/=+-D(+/!@%+-.%Y*,$+"K*.!5%P*<%#+-%<,!%+%=3*]!#$2*-%$*%"2/2$%$0!%#*"</-%G+"<!,%3!$<3-!.%
13*/% )&% !3G!35%70!%1*""*42->%#*.!%!9+/="!%.!/*-,$3+$!,%$0!%<,!%*1%=3*]!#$2*-,%$*%"2/2$%$0!%
3!$<3-!.%#*"</-%G+"<!,%13*/%$0!%K<,$*/!3,%$+6"!5
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuProjection_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim customers = From c In ctx.Customers
Where c.CompanyName.Contains("Restaurant")
Order By c.PostalCode
Select New With {c.CustomerID, c.CompanyName, c.PostalCode}
dg.ItemsSource = customers
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
G%&;/"#(<#AO#A(2"
private void mnuProjection_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var customers = from c in ctx.Customers
"4<4 #*$2/!%"3 &'()%$*% )&
where c.CompanyName.Contains("Restaurant")
orderby c.PostalCode
select new
{
c.CustomerID,
c.CompanyName,
c.PostalCode
};
dg.ItemsSource = customers;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
GRK#R)"4'
SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[PostalCode]
FROM [dbo].[Customers] AS [t0]
WHERE [t0].[CompanyName] LIKE @p0
ORDER BY [t0].[PostalCode]
-- @p0: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [%Restaurant%]
702,%#*.!%2-,$+-$2+$!,%+-%+-*-D/*<,%$D=!%$0+$%8"$!3,%*<$%#*"</-,5%K0+=$!3%\@%Z'-$3*.<#2->%
&'()@[%#*G!3,%+-*-D/*<,%$D=!,%+-.%=3*]!#$2*-,%2-%/*3!%.!$+2"5
I$$"4#_(+$*C-%2--!3%]*2-%=3*.<#!,%*<$=<$%*-"D%40!-%$0!%$4*%$+6"!,%D*<%+3!%]*2-2->%/+$#0%*-%$0!%<-2I<!%
;!D%$*%1*3!2>-%;!D5%'--!3%]*2-,%#+-%6!%2/="!/!-$!.%!+,2"D%42$0%&'()%$*% )&%6D%<,2->%$0!%,$+-E
.+3.%&'()%I<!3D%,D-$+95%70!%1*""*42->%&'()%I<!3D%=3*.<#!,%+-%2--!3%]*2-%*1%$0!%K<,$*/!3,%
$+6"!%$*%$0!%L3.!3,%$+6"!%+-.%3!$32!G!,%K<,$*/!3'O@%K*/=+-D(+/!@%L3.!3'O@%+-.%L3.!3O+$!%
6D%<,2->%I<!3D%!9$!-,2*-%/!$0*.,5
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuInnerJoin1_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim customers = ctx.Customers.Join(ctx.Orders,
Function(c) c.CustomerID,
Function(o) o.CustomerID,
Function(c, o) New With
{
c.CustomerID,
c.CompanyName,
o.OrderID,
o.OrderDate
}) _
.OrderBy(Function(r) r.CustomerID) _
.ThenBy(Function(r) r.OrderID)
dg.ItemsSource = customers
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
% &!,,*-%RU%H9!#<$2->%)<!32!,%_,2->%&'()%$*% )&% #*$2/!%"3" 4<7
G%&;/"#(<#AO#A(2"
private void mnuInnerJoin1_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var customers = ctx.Customers.Join(
ctx.Orders,
c => c.CustomerID,
o => o.CustomerID,
(c, o) => new
{
c.CustomerID,
c.CompanyName,
o.OrderID,
o.OrderDate
})
.OrderBy(r=>r.CustomerID)
.ThenBy((r=>r.OrderID));
dg.ItemsSource = customers;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
GRK#R)"4'
SELECT [t0].[CustomerID], [t0].[CompanyName], [t1].[OrderID], [t1].[OrderDate]
FROM [dbo].[Customers] AS [t0]
INNER JOIN [dbo].[Orders] AS [t1] ON [t0].[CustomerID] = [t1].[CustomerID]
ORDER BY [t0].[CustomerID], [t1].[OrderID]
_,2->%I<!3D%!9$!-,2*-%/!$0*.,%$*%=!31*3/%$0!%]*2-%=3*.<#!.%+%-2#!@%#"!+-% )&%I<!3D5%
K*<".%$02,%I<!3D%6!%432$$!-%+,%+%&'()%I<!3DW%'$%#+-@%+-.%$0!%1*""*42->%#*.!%,+/="!%=3*.<#!,%
$0!%,+/!%3!,<"$5
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuInnerJoin2_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim customers = From c In ctx.Customers
Join o In ctx.Orders
On c.CustomerID Equals o.CustomerID
Order By c.CustomerID, o.OrderID
Select New With
{
c.CustomerID,
c.CompanyName,
o.OrderID,
o.OrderDate
}
dg.ItemsSource = customers
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
"4<3 #*$2/!%"3 &'()%$*% )&
G%&;/"#(<#AO#A(2"
private void mnuInnerJoin_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var customers = from c in ctx.Customers
join o in ctx.Orders
on c.CustomerID equals o.CustomerID
orderby c.CustomerID, o.OrderID
select new
{
c.CustomerID,
c.CompanyName,
o.OrderID,
o.OrderDate
};
dg.ItemsSource = customers;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
GRK#R)"4'
SELECT [t0].[CustomerID], [t0].[CompanyName], [t1].[OrderID], [t1].[OrderDate]
FROM [dbo].[Customers] AS [t0]
INNER JOIN [dbo].[Orders] AS [t1] ON [t0].[CustomerID] = [t1].[CustomerID]
ORDER BY [t0].[CustomerID], [t1].[OrderID]
702,%2,%+%#"!+-E"**;2->%&'()%I<!3D@%+-.%2$%=3*.<#!.%+%-2#!@%!18#2!-$% )&%I<!3D5%'1%D*<%
"**;%$03*<>0%$0!%3!,<"$,%#+3!1<""D@%D*<%/2>0$%8-.%$0+$%$0!3!%+3!%$4*%#<,$*/!3,%40*%0+G!%-*$%
="+#!.%+-D%*3.!3,5%S*4%4*<".%D*<%;-*4%$0+$W%70!,!%$4*%#<,$*/!3,%+3!%/2,,2->%13*/%$0!%
*<$=<$%6!#+<,!%$0!D%.*-J$%/+$#0%<=%$*%+-D%*3.!3,5%70!%/2,,2->%#<,$*/!3%'O,%+3!%F' C%+-.%
YC^' 5%7*%,!!%+""%#<,$*/!3,@%D*<%-!!.%$*%432$!%+-%*<$!3%]*2-5
=)-"4#_(+$*C-%*<$!3%]*2-%=3*.<#!,%*<$=<$%*1%$0!%*<$!3%$+6"!@%!G!-%21%$0!%*<$!3%$+6"!%!"!/!-$%.*!,-J$%
/+$#0%$0!%2--!3%$+6"!5%7*%=!31*3/%+-%*<$!3%]*2-@%D*<%/<,$%=3*G2.!%#*.!%$*%2-.2#+$!%$0+$%D*<%
,$2""%4+-$%$0!%*<$!3%$+6"!%3*4@%!G!-%21%$0!3!%2,%-*%/+$#0%$*%$0!%2--!3%$+6"!5%P*<%#+-%=!31*3/%
*<$!3%]*2-,%6D%<,2->%$0!%N,$*3R$(%%!9$!-,2*-%/!$0*.@%+,%,0*4-%2-%$0!%1*""*42->%,+/="!%#*.!U
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuOuterJoin1_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim customers = ctx.Customers.GroupJoin(ctx.Orders, _
Function(c) c.CustomerID, _
Function(o) o.CustomerID, _
Function(c, o) New With
{
c.CustomerID,
% &!,,*-%RU%H9!#<$2->%)<!32!,%_,2->%&'()%$*% )&% #*$2/!%"3" 4<;
c.CompanyName,
.Orders = o
}) _
.SelectMany(Function(t) t.Orders.DefaultIfEmpty().Select( _
Function(ord) New With
{
t.CompanyName,
t.CustomerID,
.OrderID = CType(ord.OrderID, Nullable(Of Integer)),
.OrderDate = CType(ord.OrderDate, Nullable(Of DateTime))
})) _
.OrderBy(Function(r) r.CustomerID) _
.ThenBy(Function(r) r.OrderID)
dg.ItemsSource = customers
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
G%&;/"#(<#AO#A(2"
private void mnuOuterJoin1_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var customers = ctx.Customers.GroupJoin(
ctx.Orders,
c => c.CustomerID,
o => o.CustomerID,
(c, o) => new
{
c.CustomerID,
c.CompanyName,
Orders = o
})
.SelectMany(t=>t.Orders.DefaultIfEmpty().Select(ord=>
new
{
t.CompanyName,
t.CustomerID,
OrderID=(int?)ord.OrderID,
OrderDate=(DateTime?) ord.OrderDate}))
.OrderBy(r => r.CustomerID).ThenBy((r => r.OrderID));
dg.ItemsSource = customers;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
GRK#R)"4'
SELECT [t2].[CompanyName], [t2].[CustomerID],
[t2].[value] AS [OrderID2], [t2].[value2] AS [OrderDate]
FROM (
SELECT [t1].[OrderID] AS [value], [t1].[OrderDate] AS [value2],
[t0].[CompanyName], [t0].[CustomerID]
FROM [dbo].[Customers] AS [t0]
LEFT OUTER JOIN [dbo].[Orders] AS [t1] ON [t0].[CustomerID] = [t1].[CustomerID]
"4<< #*$2/!%"3 &'()%$*% )&
) AS [t2]
ORDER BY [t2].[CustomerID], [t2].[value]
702,%#*.!%,+/="!%$<3-!.%*<$%$*%6!%<>"D@%=32/+32"D%6!#+<,!%$0!%>*+"%4+,%$*%62-.%$02,%$*%$0!%
.+$+%>32.%+-.%,!!%$0!%,+/!%3!,<"$,%+,%$0!%2--!3%]*2-%6<$%42$0%+-%!9$3+%3*4%1*3%F' C%+-.%YC^' 5%
'-%$0!% )&%I<!3D@%+"$0*<>0%+%"!1$%*<$!3%]*2-%4+,%=!31*3/!.@%2$%4+,%-!,$!.%2-%+%,<6I<!3D@%+-.%
$0!%*-"D%3!,<"$%$0!%*<$!3%I<!3D%=3*G2.!,%2,%+%3!*3.!32->%*1%$0!%8!".,5
P*<%#+-%+",*%=!31*3/%+-%*<$!3%]*2-%6D%<,2->%+%&'()%I<!3D%42$0%$0!%(%"$%;!D4*3.%42$0%$0!%
]*2-5%70!%1*""*42->%2,%+%3!432$!%*1%$0!%=3!G2*<,%I<!3D@%.*-!%+,%+%&'()%I<!3D5
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuOuterJoin2_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim customers = From c In ctx.Customers
Group Join o In ctx.Orders
On c.CustomerID Equals o.CustomerID Into InJoin = Group
From outJoin In InJoin.DefaultIfEmpty()
Order By c.CustomerID, outJoin.OrderID
Select New With
{
c.CustomerID,
c.CompanyName,
.OrderID = CType(outJoin.OrderID, Nullable(Of Integer)),
.OrderDate = CType(outJoin.OrderDate, Nullable(Of DateTime))
}
dg.ItemsSource = customers
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
G%&;/"#(<#AO#A(2"
private void mnuOuterJoin2_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var customers = from c in ctx.Customers
join o in ctx.Orders
on c.CustomerID equals o.CustomerID into inJoin
from outJoin in inJoin.DefaultIfEmpty()
orderby c.CustomerID, outJoin.OrderID
select new
{
c.CustomerID,
c.CompanyName,
OrderID = (int?)outJoin.OrderID,
OrderDate = (DateTime?)outJoin.OrderDate
};w
dg.ItemsSource = customers;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
% &!,,*-%RU%H9!#<$2->%)<!32!,%_,2->%&'()%$*% )&% #*$2/!%"3" 4<=
GRK#R)"4'
SELECT [t0].[CustomerID], [t0].[CompanyName],
[t1].[OrderID] AS [OrderID2], [t1].[OrderDate] AS [OrderDate]
FROM [dbo].[Customers] AS [t0]
LEFT OUTER JOIN [dbo].[Orders] AS [t1] ON [t0].[CustomerID] = [t1].[CustomerID]
ORDER BY [t0].[CustomerID], [t1].[OrderID]
70!%&'()%I<!3D%2,%/<#0%-!+$!3%$0+-%$0!%=3!G2*<,%#*.!%!9+/="!@%402#0%4+,%2/="!/!-$!.%
6D%!9$!-,2*-%/!$0*.,5%'-%+..2$2*-@%$0!% )&%I<!3D%2,%+%-2#!@%#"!+-%"!1$%*<$!3%]*2-5
`4();+$,#%$2#L,,4",%-+($&'()%$*% )&%+",*%!-+6"!,%D*<%$*%=!31*3/%>3*<=2->%*=!3+$2*-,%$*%3!$32!G!%+>>3!>+$!%3!,<"$,5%
F*3%!9+/="!@%D*<%/2>0$%4+-$%$*%3!$32!G!%$0!%$*$+"%+/*<-$%*1%!+#0%*3.!35%7*%>!$%$0!%$*$+"%*1%
!+#0%*3.!3@%>!$%$0!%,</%*1%!+#0%*3.!3%2$!/%2-%$0!%L3.!3`O!$+2",%$+6"!5%70!%1*""*42->%#*.!%
,+/="!%,0*4,%0*4%>3*<=2->%+-.%+>>3!>+$2*-%#+-%,*"G!%$02,%=3*6"!/5
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Sub mnuAggregates_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim orders = From o In ctx.Order_Details
Group o By OrderID = o.OrderID Into grouped = Group
Select New With
{
.OrderID = OrderID,
.Total = grouped.Sum(Function(line) _
line.Quantity * line.UnitPrice * _
(1 - CType(line.Discount, Decimal)))
}
dg.ItemsSource = orders
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
G%&;/"#(<#AO#A(2"
private void mnuAggregates_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var orders = from o in ctx.Order_Details
group o by o.OrderID
into grouped
select new
{
OrderID = grouped.Key,
Total = grouped.Sum(
line=>line.Quantity * line.UnitPrice *
(1 - (decimal)line.Discount))
};
"4<> #*$2/!%"3 &'()%$*% )&
dg.ItemsSource = orders;
MessageBox.Show(sw.GetStringBuilder().ToString());
}
GRK#R)"4'
SELECT SUM([t1].[value]) AS [Total], [t1].[OrderID]
FROM (
SELECT (CONVERT(Decimal(29,4),[t0].[Quantity])) * [t0].[UnitPrice] *
(@p0 - (CONVERT(Decimal(33,4),[t0].[Discount]))) AS [value], [t0].[OrderID]
FROM [dbo].[Order Details] AS [t0]
) AS [t1]
GROUP BY [t1].[OrderID]
-- @p0: Input Decimal (Size = -1; Prec = 33; Scale = 4) [1]
702,%#*.!%,+/="!%>3*<=!.%$0!%L3.!3`O!$+2",%3*4,%6D%6,4&,1 %+-.%$0!-%#+"#<"+$!.%$0!%$*$+"%
*1%!+#0%*3.!3%6D%#+"#<"+$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*1%=+>!,%*1%#<,$*/!3,5%V0!-%,#3*""2->@%
$0!%;',$55%!G!-$%2,%$32>>!3!.@%+-.%D*<%,!!%$0!%=3!G2*<,%*3%-!9$%=+>!%*1%#<,$*/!3,5%702,%#*.!%
,+/="!%<,!,%$0!%;P(3%+-.%@!P&%/!$0*.,U
G%&;/"#(<#M+*)%/#N%*+3#A(2"
Private Const pageSize As Integer = 25
Private pageCount As Integer
Private customerCount As Integer
Private customers As IQueryable(Of Tuple(Of String, String))
Private sw As New StringWriter()
Private Sub mnuPaging_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
ctx.Log = sw
customers = From c In ctx.Customers
Order By c.CompanyName
% &!,,*-%RU%H9!#<$2->%)<!32!,%_,2->%&'()%$*% )&% #*$2/!%"3" 4<?
Select New Tuple(Of String, String)(c.CustomerID, c.CompanyName)
customerCount = customers.Count()
pageCount = customerCount / pageSize
If (pageCount * pageSize < customerCount) Then pageCount += 1
scrData.Minimum = 0
scrData.Maximum = pageCount
scrData.Visibility = Visibility.Visible
scrData.SmallChange = 1
scrData_Scroll(Nothing, Nothing)
End Sub
Private Sub scrData_Scroll(ByVal sender As System.Object, _
ByVal e As System.Windows.Controls.Primitives.ScrollEventArgs)
Dim customersDisplay = From c In customers
Select New With {.ID = c.Item1, .Name = c.Item2}
dg.ItemsSource = customersDisplay.Skip(CInt(scrData.Value) * pageSize).Take(pageSize)
End Sub
G%&;/"#(<#AO#A(2"
private const int pageSize = 25;
private int pageCount;
private int customerCount;
private IQueryable<Tuple<string,string>> customers;
StringWriter sw = new StringWriter();
private void mnuPaging_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
ctx.Log = sw;
customers = from c in ctx.Customers
orderby c.CompanyName
select
new Tuple<string,string>(c.CustomerID,c.CompanyName);
customerCount = customers.Count();
pageCount = customerCount / pageSize;
if (pageCount * pageSize < customerCount) pageCount++;
scrData.Minimum = 0;
scrData.Maximum = pageCount;
scrData.Visibility = Visibility.Visible;
scrData.SmallChange = 1;
scrData_Scroll(null, null);
}
private void scrData_Scroll(object sender,
System.Windows.Controls.Primitives.ScrollEventArgs e)
{
var customersDisplay = from c in customers
select new {ID = c.Item1, Name = c.Item2};
dg.ItemsSource = customersDisplay.Skip((int)scrData.Value * pageSize).Take(pageSize);
}
"4=@ #*$2/!%"3 &'()%$*% )&
GRK#R)"4'
SELECT COUNT(*) AS [value]
FROM [dbo].[Customers] AS [t0]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
SELECT [t1].[CustomerID] AS [item1], [t1].[CompanyName] AS [item2]
FROM (
SELECT ROW_NUMBER() OVER (
ORDER BY [t0].[CompanyName]) AS [ROW_NUMBER],
[t0].[CustomerID], [t0].[CompanyName]
FROM [dbo].[Customers] AS [t0]
) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1
ORDER BY [t1].[ROW_NUMBER]
-- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [0]
-- @p1: Input Int (Size = -1; Prec = 0; Scale = 0) [25]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
L1%$0!% )&%I<!32!,%$0+$%4!3!%3<-@%$0!%83,$%I<!3D%4+,%$*%>!$%$0!%#*<-$%*1%#<,$*/!3,@%402#0%
4+,%!9!#<$!.%40!-%$0!%'*)"$+&,)S#$*%"TU%#+""%4+,%/+.!5%70!%-!9$% )&%I<!3D%4+,%$*%3!$32!G!%
$0!%83,$%=+>!%*1%#<,$*/!3,5%'-%$02,%I<!3D@%$0!%$4*%=+3+/!$!3,%+3!%V3W@%$0!%#<33!-$%=+>!@%+-.%
V3X@%$0!%=+>!%,2X!5%70!,!%=+3+/!$!3,%+3!%,!$%$*%i%+-.%Rb@%3!,=!#$2G!"D5%70!%I<!3D%2$,!"1%<,!,%
$0!%<6O702-H9<%1<-#$2*-%+G+2"+6"!%2-% )&% !3G!3%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+-%6!%2-E
,$+""!.%13*/%$0!%K*.!%1*".!3%*-%$0!%#*/=+-2*-%KO5
'('"$&)' * L22#-!"#`PI
'-%$02,%!9!3#2,!@%D*<%/*.21D%$0!%VYF%+=="2#+$2*-%D*<%#3!+$!.%2-%&!,,*-%T%6D%#3!+$2->%$0!%j_'5%
'-%$0!%-!9$%!9!3#2,!@%D*<%+..%$0!%&'()%I<!32!,%$*%=*=<"+$!%$0!%,#3!!-5
*+% '-%k2,<+"% $<.2*%5(H7%RiTi@%#0**,!%F2"!%l%L=!-%l%Y3*]!#$5%L=!-%$0!%=3*]!#$%13*/%&!,,*-%
T%*3%"*#+$!%+-.%*=!-%$0!%,*"<$2*-%2-%$0!%m!>2-%1*".!3%1*3%$02,%"!,,*-5
% &!,,*-%RU%H9!#<$2->%)<!32!,%_,2->%&'()%$*% )&% #*$2/!%"3" 4=5
,+% '-% *"<$2*-%H9="*3!3@%.*<6"!E#"2#;%$0!%B+2-V2-.*459+/"%8"!%$*%*=!-%$0!%8"!%2-%$0!%VYF%
F*3/%O!,2>-!3%42-.*45
-+% L-%$0!%V2-.*4%$+6@%+..%+%G$!4&4%!G!-$%0+-."!35%V0!-%=3*/=$!.%1*3%+%-!4%
%9.&%"8!%45&,@%.*<6"!E#"2#;%$0!%(!4%HG!-$S+-."!3%*=$2*-5%P*<3%ACB&%,0*<".%"**;%"2;!%
$0!%1*""*42->U
G%&;/"#(<#M+*)%/#N%*+3#aLFK
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="Window_Loaded"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
G%&;/"#(<#AO#aLFK
<Window x:Class="OrderEntryProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="Window_Loaded"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
.+% 70!%ACB&%#*.!%#*-$+2-,%+%N,(4%.!8-2$2*-5%'-,2.!%$0!%>32.@%+..%$03!!%3*4%.!8-2$2*-,5%
70!%83,$%$4*%3*4,%,0*<".%0+G!%$0!23%8&(F="%=3*=!3$D%,!$%$*%A*"$@%+-.%$0!%"+,$%3*4%
,0*<".%0+G!%2$,%8&(F="%=3*=!3$D%,!$%$*%Zn[5%^!>+3."!,,%*1%D*<3%=3*>3+//2->%"+-><+>!@%
D*<3%ACB&%1*3%$0!%>32.%,0*<".%"**;%"2;!%$0!%1*""*42->U
aLFK
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
</Grid>
/+% '-%$0!%ACB&@%6!1*3!%$0!%!-.%*1%$0!%N,(4@%+..%+%-&%*5%'-,2.!%$0!%/!-<@%+..%-&%*Y
1"&+%!"!/!-$,%1*3% +G!%#+""!.%VHT9\]M@%(!4%L3.!3%#+""!.%VHT8EOME@%+-.%H92$%#+""!.%
VHT!YGK5%C1$!3%+..2->%$0!,!%2$!/,@%.*<6"!E#"2#;%!+#0%/!-<%2$!/%$*%+..%$0!%#"2#;%!G!-$%
0+-."!3%#*.!5%P*<3%ACB&%,0*<".%"**;%"2;!%$0!%1*""*42->5
aLFK
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
"4=4 #*$2/!%"3 &'()%$*% )&
</Grid.RowDefinitions>
<Menu>
<MenuItem Header="Save" Name="mnuSave" Click="mnuSave_Click" />
<MenuItem Header="New Order" Name="mnuOrder" Click="mnuOrder_Click" />
<MenuItem Header="Exit" Name="mnuExit" Click="mnuExit_Click" />
</Menu>
</Grid>
0+% '-%ACB&@%<-.!3%-&%*@%+..%+%#*/6*%6*9%#+""!.%RVU#TNKDVMEN5%K*-8><3!%$0!%#*/6*%
6*9%$*%6!%2-%j32.5^*4gZT[5%_-.!3%$0+$@%+..%+%"2,$%6*9%#+""!.%SNK8EOMEN5%K*-8><3!%
G()"H$?%$*%6!%2-%j32.5^*4g[R[5% !$%$0!%-!,F(%%=3*=!3$D%*1%6*$0%2$!/,%$*%b5%O*<6"!E#"2#;%
$0!%#*/6*%6*9%$*%+..%+%;&5&'"($%#=!%F&4%!G!-$%0+-."!3%$*%D*<3%#*.!5%P*<3%ACB&%
,0*<".%"**;%"2;!%$0!%1*""*42->U
aLFK
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Menu>
<MenuItem Header="Save" Name="mnuSave" Click="mnuSave_Click" />
<MenuItem Header="New Order" Name="mnuOrder" Click="mnuOrder_Click"/>
<MenuItem Header="Exit" Name="mnuExit" Click="mnuExit_Click" />
</Menu>
<ComboBox Grid.Row="1" Name="cmbCustomers" Margin="5"
SelectionChanged="cmbCustomers_SelectionChanged"/>
<ListBox Grid.Row="2" Name="lstOrders" Margin="5"/>
</Grid>
1+% H9$!-.%/+3;<=%2-%$0!%"2,$%6*9%!"!/!-$%$*%#*-8><3!%+%#<,$*/%$!/="+$!%$*%.2,="+D%
%L3.!3'O@%L3.!3O+$!@%+-.%^!I<23!.O+$!%13*/%$0!%L3.!3,%$+6"!5%702,%42""%3!I<23!%$0!%
G()"H$?%!"!/!-$%$*%6!%#*-G!3$!.%$*%0+G!%,!=+3+$!%,$+3$%+-.%!-.%$+>,5%P*<3%ACB&%1*3%
$0!%"2,$%6*9%,0*<".%"**;%"2;!%$0!%1*""*42->@%3!>+3."!,,%*1%=3*>3+//2->%"+-><+>!U
aLFK
<ListBox Grid.Row="2" Margin="5" Name="lstOrders">
<ListBox.ItemTemplate>
<DataTemplate>
<Border CornerRadius="5" BorderThickness="2"
BorderBrush="Blue" Margin="3">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Order #"
TextAlignment="Right" Width="40"/>
<TextBlock Name="txtOrderID"
Text="{Binding Path=OrderID}" Margin="5,0,10,0"
Width="30"/>
<TextBlock Text="Order Date:"
TextAlignment="Right" Width="80"/>
<TextBlock Name="txtOrderDate"
Text="{Binding Path=OrderDate, StringFormat={}{0:MM/dd/yyyy}}"
Margin="5,0,10,0" Width="75"/>
!"##$% &' ()"*+,-%. /+"0-"# 1#-%. !23/ ,$ 4/! !"#$%&'(' )*+
<TextBlock Text="Required Date:"
TextAlignment="Right" Width="80"/>
<TextBlock Name="txtRequiredDate"
Text="{Binding Path=RequiredDate, StringFormat={}{0:MM/dd/
yyyy}}"
Margin="5,0,10,0" Width="75"/>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
!" 56$$#" 7"8+. 9 4,:0, 7"8+..-%. ,$ 0+% ,6-# :;;<-*:,-$%=
><,6$+.6 ?$+ 6:@"%A, B0-,,"% :%? C-#+:< D:#-* &EFE $0 5G *$H" ?",I ?$+ 6:@" "%,"0"H
"%$+.6 J>K! ,$ ;0$H+*" : #*0""% ,6:, *:% #6$B : *+#,$L"0 <-#, -% ,6" *$L8$ 8$) :%H
,6" *+#,$L"0A# $0H"0# -% ,6" H:,: .0-H= M$+0 L:-% B-%H$B #6$+<H <$$N <-N" ,6" #:L;<"
-% O-.+0" PQF&= 2% ,6" %"), ")"0*-#"I ?$+ B-<< :HH *$H" ,$ ;$;+<:," ,6" B-%H$B=
,-./&%'(01)' R6-# -# ,6" *$L;<","H S12 ,6:, B-<< H-#;<:? *+#,$L"0# :%H $0H"0#=
#$#%&'(# ) !"#$%&'()*+,(,-"!%".($/(0%.12#3(0#$#
2% ,6-# ")"0*-#"I ?$+ :HH *$H" ,6:, -%*<+H"# !23/ T+"0-"# ,$ ,6" UVO :;;<-*:,-$% ?$+ B$0N"H
$% -% ()"0*-#" FI W>HH ,6" S12IX $Y ,6-# <"##$%= R6-# ;0$H+*"# : 0+%%-%. :;;<-*:,-$% Y$0 @-"B-%.
,6" H:,:I 8+, -% ,6" %"), <"##$%I ?$+A<< :HH *$H" ,$ :HH :% $0H"0 ,$ : *+#,$L"0 :%H #:@" -,=
*" 2% C-#+:< 4,+H-$ =3(R &EFEI *6$$#" O-<" 9 Z;"% 9 V0$["*,= Z;"% ,6" ;0$["*, Y0$L ,6"
;0"*"H-%. ")"0*-#"=
)" 2% 4$<+,-$% ();<$0"0I H$+8<"Q*<-*N ,6" K:-%U-%H$B=):L<=@8 $0 K:-%U-%H$B=):L<=*# \<"
,$ $;"% ,6" *$H"Q8"6-%H \<" Y$0 ,6" L:-% B-%H$B=
+" >HH : ;0-@:," \"<H ,$ ,6" ,$; $Y ,6" !"#$"#%&' *<:##I *:<<"H ()*I :%H #", -,# ,?;"
,$ +&,)-'"#%.!)!/&#)0*)] :<#$I -%#,:%,-:," ,6" *<:## :# #6$B% -% ,6" Y$<<$B-%. *$H"
#:L;<"'
')*( !"#$%&'( !23/ ,$ 4/!
4#512"(/6(7%.-#2(8#.%9( /:"
Private ctx As New NorthwindDataContext();
4#512"(/6( ;( /:"
private NorthwindDataContext ctx = new NorthwindDataContext();
," 2% ,6" $"#%&'12&!%0% "@"%, 6:%H<"0 L",6$HI :HH *$H" ,$ #:@" ()* ,$ :% :;;<-*:Q
,-$% ;0$;"0,? *:<<"H ()*I B6-*6 L:N"# ,6" ()* $8["*, :**"##-8<" Y0$L $,6"0 B-%H$B#=
><#$I :HH : !23/ T+"0? ,$ ;$;+<:," (34/56)&30,6 B-,6 : 75890 $Y 6),"#:I : 6),"#:
,6:, *$%,:-%# 5+#,$L"027 :%H 5$L;:%?3:L" Y0$L ,6" 5+#,$L"0# ,:8<"= 4", ,6"
."689!; 0340,<!)- ,$ H-#;<:? =)03> $Y ,6" 75890= R6" $"#%&'12&!%0% "@"%, 6:%H<"0
#6$+<H <$$N <-N" ,6" Y$<<$B-%.'
4#512"(/6(7%.-#2(8#.%9( /:"
Private Sub Window_Loaded(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Application.Current.Properties("ctx") = ctx
cmbCustomers.ItemsSource = From c In ctx.Customers
Select New Tuple(Of String, String)( _
c.CustomerID, _
c.CompanyName)
cmbCustomers.DisplayMemberPath = "Item2"
End Sub
4#512"(/6( ;( /:"
private void Window_Loaded(object sender, RoutedEventArgs e)
{
App.Current.Properties["ctx"] = ctx;
cmbCustomers.ItemsSource = from c in ctx.Customers
select new Tuple<string,string>
(
c.CustomerID,
c.CompanyName
);
cmbCustomers.DisplayMemberPath = "Item2";
}
-" >HH *$H" ,$ ,6" ?090()"&#/-!#:0% "@"%, 6:%H<"0 L",6$H ,$ 0",0-"@" ,6" #"<"*, *+#Q
,$L"0 -%Y$0L:,-$% :%H +#" -, ,$ B0-," : !23/ T+"0? Y$0 : <-#, $Y Z0H"027I Z0H"07:,"I
:%H ^"T+"#,7:," Y0$L ,6" Z0H"0# ,:8<"= M$+0 *$H" #6$+<H <$$N <-N" ,6" Y$<<$B-%.=
4#512"(/6(7%.-#2(8#.%9( /:"
Private Sub cmbCustomers_SelectionChanged(ByVal sender As System.Object, _
ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
Dim customer = CType(cmbCustomers.SelectedValue, Tuple(Of String, String))
If (customer Is Nothing) Then Return
lstOrders.ItemsSource =
From o In ctx.Orders
Where o.CustomerID = customer.Item1
Select New With _
{ _
o.OrderID, _
!"##$% &' ()"*+,-%. /+"0-"# 1#-%. !23/ ,$ 4/! !"#$%&'(' )*2
o.OrderDate, _
o.RequiredDate _
}
End Sub
4#512"(/6( ;( /:"
private void cmbCustomers_SelectionChanged(object sender,
SelectionChangedEventArgs e)
{
var customer = (Tuple<string,string>)cmbCustomers.SelectedValue;
if (customer == null) return;
lstOrders.ItemsSource =
from o in ctx.Orders
where o.CustomerID == customer.Item1
select new
{
o.OrderID,
o.OrderDate,
o.RequiredDate
};
}
." 2% ,6" @*") "@"%, 6:%H<"0 L",6$HI :HH *$H" ,$ "%H ,6" :;;<-*:,-$%= M$+0 *$H" #6$+<H
<$$N <-N" ,6" Y$<<$B-%.'
4#512"(/6(7%.-#2(8#.%9( /:"
Private Sub mnuExit_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Application.Current.Shutdown()
End Sub
4#512"(/6( ;( /:"
private void mnuExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
/" 56$$#" 7"8+. 9 4,:0, 7"8+..-%. ,$ 0+% ,6" :;;<-*:,-$%= 2Y ?$+ #"<"*, : *+#,$L"0 Y0$L
,6" *$L8$ 8$)I ,6" <-#, 8$) B-<< ;$;+<:," B-,6 ,6" <-#, $Y Z0H"027I Z0H"07:,"I :%H
"T+-0"H7:,"= 5<-*N ()-, ,$ #6+, H$B% ,6" :;;<-*:,-$%=
)"../&(4-55#!3R6-# <"##$% ;0$@-H"H H",:-<"H -%Y$0L:,-$% :8$+, 6$B ,$ 0+% !23/ ,$ 4/! T+"0-"#=
■ M$+ *:% +#" ,6" ,:8<" ;0$;"0,-"# $% ,6" .!)!/&#)0*) $8["*, ,$ 0+% !23/ T+"0-"#=
■ 2Y ?$+ ;0$@-H" : '-0,0 *<:+#"I !23/ ,$ 4/! B-<< *0":," : 4/! T+"0? ,6:, -%*<+H"# ,6"
'-0,0 *<:+#" ,$ <-L-, ,6" 0$B# 0",+0%"H ,$ ,6" :;;<-*:,-$%=
■ 2Y ?$+ ;0$@-H" : ;0$["*,-$% -% ?$+0 6090() *<:+#" ,$ <-L-, ,6" ;0$;"0,-"# ,6:, :0" #"<"*,Q
"HI !23/ ,$ 4/! B-<< *0":," : 4/! T+"0? ,6:, -%*<+H"# : L:,*6-%. *$<+L% \<,"0 ,$ <-L-,
,6" H:,: 0",+0%"H ,$ ,6" :;;<-*:,-$%=
')*3 !"#$%&'( !23/ ,$ 4/!
■ !23/ ,$ 4/! #+;;$0,# 8$,6 -%%"0 :%H $+,"0 [$-%#=
■ !23/ ,$ 4/! #+;;$0,# .0$+;-%. :%H :..0".:,-$%=
■ M$+ *:% +#" ,6" ?A"8 :%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-"@:<I #$ ?$+ L-.6, 8" B$%H"0-%. :8$+,
6$B ,$ *6:%." H:,:= !23/ -,#"<Y -# : T+"0?Q8:#"H ,$$< Y$0 H:,: 0",0-"@:<I 8+, ,6" !23/ ,$ 4/!
*<:##"# H$ ;0$@-H" L":%# Y$0 ?$+ ;"0Y$0L -%#"0,I +;H:,"I :%H H"<"," $;"0:,-$%# $% ?$+0 H:,:=
R6-# <"##$% Y$*+#"# $% ,6:,=
?6$"!($@%.(2"../&I(3/-(>%22(F"(#F2"($/J
■ 1%H"0#,:%H 6$B !23/ ,$ 4/! ,0:*N# *6:%."# :%H *:*6"# $8["*,#=
■ a%$B ,6" <-Y" *?*<" : !23/ ,$ 4/! "%,-,?=
■ K$H-Y? !23/ ,$ 4/! "%,-,-"#=
■ >HH %"B !23/ ,$ 4/! "%,-,-"#=
■ 7"<"," !23/ ,$ 4/! "%,-,-"#=
■ ()"*+," #,$0"H ;0$*"H+0"# +#-%. !23/ ,$ 4/! *<:##"#=
■ 4+8L-, :<< *6:%."# 8:*N ,$ ,6" H:,:8:#" #"0@"0=
■ 4+8L-, *6:%."# B-,6-% : ,0:%#:*,-$%=
K.$%5#$":(2"../&($%5"J(LM(5%&-$".
2% ,6" =3(R O0:L"B$0NI *<:##"# :0" 0"Y"0"%*" ,?;"#I :%H :% -%#,:%*" $Y : *<:## -# *:<<"H :%
&4F0()= (:*6 $8["*, 6:# : +%-T+" -H"%,-,?I :%H L:%? @:0-:8<"# *:% 0"Y"0 ,$ ,6" #:L" $8["*,= 2Y
,B$ @:0-:8<"# :0" 0"Y"00-%. ,$ ,6" #:L" $8["*,I *6:%."# L:H" ,60$+.6 $%" @:0-:8<" :0" :<#$
@-#-8<" ,60$+.6 ,6" $,6"0 @:0-:8<"=
U6"% B$0N-%. B-,6 0"<:,-$%:< H:,:8:#" ,:8<"#I : 0$B 6:# : ;0-L:0? N"? ,6:, -# +%-T+"I #$
%$ ,B$ 0$B# L:? #6:0" ,6" #:L" ;0-L:0? N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?$+ Y0$L ,6"
.!)!/&#)0*) $8["*,A# *:*6"=
2, L-.6, #""L 0:,6"0 B"-0H ,6:, T+"0?-%. Y$0 ,6" #:L" 0$B 0",+0%"H ,6" $0-.-%:< #,:," $Y
,6" 0$BI "@"% ,6$+.6 ,6" 0$B 6:H 8""% *6:%."H 8? :%$,6"0 :;;<-*:,-$%= 2% "##"%*"I ,6" %"B
H:,: B:# ,60$B% :B:?= R6" 0":#$% Y$0 ,6-# 8"6:@-$0 -# ,6:, !23/ ,$ 4/! %""H# ,6-# 8"6:@-$0 ,$
#+;;$0, $;,-L-#,-* *$%*+00"%*?= .!)!/&#)0*) *$%,:-%# : L",6$H *:<<"H ?543")/-!#:06I B6-*6
#"%H# :<< ?$+0 *6:%."# 8:*N ,$ ,6" H:,:8:#" ,:8<"= R6-# -# ");<:-%"H -% L$0" H",:-< <:,"0 -% ,6-#
<"##$%=
2Y ,6" H:,:8:#" *$%,:-%# : ,:8<" B-,6$+, : ;0-L:0? N"?I !23/ ,$ 4/! :<<$B# T+"0-"# ,$ 8"
#+8L-,,"H $@"0 ,6" ,:8<"I 8+, -, H$"#%A, :<<$B +;H:,"# 8"*:+#" ,6" Y0:L"B$0N *:%%$, -H"%,-Y?
B6-*6 0$B ,$ +;H:,"I .-@"% ,6" <:*N $Y : +%-T+" N"?=
#$%&'"()
O@"("B#5(>%22(9/&$#%&(A-".$%/&.(!"2#$":($/(5/:%63%&'(:#$#(-.%&'($@"( !"!#$%"&'"(92#..I(
./(F"(.-!"(3/-(-&:"!.$#&:($@"(!/2"(/6( !"!#$%"&'"(>@"&(9@#&'".(&"":($/(F"(."&$($/(
4,)(4"!="!H
2Y ,6" $8["*, 0"T+"#,"H 8? ,6" T+"0? -# -H"%,-\"H :# $%" ,6:, 6:# :<0":H? 8""% 0",0-"@"HI
%$ T+"0? -# ")"*+,"H :, :<<= R6" -H"%,-,? ,:8<" :*,# :# : *:*6"I #,$0-%. :<< ;0"@-$+#<? 0",0-"@"H
$8["*,#=
O@"()%6"( 392"(/6(#&(K&$%$35$%#-H"0 ,6" Y$<<$B-%. #*"%:0-$ -% B6-*6 :% $8["*, -# 0",0-"@"H 8? : !23/ ,$ 4/! T+"0? :%H
L$H-\"HI L:?8" #"@"0:< ,-L"#I +%,-< ?$+0 :;;<-*:,-$% -# 0":H? ,$ #"%H ,6" *6:%."# 8:*N ,$ ,6"
#"0@"0= M$+ L-.6, 0";":, ,6-# #*"%:0-$ +%,-< ?$+0 :;;<-*:,-$% %$ <$%."0 %""H# ,6" "%,-,? $8["*,
-%Y$0L:,-$%= 2Y ,6" "%,-,? $8["*, -# %$ <$%."0 0"Y"0"%*"H 8? ?$+0 :;;<-*:,-$%I ,6" $8["*, B-<<
8" 0"*<:-L"H 8? ,6" .:08:." *$<<"*,$0I [+#, <-N" :%? $,6"0 =3(R O0:L"B$0N $8["*,= ># <$%. :#
?$+ #+8L-,,"H ,6" *6:%."# ,$ ,6" .!)!/&#)0*) $8["*, 8? +#-%. -,# ?543")/-!#:06 L",6$HI
,6" H:,: -# #"%, :%H 0"L:-%# -% ,6" H:,:8:#"= D"*:+#" $Y ,6" H:,:8:#" ;"0#-#,"%*"I ?$+ *:%
T+"0? ,6" .!)!/&#)0*) $8["*, Y$0 ,6" #:L" H:,:I :%H ?$+ B-<< 0"*"-@" :% $8["*, ,6:, :;;":0#
:%H 8"6:@"# <-N" ,6" $0-.-%:< $8["*, ,6:, B:# .:08:."Q*$<<"*,"H= O0$L ,6:, ;"0#;"*,-@"I ,6"
.!)!/&#)0*) $8["*, ;0$@-H"# ,6" -<<+#-$% ,6:, ,6" <-Y",-L" $Y ,6" $8["*, -# 8"?$%H :%? #-%.<"
0+%Q,-L" -%#,:%,-:,-$%=
!"##$% `' 4+8L-,,-%. 56:%."# ,$ ,6" 7:,:8:#" !"#$%&'(' )*G
R6-# #"*,-$% Y$*+#"# $% : #-%.<" -%#,:%,-:,-$% $Y :% "%,-,? $8["*, #$ ,6:, : *?*<" 0"Y"0# ,$
,6" ,-L" #;:% $Y ,6:, $8["*, -%#,:%*" B-,6-% : ;:0,-*+<:0 0+%Q,-L" *$%,"),= R6-# *?*<" #,:0,#
B6"% ,6" .!)!/&#)0*) $8["*, 8"*$L"# :B:0" $Y : %"B -%#,:%*" :%H "%H# B6"% ,6" $8["*, $0
.!)!/&#)0*) $8["*, -# %$ <$%."0 %""H"H=
U6"% ?$+ 0",0-"@" $8["*,# Y0$L 4/! 4"0@"0 8? +#-%. ,6" .!)!/&#)0*) $8["*,I !23/ ,$ 4/!
:+,$L:,-*:<<? #,$0"# -%Y$0L:,-$% :8$+, ,6" "%,-,? $8["*,#= R6" .!)!/&#)0*) $8["*, ;0$@-H"#
:% $8["*,Q,0:*N-%. #"0@-*" ,6:, ,0:*N# ,6" #,:," $Y ?$+0 $8["*,#= !23/ ,$ 4/! $8["*,# :<B:?#
6:@" : #,:,"I :%H R:8<" PQF #6$B# ,6" #,:,"# : !23/ ,$ 4/! $8["*, *:% 6:@"= 2% ,"0L# $Y ;"0Q
Y$0L:%*" :%H 0"#$+0*" +#:."I $8["*, ,0:*N-%. +#-%. ,6" "%0#)");G),!(A"#:G60,H"(0 -# %$, *$#,<?I
8+, L:N-%. *6:%."# ,$ ,6" $8["*, 8? +#-%. ,6" (-!#:0G),!(A"#:G60,H"(0 *:% 8" *$#,<?=
$"H7%'(01' R6" 4,:,"# >@:-<:8<" ,$ !23/ ,$ 4/! Z8["*,#
5$"$% E%5 &-#$-I4
I#),!(A0% >% $8["*, %$, ,0:*N"H 8? !23/ ,$ 4/! H+" ,$ $%" $Y ,6" Y$<<$BQ
-%. 0":#$%#'
M$+ -%#,:%,-:,"H ,6" $8["*, ?$+0#"<Y=
R6" $8["*, B:# *0":,"H ,60$+.6 H"#"0-:<-b:,-$%=
R6" $8["*, *:L" Y0$L : H-YY"0"%, .!)!/&#)0*) $8["*,=
I#(-!#:0% >% $8["*, 0",0-"@"H 8? +#-%. ,6" *+00"%, .!)!/&#)0*) $8["*, :%H
%$, N%$B% ,$ 6:@" 8""% L$H-\"H #-%*" -, B:# *0":,"H=
<&66"49; &%"J0% >% $8["*, ,6:, -# :,,:*6"H ,$ : .!)!/&#)0*) $8["*, B-<< 8" -% ,6-#
#,:," +%<"## ?$+ #;"*-Y? $,6"0B-#" B6"% ?$+ :,,:*6=
7&C0=#60,)0% >% $8["*, %$, 0",0-"@"H 8? +#-%. ,6" *+00"%, .!)!/&#)0*) $8["*,I
B6-*6 B-<< #"%H :% "#60,) #,:,"L"%, ,$ ,6" H:,:8:#"=
7&C0I8%!)0% >% $8["*, N%$B% ,$ 6:@" 8""% L$H-\"H #-%*" -, B:# 0",0-"@"HI
B6-*6 #"%H# :% 58%!)0 #,:,"L"%, ,$ ,6" H:,:8:#"=
7&C0.090)0% >% $8["*, L:0N"H Y$0 H"<",-$%I B6-*6 B-<< #"%H : %090)0 #,:,"L"%,
,$ ,6" H:,:8:#"=
.090)0% >% $8["*, ,6:, 6:# 8""% H"<","H -% ,6" H:,:8:#"] ,6-# #,:," -# \%:<
:%H H$"# %$, :<<$B Y$0 :HH-,-$%:< ,0:%#-,-$%#=
R6" Y$<<$B-%. *$H" 0",0-"@"# : *+#,$L"0 Y0$L ,6" 3$0,6B-%H H:,:8:#"= R6-# *+#,$L"0 B-<<
8" +#"H -% ,6" "):L;<"# ,6:, Y$<<$B=
4#512"(/6(7%.-#2(8#.%9( /:"
Dim customer As Customer
Dim ctx As New NorthwindDataContext()
Private Sub mnuCreateEntity_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim sw = New StringWriter()
ctx.Log = sw
customer = (From c In ctx.Customers
')FJ !"#$%&'( !23/ ,$ 4/!
Where c.CustomerID = "ALFKI"
Select c).First()
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
4#512"(/6( ;( /:"
private Customer customer;
private NorthwindDataContext ctx = new NorthwindDataContext();
private void mnuCreateEntity_Click(object sender, RoutedEventArgs e)
{
var sw = new StringWriter();
ctx.Log = sw;
customer = (from c in ctx.Customers
where c.CustomerID == "ALFKI"
select c).First();
MessageBox.Show(sw.GetStringBuilder().ToString());
}
4,)(,-"!3
SELECT TOP (1) [t0].[CustomerID], [t0].[CompanyName],
[t0].[ContactName], [t0].[ContactTitle],
[t0].[Address], [t0].[City], [t0].[Region],
[t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]
FROM [dbo].[Customers] AS [t0]
WHERE [t0].[CustomerID] = @p0
-- @p0: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [ALFKI]
2% ,6-# "):L;<"I ,6"0" -# : #L:<< H-YY"0"%*" -% 8"6:@-$0 8",B""% C-#+:< D:#-* &EFE :%H 5G=
2% C-#+:< D:#-* &EFEI "@"0? ,-L" ?$+ *<-*N ,6" L"%+ $;,-$% ,$ 0+% ,6-# *$H"I ,6" T+"0? -# #"%,
,$ 4/! 4"0@"0= 2% 5GI $% ,6" \0#, *<-*N $Y ,6" L"%+ $;,-$%I ,6" 4/! T+"0? -# 0+%I 8+, #+8#"Q
T+"%, *<-*N# #-L;<? 0",+0% ,6" ")-#,-%. $8["*, ,6:,A# -% ,6" *:*6"= 2% "-,6"0 *:#"I ?$+ B$%A, #""
:%? *6:%."# ,6:, :0" L:H" ,$ ,6" 0$B -% ,6" H:,:8:#"= U"-0H_ D$,6 <:%.+:."# +#" ,6" #:L"
+%H"0<?-%. =3(R O0:L"B$0N *<:##"#I #$ ?$+ B$+<H ,6-%N ,6" 8"6:@-$0 #6$+<H 8" ,6" #:L"=
2Y ?$+ 0"@"0#"Q"%.-%""0 ,6" *$L;-<"H L",6$HI ?$+A<< \%H ,6:, ,6" C-#+:< D:#-* :%H 5G *$H"
;0$H+*" @"0? H-YY"0"%, 2%,"0L"H-:," !:%.+:." c2!d= ><#$I -Y ?$+ 0"@"0#"Q"%.-%""0 ,6" *$L;-<"H
3$0,6B-%H=7"#-.%"0=@8 :%H ,6" 3$0,6B-%H=7"#-.%"0=*# *$H"I ?$+A<< #"" ,6:, ,6"? ;0$H+*"
@"0? H-YY"0"%, 2! *$H" :# B"<<= R6" ;$-%, -# ,6:, ,6" +%H"0<?-%. Y0:L"B$0N -# ,6" #:L"I 8+, ,6"
H"#-.%"0Q."%"0:,"H *$H"I :%H ,6" *$L;-<"H 5G :%H C-#+:< D:#-* *$H"I :0" H-YY"0"%,=
R/:%63%&'(KB%.$%&'(K&$%$%".U6"% !23/ ,$ 4/! *0":,"# : %"B $8["*,I ,6" $8["*, -# -% I#(-!#:0% #,:,"= 2Y ?$+ L$H-Y? ,6"
$8["*,I ,6" .!)!/&#)0*) $8["*, B-<< *6:%." ,6" #,:," $Y ,6" $8["*, ,$ ,6" 7&C0I8%!)0% #,:,"=
R6-# -# B6:, ,6" .!)!/&#)0*) $8["*, +#"# ,$ H","0L-%" B6-*6 $8["*,# L+#, 8" ;"0#-#,"H B6"%
?$+ #+8L-, ?$+0 *6:%."#=
e$B H$"# ,6" .!)!/&#)0*) $8["*, N%$B B6"% ?$+ *6:%." ?$+0 $8["*,_ 56:%." %$,-\*:Q
,-$%# :0" :**$L;<-#6"H ,60$+.6 ,6" <,&80,);/-!#:"#: "@"%, ,6:,A# -% ;0$;"0,? #",,"0#= U6"%
!"##$% `' 4+8L-,,-%. 56:%."# ,$ ,6" 7:,:8:#" !"#$%&'(' )F1
.!)!/&#)0*) 0"*"-@"# : *6:%." %$,-\*:,-$%I -, *0":,"# : *$;? $Y ,6" $8["*, :%H *6:%."# -,#
#,:," ,$ 7&C0I8%!)0%=
^"*:<< ,6:,I :# ");<:-%"H -% !"##$% FI ,6" "%,-,? *<:## -L;<"L"%,# ,6"
=+&)"K;<,&80,);/-!#:"#: -%,"0Y:*"= M$+ *$+<H *0":," :% "%,-,? *<:## ,6:, H$"# %$, -L;<"Q
L"%, =+&)"K;<,&80,);/-!#:"#:I :%HI -% ,6:, #*"%:0-$I .!)!/&#)0*) L:-%,:-%# : *$;? $Y ,6"
@:<+"# ,6:, $8["*,# 6:H B6"% ,6"? B"0" \0#, -%#,:%,-:,"H= U6"% ?$+ *:<< ?543")/-!#:06I
.!)!/&#)0*) B-<< *$L;:0" ,6" *+00"%, :%H $0-.-%:< @:<+"#I \"<H 8? \"<HI ,$ H"*-H" B6",6"0 ,6"
$8["*, 6:# 8""% *6:%."H=
R6" Y$<<$B-%. *$H" #:L;<" L$H-\"# ,6" *+#,$L"0 $8["*, ,6:, B:# 0",0-"@"H -% ,6"
;0"@-$+# *$H" "):L;<" :%H ,6"% #+8L-,# ,6" *6:%." 8:*N ,$ ,6" H:,:8:#" 8? +#-%. ,6"
?543")/-!#:06 L",6$H $% ,6" .!)!/&#)0*) $8["*,= D" #+0" ,$ 0+% ,6" ;0"@-$+# "):L;<" ,$
*0":," ,6" *+#,$L"0 $8["*, \0#,=
4#512"(/6(7%.-#2(8#.%9( /:"
Private Sub mnuModifyEntity_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
customer.ContactName = "Marty " + DateTime.Now.ToLongTimeString()
ctx.SubmitChanges()
End Sub
4#512"(/6( ;( /:"
private void mnuModifyEntity_Click(object sender, RoutedEventArgs e)
{
customer.ContactName = "Marty " + DateTime.Now.ToLongTimeString();
ctx.SubmitChanges();
}
4,)(,-"!3
UPDATE [dbo].[Customers]
SET [ContactName] = @p10
WHERE ([CustomerID] = @p0) AND
([CompanyName] = @p1) AND
([ContactName] = @p2) AND
([ContactTitle] = @p3) AND
([Address] = @p4) AND
([City] = @p5) AND
([Region] IS NULL) AND
([PostalCode] = @p6) AND
([Country] = @p7) AND
([Phone] = @p8) AND
([Fax] = @p9)
-- @p0: Input NChar (Size = 5; Prec = 0; Scale = 0) [ALFKI]
-- @p1: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Alfreds Futterkiste]
-- @p2: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Maria Anders]
-- @p3: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Sales Representative]
-- @p4: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Obere Str. 57]
-- @p5: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Berlin]
-- @p6: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [12209]
-- @p7: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Germany]
-- @p8: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [030-0074321]
')F) !"#$%&'( !23/ ,$ 4/!
-- @p9: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [030-0076545]
-- @p10: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Marty 11:44:30 AM]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
2% ,6-# *$H" #:L;<"I ,6" '-0,0 *<:+#" -% ,6" 4/! T+"0? -# %$, #-L;<? <$$N-%. Y$0 : L:,*6Q
-%. ;0-L:0? N"?] -,A# *$L;:0-%. :<< \"<H# ,$ \%H : L:,*6I :%H -,A# +#-%. ,6" $0-.-%:< @:<+"# ,$
;"0Y$0L ,6" #":0*6= 2Y #$L"$%" L$H-\"H ,6:, 0$B -% ,6" H:,:8:#"I ?$+0 :;;<-*:,-$% B-<< %$,
\%H : L:,*6= R6-# B-<< ."%"0:," : *$%*+00"%*? "00$0=
2Y ?$+ L:N" : *6:%." ,$ : 0"<:,-$%#6-;I ,6" $8["*, ,6:, 6:# ,6" Y$0"-.% N"?I B6-*6 -# ,?;-Q
*:<<? ,6" *6-<H $8["*,I B-<< 6:@" ,6" :+,6$0-,:,-@" -%Y$0L:,-$% :8$+, ,6" ;:0"%,= Z;,-$%:<<?I
?$+ *:% 6:@" : 0"Y"0"%*" Y0$L ,6" ;:0"%, ,$ ,6" *6-<H= 2,A# ,6" ."%"0-* @#)");?0) $Y 7@#)"); :%H
@#)");L0K $Y 7@#)"); ,6:, L:-%,:-% 8-H-0"*,-$%:< 0"Y"0"%*"# ,$ "%#+0" *$%#-#,"%*? $Y $%"Q,$Q
L:%? :%H $%"Q,$Q$%" 0"<:,-$%#6-;#=
?::%&'(+">(K&$%$%".($/( !"!#$%"&'"> %"B $8["*, ?$+ -%#,:%,-:," ?$+0#"<Y -# +%N%$B% ,$ .!)!/&#)0*) :%H -# -% I#),!(A0% #,:,"
8"*:+#" %$ .!)!/&#)0*) *<:## -# :B:0" $Y ?$+0 $8["*,= M$+ *:% +#" ,6" =#60,)M#?543") L",6Q
$HI $0 ?$+ *:% :##-.% ?$+0 %"B $8["*, ,$ :% $8["*, ,6:, -# :<0":H? :,,:*6"HI :%H .!)!/&#)0*)
B-<< H-#*$@"0 ,6" %"B $8["*, #$ ,6:, -, *:% 8" #:@"H ,$ ,6" H:,:8:#"= M$+ *:% :<#$ *:<< ,6"
=#60,)N99M#?543") L",6$H B6"% ?$+ 6:@" L:%? $8["*,# ,$ -%#"0,=
R6" Y$<<$B-%. #:L;<" *$H" H"L$%#,0:,"# ,6" *0":,-$% $Y :% "L;<$?"" $8["*, ,6:, -# ,6"%
:HH"H ,$ ,6" .!)!/&#)0*) $8["*, :%H #+8L-,,"H ,$ ,6" H:,:8:#"=
4#512"(/6(7%.-#2(8#.%9( /:"
Private Sub mnuAddNewEntity_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim employee = New Employee With
{
.FirstName = "John",
.LastName = "Smith"
}
ctx.Employees.InsertOnSubmit(employee)
ctx.SubmitChanges()
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
4#512"(/6( ;( /:"
private void mnuAddNewEntity_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var employee = new Employee
{
FirstName = "John",
!"##$% `' 4+8L-,,-%. 56:%."# ,$ ,6" 7:,:8:#" !"#$%&'(' )F+
LastName = "Smith"
};
ctx.Employees.InsertOnSubmit(employee);
ctx.SubmitChanges();
MessageBox.Show(sw.GetStringBuilder().ToString());
}
4,)(,-"!3
INSERT INTO [dbo].[Employees]([LastName], [FirstName], [Title],
[TitleOfCourtesy], [BirthDate], [HireDate], [Address], [City], [Region],
[PostalCode], [Country], [HomePhone], [Extension], [Photo],
[Notes], [ReportsTo], [PhotoPath])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8,
@p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16)
SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]
-- @p0: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Smith]
-- @p1: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [John]
-- @p2: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p3: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p4: Input DateTime (Size = -1; Prec = 0; Scale = 0) [Null]
-- @p5: Input DateTime (Size = -1; Prec = 0; Scale = 0) [Null]
-- @p6: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p7: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p8: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p9: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p10: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p11: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p12: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- @p13: Input Image (Size = 8000; Prec = 0; Scale = 0) [Null]
-- @p14: Input NText (Size = -1; Prec = 0; Scale = 0) [Null]
-- @p15: Input Int (Size = -1; Prec = 0; Scale = 0) [Null]
-- @p16: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Null]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
2% ,6-# *$H" #:L;<"I :% "L;<$?"" $8["*, B:# *0":,"H :%H ;$;+<:,"H B-,6 H:,:= R6" "LQ
;<$?"" $8["*, -# ,6"% :HH"H ,$ ,6" (L;<$?""# ,:8<" $% ,6" .!)!/&#)0*) $8["*, 8? +#-%. ,6"
=#60,)M#?543") L",6$H= O-%:<<?I ,6" ?543")/-!#:06 L",6$H $% ,6" .!)!/&#)0*) $8["*, -#
*:<<"H ,$ #"%H ,6" %"B "L;<$?"" ,$ ,6" (L;<$?""# H:,:8:#" ,:8<"= R6" 4/! T+"0? ;"0Y$0L#
,6" -%#"0, :%H ,6"% ")"*+,"# : ?@2@/7 #,:,"L"%, ,$ 0",0-"@" ,6" ?/M<@1=.@+7=7OI B6-*6 -# ,6"
@:<+" $Y ,6" ;0-L:0? N"? ,6:, B:# *0":,"H= R6" (L;<$?""27 *$<+L% -# :% -H"%,-,? *$<+L% ,6:,
:+,$L:,-*:<<? ;0$@-H"# : %"B #"T+"%,-:< %+L8"0 Y$0 ":*6 0$B :HH"H= >Y,"0 ,6" *$H" 0+%#I ?$+
*:% <$$N :, ,6" @389&;00=. ;0$;"0,? ,$ #"" ,6" 27 ,6:, B:# ."%"0:,"H=
0"2"$%&'(K&$%$%".U6"% ?$+ B:%, ,$ H"<"," 0$B# Y0$L : H:,:8:#" ,:8<"I ?$+ *:% *:<< ,6" .090)0M#?543") $0
.090)0N99M#?543") L",6$H# $% ,6" :;;0$;0-:," ,:8<" ;0$;"0,? $Y ,6" .!)!/&#)0*) $8["*,=
7"<",-%. ,?;-*:<<? 0"T+-0"# ?$+ ,$ <$*:," ,6" -,"L $0 -,"L# ,$ 8" H"<","H :%H ,6"% ;:## ,6"L
,$ ,6" :;;0$;0-:," :Y$0"L"%,-$%"H L",6$H= R6" Y$<<$B-%. -# : *$H" #:L;<" ,6:, #6$B# 6$B
,$ H"<"," :% "L;<$?"" B6$#" (L;<$?""27 -# FE=
')F( !"#$%&'( !23/ ,$ 4/!
4#512"(/6(7%.-#2(8#.%9( /:"
Private Sub mnuDeleteEntity_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
Dim employee = (From emp In ctx.Employees
Where emp.EmployeeID = 10
Select emp).First()
ctx.Employees.DeleteOnSubmit(employee)
ctx.SubmitChanges()
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
4#512"(/6( ;( /:"
private void mnuDeleteEntity_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
var employee = (from emp in ctx.Employees
where emp.EmployeeID == 10
select emp).First();
ctx.Employees.DeleteOnSubmit(employee);
ctx.SubmitChanges();
MessageBox.Show(sw.GetStringBuilder().ToString());
}
4,)(,-"!3
SELECT TOP (1) [t0].[EmployeeID], [t0].[LastName], [t0].[FirstName],
[t0].[Title], [t0].[TitleOfCourtesy], [t0].[BirthDate], [t0].[HireDate],
[t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country],
[t0].[HomePhone], [t0].[Extension], [t0].[Notes],
[t0].[ReportsTo], [t0].[PhotoPath]
FROM [dbo].[Employees] AS [t0]
WHERE [t0].[EmployeeID] = @p0
-- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [10]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
DELETE FROM [dbo].[Employees] WHERE ([EmployeeID] = @p0) AND
([LastName] = @p1) AND
([FirstName] = @p2) AND ([Title] IS NULL) AND
([TitleOfCourtesy] IS NULL) AND ([BirthDate] IS NULL) AND
([HireDate] IS NULL) AND ([Address] IS NULL) AND
([City] IS NULL) AND ([Region] IS NULL) AND
([PostalCode] IS NULL) AND ([Country] IS NULL) AND
([HomePhone] IS NULL) AND ([Extension] IS NULL) AND
([ReportsTo] IS NULL) AND ([PhotoPath] IS NULL)
-- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [10]
-- @p1: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [Smith]
-- @p2: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [John]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
!"##$% `' 4+8L-,,-%. 56:%."# ,$ ,6" 7:,:8:#" !"#$%&'(' )F2
R6-# *$H" #:L;<" #,:0,# 8? T+"0?-%. Y$0 ,6" "L;<$?"" B6$#" (L;<$?""27 -# FE= 2Y ?$+ 6:H
0+% ,6" ;0"@-$+# *$H" #:L;<" ,6:, :HH# :% "L;<$?"" %:L"H f$6% 4L-,6I ?$+ B$+<H 6:@" :%
"L;<$?"" B-,6 :% (L;<$?""27 $Y FE= 3"),I ,6-# *$H" #:L;<" ")"*+,"# ,6" .090)0M#?543")
L",6$H $% ,6" (L;<$?""# 7!490 ;0$;"0,? ,6:,A# $% ,6" .!)!/&#)0*) $8["*,= O-%:<<?I ,6" *:<< -#
L:H" ,$ ,6" ?543")/-!#:06 L",6$HI B6-*6 #"%H# ,6" %090)0 *$LL:%H ,$ ,6" H:,:8:#"=
2% ,6" 4/! T+"0?I ,6" 0$B 6:H ,$ 8" 0",0-"@"H ,$ 8" H"<","H= 2Y ?$+ B:%, ,$ H"<"," :%
"L;<$?""A# %:L" B-,6$+, 0",0-"@-%. -, \0#,I -L;<"L"%, : #,$0"H ;0$*"H+0" ,6:, ,:N"# ,6" 27 $Y
,6" "L;<$?"" :# : ;:0:L","0=
!23/ ,$ 4/! H$"# %$, #+;;$0, $0 0"*$.%-b" *:#*:H"QH"<"," $;"0:,-$%#= 2Y ?$+ B:%, ,$
H"<"," : 0$B -% : ,:8<" ,6:, 6:# *$%#,0:-%,# :.:-%#, -,I ?$+ 6:@" ,B$ $;,-$%#= R6" \0#, $;,-$%
-# ,$ #", ,6" Z3 7(!(R( 5>45>7( 0+<" -% ,6" Y$0"-.%QN"? *$%#,0:-%, -% ,6" H:,:8:#"= R6-#
:+,$L:,-*:<<? H"<","# ,6" *6-<H 0$B# B6"% : ;:0"%, 0$B -# H"<","H= R6" $,6"0 $;,-$% -# ,$ B0-,"
?$+0 $B% *$H" ,$ \0#, H"<"," ,6" *6-<H $8["*,# ,6:, B$+<H $,6"0B-#" ;0"@"%, ,6" ;:0"%, $8["*,
Y0$L 8"-%. H"<","H=
N.%&'(4$/!":(S!/9":-!".2% !"##$% FI ?$+ B"0" -%,0$H+*"H ,$ ,6" !23/ ,$ 4/! H"#-.%"0I :%H ,6-# <"##$% L"%,-$%"H ,6:,
?$+ *:% :HH #,$0"H ;0$*"H+0"# ,$ ,6" !23/ ,$ 4/! H"#-.%"0= R6" #,$0"H ;0$*"H+0"# ?$+ :HH
,$ ,6" H"#-.%"0 8"*$L" L",6$H# $% ?$+0 .!)!/&#)0*) $8["*,I B6-*6 L:N"# *:<<-%. : #,$0"H
;0$*"H+0" T+-," ":#?= R6" Y$<<$B-%. #:L;<" *$H" H"L$%#,0:,"# ,6" *:<< ,$ : #,$0"H ;0$*"H+0"
*:<<"H /56)M,%0,P"6)I B6-*6 *$%,:-%# : ?@2@/7 #,:,"L"%, ,6:, 0",+0%# : <-#, $Y :<< ,6" ;0$H+*,#
: *+#,$L"0 6:# ;+0*6:#"H=
4#512"(/6(7%.-#2(8#.%9( /:"
Private Sub mnuStoredProc_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs)
Dim ctx = New NorthwindDataContext()
Dim sw = New StringWriter()
ctx.Log = sw
dg.ItemsSource = ctx.CustOrderHist("ALFKI")
MessageBox.Show(sw.GetStringBuilder().ToString())
End Sub
4#512"(/6( ;( /:"
private void mnuStoredProc_Click(object sender, RoutedEventArgs e)
{
var ctx = new NorthwindDataContext();
var sw = new StringWriter();
ctx.Log = sw;
dg.ItemsSource = ctx.CustOrderHist("ALFKI");
MessageBox.Show(sw.GetStringBuilder().ToString());
}
4,)(,-"!3
EXEC @RETURN_VALUE = [dbo].[CustOrderHist] @CustomerID = @p0
')F3 !"#$%&'( !23/ ,$ 4/!
-- @p0: Input NChar (Size = 5; Prec = 0; Scale = 0) [ALFKI]
-- @RETURN_VALUE: Output Int (Size = -1; Prec = 0; Scale = 0) [Null]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1
R6-# *$H" -# T+-," #-L;<"= M$+ ;:## ,6" *+#,$L"0 27 $Y : *+#,$L"0 c>!Oa2 -% ,6-# *:#"dI :%H
?$+ .", 8:*N : <-#, $Y $8["*,# ,6:, *:% 8" ":#-<? 8$+%H ,$ ,6" H:,: .0-H=
2Y ?$+ *:<< #,$0"H ;0$*"H+0"# ,6:, 6:@" MI7<I7 ;:0:L","0#I ,6" L",6$H *0":,"H H"\%"#
;:0:L","0# :# C;L0KGQ5G ,0KRI B6-*6 .-@"# ?$+ :**"## ,$ ,6" 0",+0%"H @:<+"=
N.%&'( !"!#$%"&'"($/(4-F5%$( @#&'".>Y,"0 ?$+ +#" !23/ ,$ 4/! ,$ 0",0-"@" H:,:I ?$+ L-.6, L:N" L:%? *6:%."# ,$ ,6" $8["*,#I 8+,
0"L"L8"0 ,6:, ,6"#" *6:%."# :0" L:H" $%<? ,$ ?$+0 -%QL"L$0? $8["*,#= 3$ *6:%."# :0" #"%,
,$ ,6" H:,:8:#" +%,-< ?$+ *:<< ,6" ?543")/-!#:06 L",6$H $% ,6" .!)!/&#)0*) $8["*,=
U6"% ?$+ *:<< ,6" ?543")/-!#:06 L",6$HI ,6" .!)!/&#)0*) $8["*, ,0-"# ,$ ,0:%#<:," ?$+0
*6:%."# -%,$ 4/! *$LL:%H#= ><,6$+.6 ?$+ *:% +#" ?$+0 $B% *+#,$L <$.-* ,$ $@"00-H" ,6"#"
:*,-$%#I ,6" $0H"0 $Y #+8L-##-$% -# $0*6"#,0:,"H 8? : (-!#:0G8,&(066&,=
R6" \0#, ,6-%. ,6" *6:%." ;0$*"##$0 B-<< H$ -# "):L-%" ,6" #", $Y N%$B% $8["*,# ,$ H","0Q
L-%" B6",6"0 %"B $8["*,# 6:@" 8""% :,,:*6"H= 2Y #$I ,6"#" %"B $8["*,# :0" :HH"H ,$ ,6" #",
$Y ,0:*N"H $8["*,#=
3"),I :<< $8["*,# ,6:, 6:@" ;"%H-%. *6:%."# :0" $0H"0"H -%,$ : #"T+"%*" 8:#"H $% ,6"
H";"%H"%*-"# 8",B""% ,6" $8["*,#= Z8["*,# B6$#" *6:%."# H";"%H $% $,6"0 $8["*,# B-<< 8"
<$*:,"H :Y,"0 ,6"-0 H";"%H"%*-"#=
R6" .!)!/&#)0*) $8["*, ,6"% #,:0,# : ,0:%#:*,-$% ,$ "%*:;#+<:," ,6" -%H-@-H+:< "#60,)I
58%!)0I :%H %090)0 *$LL:%H#=
O-%:<<?I ,6" *6:%."# ,$ ,6" $8["*,# :0" #"%, ,$ ,6" H:,:8:#" #"0@"0I $%" 8? $%"I :# 4/!
*$LL:%H#= >%? "00$0# H","*,"H 8? ,6" H:,:8:#" *:+#" ,6" #+8L-##-$% ;0$*"## ,$ #,$;I :%H
:% ")*";,-$% -# ,60$B%= R6" ,0:%#:*,-$% 0$<<# 8:*N :<< *6:%."# ,$ ,6" H:,:8:#"= .!)!/&#)0*)
#,-<< 6:# :<< *6:%."#I #$ ?$+ *:% ,0? ,$ *$00"*, ,6" ;0$8<"L :%H *:<< ?543")/-!#:06 :.:-% -Y
%""H 8"=
O$<<$B-%. #+**"##Y+< ")"*+,-$% $Y ?543")/-!#:06I :<< $8["*,# N%$B% ,$ ,6" .!)!/&#)0*)
$8["*, :0" -% ,6" I#(-!#:0% #,:,"= cR6" #-%.<" ")*";,-$% -# 0";0"#"%,"H 8? ,6$#" ,6:, 6:@"
8""% #+**"##Y+<<? H"<","H Y0$L ,6" H:,:8:#"I B6-*6 :0" -% .090)0% #,:," :%H +%+#:8<" -% ,6:,
.!)!/&#)0*) -%#,:%*"=d
4-F5%$$%&'( @#&'".(%&(#(O!#&.#9$%/&!23/ ,$ 4/! #+;;$0,# ,60"" ,0:%#:*,-$% L$H"<# B6"% #+8L-,,-%. ?$+0 *6:%."# 8:*N ,$ ,6"
H:,:8:#"= R6-# #"*,-$% *$@"0# ,6"#" L$H"<# -% ,6" $0H"0 $Y *6"*N# ;"0Y$0L"H=
■ %KLM@N@A'7:NDM'$OD;9DNA@:; 2Y ,6" 7,!#6!()"&# ;0$;"0,? -# #", ,$ : c=.47,!#6!()"&#d
,0:%#:*,-$%I ,6" ?543")/-!#:06 *:<< -# ")"*+,"H -% ,6" *$%,"), $Y ,6" #:L" ,0:%#:*,-$%=
2% ,6-# #*"%:0-$I ?$+ :0" 0"#;$%#-8<" Y$0 *$LL-,,-%. $0 0$<<-%. 8:*N ,6" ,0:%#:*,-$%