ToolStripDropDownButton

The ToolStripDropDownButton allows you to create a drop-down menu that appears when the button is clicked. At design time, you can create the menu by typing text for menu items in the menu designer, as shown in Figure 4-2. Figure 4-2 Creating a menu with the ToolStripDropDownButton Figure 4-2 Creating a menu with the ToolStripDropDownButton Each menu item has its own ToolStripMenuItemClick event that you can respond to.

Take a Practice Test Gsl

The practice tests on this book's companion CD offer many options. For example, you can test yourself on just the content covered in this chapter, or you can test yourself on all the 70-526 certification exam content. You can set up the test so that it closely simulates the experience of taking a certification exam, or you can set it up in study mode so that you can look at the correct answers and explanations after you answer each question. For details about all the practice test options...

Creating and Starting a New Thread

The Thread object requires a delegate to the method that will serve as the starting point for the thread. This method must be a Sub void in C method and must have either no parameters or take a single Object parameter. In the latter case, the Object parameter is used to pass any required parameters to the method that starts the thread. Once a thread is created, you can start it by calling the Thread.Start method. The following example demonstrates how to create and start a new thread Dim...

Lab Bulk Copying

In this lab you will bulk copy data from one table to another. Creating Tables to Copy Data into To demonstrate how to perform a bulk copy operation, you need tables to copy data into. A quick way to create the tables is to use Server Explorer and the Visual Database Tools to do some cutting and pasting Use the following steps to create CustomerHis-tory and OrderHistory tables, which you will use to bulk copy the Customer and Order table data into. 1. In Server Explorer, expand the Tables node...

The PropertyGrid Control

The PropertyGrid control is essentially a user-configurable version of the Properties window in Visual Studio. The PropertyGrid control allows the user to set the properties of controls or components in a graphical interface at run time. Figure 12-1 shows the PropertyGrid control in a form. The text associated with the control. Figure 12-1 The PropertyGrid control in a form Figure 12-1 The PropertyGrid control in a form The PropertyGrid control that is shown in Figure 12-1 is configured to...

Configuring the MaskedTextBox for User Input

In addition to the Mask property, the MaskedTextBox control has several properties that affect how the control behaves when receiving user input. The AsciiOnly property determines if only ASCII characters are allowed as input when set to True, it restricts input to A-Z and a-z. Other inputs are rejected. You can set the control to notify users when an error has been committed by setting the BeepOnError property to True. The SkipLiterals property determines whether literal characters should be...

Creating a Command Object that Returns XML Data

You can also execute commands that return data formatted as XML. To execute commands that return XML data, create commands that run SQL statements that return XML or retrieve existing XML-formatted data from your database. Set the CommandText property to a SQL statement that returns XML and call the ExecuteXMLReader method of the command. Calling the ExecuteXMLReader method returns a System.Xml.XmlReader object, which is similar to a data reader except that it is specifically for accessing...

Lesson Review Wli

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each choice is right or wrong are located in the Answers section at the end of the book. 1. Which of the following code samples will create a new instance of the XmlReader class Dim aReader As XmlReader aReader XmlReader.Create aReader aReader Dim...

Working with BLOBs

Saving and fetching binary data presents interesting problems that are typically not encountered when querying standard rows of data. The problems arise because you will probably not want to move the entire BLOB in one piece but will likely need to break it up into smaller portions. For example, consider having to move a large binary that is several megabytes in size. Loading the entire BLOB into a variable consumes a lot of memory and can seriously affect the performance of your application....

Retrieving Information from the Parent Form

Once the parent form has been set, you can retrieve information from it by casting the ParentForm property to the appropriate type and then reading its properties, as shown in the following example. This example assumes an instance of a dialog box called DialogForm and that the ParentForm property has been set to an instance of a form called Form1. aForm CType DialogForm.ParentForm, Form1 ' You can now read the information of the parent form aForm Form1 DialogForm.ParentForm You can now read...

Correct Answer C Iax

A. Incorrect. The GetParentRow and GetChildRows methods are not members of the DataSet. B. Incorrect. The GetParentRow and GetChildRows methods are not members of the DataTable. C. Correct. Calling the GetParentRow and GetChildRows methods of a DataRow is the correct way to programmatically access related records in DataTable objects. D. Incorrect. The ParentColumns and ChildColumns are collections of the columns that participate in the relation.

Correct Answers B and D 1

A. Incorrect. Calling the EndExecuteNonQuery method before the Statement-Completed event fires is incorrect because BeginExecuteNonQuery does not return any data. B. Correct. Calling the EndExecuteReader method before the Statement-Completed event fires causes the process to wait for the query to return and allows you to access the data afterward. C. Incorrect. Waiting for the StatementCompleted event to fire and then iterating through the DataReader is incorrect because you need to call...

Configuring Connection Pooling with OLE DB Connections

The OLE DB connection object OleDbConnection automatically pools connections through the use of OLE DB session pooling. You control how OLE DB connections use pooling by adding an OLE DB Services keyword to the connection string and setting its value based on the combination of services you want to enable or disable for the connection. The following connection strings explicitly enable connection pooling by setting the OLE DB Services keyword to -1. OLE DB connection string for an Office Access...

Lab Use Print Dialogs

In this lab, you will create a simple application that enables the user to use PageSetupDialog, PrintDialog, and PrintPreviewDialog to control the printing of a test document. 1. Open the partial solution for Chapter 10, Lab 1 from Open Form1. Note that it already has a PrintDocument component named PrintDocument1 and that there is code in the event handler for the PrintPage event. 2. From the Toolbox, drag a MenuStrip onto the form. Add a top-level menu item named File. 3. Beneath the File...

Merging Menus

Menus can be merged at run time and their items incorporated into a single menu. You can merge MenuStrips, ContextMenuStrips which are covered in greater detail later in this lesson , or both. In fact, you can even merge MenuStrip controls with ToolStrip controls. Like merging tool strips, merging menu strips is accomplished by invoking the ToolStripManager.Merge method on the static ToolStripManager class, as shown here targetMenuStrip C targetMenuStrip The preceding example takes the first...

How to Create AutoIncrementing Columns in DataTable Objects

The DataTable itself assigns values to an auto-incrementing column in the table. This is typical of a table that contains information such as order information where it is desirable to have a unique OrderID, but the actual value of the OrderID column isn't important other than that it needs to be unique. DataColumn objects provide specific properties to create auto-incrementing columns where you can set the starting value, called the AutolncrementSeed, as well as the increment, or number added...

Lab Create a Print Document

In this lab, you will expand on the solution you created in Lesson 1, Managing the Print Process by Using Print Dialogs, and create an application that allows the user to open a text file and print the contents. Exercise 1 Creating a Print Document 1. From the Toolbox, drag an OpenFileDialog box onto the form. 2. In the Properties window, set the Filter property of OpenFileDialog1 to Text Files .txt. 3. Beneath the FileMenuItem, add a menu item named Open File. 4. Double-click...

Disabling Hiding and Deleting Menu Items

At times, it makes sense to remove certain options from a menu. You might want a menu item to be disabled when conditions aren't appropriate for it to be invoked or to hide a menu item that shouldn't be displayed. In some cases, you might want to delete a menu item completely from a menu. You can disable a menu item by setting the Enabled property to False. This will cause the menu item to appear dimmed. It will still be visible to the user, but it cannot be invoked by mouse clicks or...

Lesson Review Tce

You can use the following questions to test your knowledge of the information in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each choice is right or wrong are located in the Answers section at the end of the book. 1. Which of the following are required to create an access key for a menu item A. The UseMnemonic property for the ToolStripMenuItem must be set to True. B. The...

Lesson Review Tgr

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each answer choice is right or wrong are located in the Answers section at the end of the book. 1. Which of the following are possible values for the Checked property of a CheckBox control Choose all that apply. 2. You are designing an application that...

Lesson Review Knv

You can use the following questions to test your knowledge of the information in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each answer choice is right or wrong are located in the Answers section at the end of the book. 1. Which of the following properties and methods can be used to find the index of a selected item in a ListBox control Choose all that apply. 2. Which of...

To view errors in a DataSet with the ErrorProvider component

1. Bind the ErrorProvider component to a table in the dataset, as shown here ' Assumes existence of DataSet1 with a Customers table ErrorProvider1.DataSource DataSet1 ErrorProvider1.DataMember Customers Assumes existence of DataSet1 with a Customers table errorProvider1.DataSource DataSet1 errorProvider1.DataMember Customers 2. Set the ContainerControl property of the ErrorProvider component ErrorProvider1.ContainerControl Me errorProviderl.ContainerControl this 3. Use the SetColumnError method...

Adding Tool Strip Items to a Tool Strip

At design time, you can add tool strip items to a tool strip by choosing appropriate items from the drop-down menu in the Designer as shown in Figure 4-1. Figure 4-1 Adding a tool strip item at design time The item you choose from the menu will be added to the tool strip, and an instance of it will be added to your application. You can set properties for the item in the Properties window and refer to the item in code. At run time, you can dynamically add items to a tool strip by using the...

Exercise Practice with Container Controls

1. Open Visual Studio and create a new Windows Forms project. 2. From the Toolbox, drag a TabControl to the surface of the Form. In the Property Grid, set the Dock property to Fill. 3. In the Property Grid, choose the TabPages property to open the TabPages Collection Editor. Add tab pages until there is a total of four pages. Set the Text properties of these four TabPage controls to GroupBox, FlowLayoutPanel, TableLayoutPanel, and SplitContainer, respectively. Click OK. 4. In the form, select...

Lesson Review Cna

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each choice is correct or incorrect are located in the Answers section at the end of the book. 1. When would you typically use an Input parameter Choose all that apply. A. When the parameter value is created based on user input B. When the parameter is...

Lesson Review Eev

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each choice is correct or incorrect are located in the Answers section at the end of the book. 1. What is a DataSet Choose all that apply. A. A pointer to a remote database B. A collection of DataTable and DataRelation objects D. A collection of records...

Lesson Review Htw

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each choice is correct or incorrect are located in the Answers section at the end of the book. 1. When adding a new row to a DataTable A. Create an instance of a DataRow and call the Update method of the DataAdapter. B. Create an instance of a DataRow or...

Lesson Review Bls

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each choice is right or wrong are located in the Answers section at the end of the book. 1. Where is the connection object located that was created as a result of running the Data Source Configuration Wizard A. In the application configuration file C. In...

Lesson Review Bzd

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each choice is correct or incorrect are located in the Answers section at the end of the book. 1. What are the main objects that make up a DataAdapter A. Connection and DataTable objects B. Connection and Command objects C. DataTable and DataSet objects...

Lab Practice with Delegates and Threads

In this lab, you will create an application similar to the application you created in Lesson 1. Your application will execute a time-consuming process on a separate thread that can be cancelled, reports progress, and notifies the user when finished. First, you will use delegates and asynchronous invocation to implement this functionality. After that is complete, you will modify your application to use threads. Exercise 1 Practice with Delegates 1. Open the partial solution for the first lab...

Lab Create a Customized PrintPreview Form

In this exercise, you will create a customized PrintPreview form and add it to the solution you created in Lesson 2, Constructing Print Documents. You will add a PrintPreviewControl to a form and add controls that allow the user to specify the number of rows and columns, to specify the magnification, and to turn anti-aliasing on and off. Exercise 1 Creating a Customized PrintPreview Form 1. Open the solution you completed in Lesson 2, or open the completed Lesson 2 solution on the companion CD....

Lab Working with DataView Objects

In this lab you will use DataView objects to sort and filter the data displayed from a DataTable. Exercise 1 Working with DataView Objects This example demonstrates sorting and filtering using a DataView. 1. Create a Windows application and name it DataViewExample. 2. Add a DataGridView to the form and set its Name property to CustomersGrid. 3. Add a TextBox and set the following properties 4. Add a second TextBox and set the following properties 5. Add a button to the form and set the...

Setting the DataTable Objects Default Table Views Using a DataViewManager

A DataViewManager is basically a collection of DataViewSetting objects that are used to set the default sorting and filtering behavior of each DataTable in a DataSet. You can use a DataViewManager as a data source for data-bound controls. For example, if you create a DataViewManager to manage several tables from the Northwind DataSet, you can use code similar to the following to bind it to the individual tables Dim dvm As New DataViewManager NorthwindDataSet1 OrdersDataGridView.DataSource C...

Synchronizing a DataSet with an XmlDataDocument

When working with XML data and DataSet objects, you will typically need to manipulate data through the DataSet classes as well as XML classes available in the .NET Framework. Keeping your DataSet and XmlDataDocument in synch allows you to process the data using whichever method of access you prefer while working on the same data source. The following code example shows how to create a new XmlDataDocument and synchronize it with the NorthwindDataSet. Dim NwDataDocument As New XmlDataDocument...

Maintaining Changes to DataRow Objects

Changes to DataRow objects that have not yet been accepted or rejected are maintained by the RowState and DataRowVersion enumerations. The RowState is used to determine the state of a row. When first populated, the rows in a DataTable have a RowState of Unchanged. Table 7-3 details the different values of the RowState enumeration. No changes have been made since the last AcceptChanges call or since the initial filling of the DataTable. This row has been added since the last AcceptChanges call....

Resolving Conflicts Between a DataSet and a Database Using the DataAdapter

DataAdapter objects provide two specific properties that assist in resolving conflicts that may occur when attempting to fill a DataSet with a DataAdapter the MissingMapping-Action property and the MissingSchemaAction property. These conflicts typically occur when changes have been made to the database schema or to the DataSet schema. For example, if columns are added to a table in the database and you attempt to perform a SELECT from that table, the adapter uses these properties to decide what...

Creating Menu Strips and Tool Strip Menu Items

Toolstripmenu

You can create a MenuStrip at design time in the same way that you create any control by dragging it from the Toolbox onto the design surface. Once added to the design surface, an interface for creating tool strip menu items appears. You can type a string into the box in the menu strip to create a new tool strip menu item. After a new item has been created, additional boxes appear to the right and beneath the newly created tool strip menu item to allow you to create more items or sub-items of...

Security and Printing

Printing is a secured activity, and permission to print is defined by the PrintingPermis-sion class. The PrintingPermission class can specify four PrintingPermissionLevel values that detail the various secure printing environments. These levels are AllPrinting Provides unrestricted access to the printer. DefaultPrinting Enables programmatic printing to the default printer and access to other printers through a printer dialog box. SafePrinting Allows printing only through a printer dialog box....

Lesson Summary Aql

The DataGridView is the preferred control for displaying tabular data such as a DataTable. You can add and remove columns to a DataGridView in the Designer, using the Add Column and Edit Column dialog boxes available from the smart tag of the DataGridView. The DataGridView.CurrentCell property provides access to the currently selected cell in a DataGridView. The DataGridView raises a CellValidating event through which you can add code that verifies that the value in a column conforms to your...

Lesson Summary Wwp

The WebBrowser control encapsulates all of the functionality necessary to access the Internet and load a variety of document types. It contains methods that facilitate navigation of the World Wide Web and the file system. The NotifyIcon component allows you to set an icon in the system tray and provide notifications to users regarding processes running in the background. You can display messages to the user via balloon tips and can enable commands by associating a ContextMenuStrip with the...

FlatStyle and FlatAppearance

The FlatStyle property governs whether the button has a three-dimensional, raised appearance, or a flat appearance. You can give a button a flat appearance by setting the FlatStyle property to Flat. When the FlatStyle property is set to Flat, the FlatAppearance property determines how the button looks and behaves in the user interface. The FlatAppearance property is an instance of a structure that contains properties described in Table 2-4. Table 2-4 Properties of FlatAppearance Table 2-4...

Executing Commands Asynchronously

In addition to the execution commands listed in Figure 6-2, an additional set of commands are specifically used for asynchronous calls to a database. Executing commands asynchronously is the process of having the command execute on a separate thread from the rest of your application so users do not have to wait for the command to complete before continuing work in other parts of the application. For example, commands that are not executed asynchronously can cause your form to freeze until the...

Validating XML with XmlValidatingReader

The XmlValidatingReader allows you to validate XML against a given schema. As the document is read, it is checked for validity against the schema that are indicated. XmlValidatingReader wraps an existing XmlReader instance. You can create an XmlValidatingReader instance, as shown here ' Assumes the existence of an XmlReader named aReader Dim aValReader As XmlValidatingReader aValReader New XmlValidatingReader aReader Assumes the existence of an XmlReader named aReader aValReader new...

Setting the Document Property

The Document property represents the PrintDocument that is currently associated with the PrintPreviewControl. The PrintPreviewControl calls the PrintDocument.Print method and redirects the output of the PrintPages event handler to the PrintPreview-Control instead of to the printer. The following code example demonstrates how to set the PrintPreviewControl.Document property ' Assumes a PrintDocument named PrintDocument1 PrintPreviewControl1.Document PrintDocument1 Assumes a PrintDocument named...

Printpreviewcontrol1.document

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form. Answers to these questions and explanations of why each choice is right or wrong are located in the Answers section at the end of the book. 1. Which of the following values for the Zoom property will cause the document to be previewed at 250 percent of normal size 2. Which of the following lines of code...

Lab Returning the List of Visible SQL Servers

In this lab you will practice enumerating the SQL Servers on your network. Exercise 1 Enumerating the SQL Servers on a Network To demonstrate how to retrieve the list of visible SQL servers, let's create a small application to display the information returned from the GetDataSources method in a Data-GridView. 1. Create a new Windows application named SqlServerEnumerator. 2. Add a DataGridView to the form and name it VisibleSqlServers. The DataGridView is the control typically used for...

What Are Command Objects

To execute SQL statements and stored procedures against a database from your application , you use Command objects. Command objects contain the necessary information to execute SQL statements, stored procedures, functions, and so on against a data source return data to your application and perform database catalog operations such as creating, altering, and deleting database objects. In other words, you can use Command objects to execute any valid SQL statement. NOTE SQL Statements and Stored...

Providing a Toolbox Bitmap for Your Control

After a control has been built, it automatically appears in the Toolbox if you are using it in the same solution that contains the control, or it can be added to the Toolbox if it was created in a different project. When the control is added to the Toolbox, it appears in the Toolbox as the name of the control next to an icon. If no icon is specified, a generic icon is supplied. You can specify the icon that is displayed next to the name of your control by using the ToolboxBitmapAttribute. You...

To provide a parameter to a background process

1. Include the parameter in the RunWorkerAsync call, as shown below C RunWorkerAsync C myfi le.txt 2. Retrieve the parameter from the DoWorkEvenArgsArgument property and cast it appropriately to use it in the background process. An example is shown below Private Sub BackgroundWorker1_DoWork ByVa1 sender As System.Object, ByVal _ e As System.ComponentModel.DoWorkEventArgs Handles _ BackgroundWorker1.DoWork Dim myPath As String myPath CType e.Argument, String ' Use the argument in the process...

Executing Multiple SQL Statements Using a DataReader

In addition to returning the results from a single SQL statement, you can use a Command object and DataReader to return the results of multiple SQL statements. To execute more than one SQL statement, set the CommandText property of a Command object to multiple SQL statements separated by semicolons . After calling the ExecuteReader method, the DataReader will hold the number of result sets equal to the number of SQL statements executed. To access the data returned by the additional statements,...