<docbook><section><title>VirtInformixVisualStudioDataGridFormsApp</title><bridgehead class="http://www.w3.org/1999/xhtml:h3">Visual Studio Windows DataGrid Form Application</bridgehead>
<para>This article details the steps required to create a simple Visual Studio 2008 Windows Form application, with associated DataGridView control for displaying data in selected tables from the target database.</para><para>1.
 Launch the Visual Studio 2008 SP1 IDE.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp01.png" /></figure></para><para>2.
 Create a <emphasis>Web Application</emphasis> project by going to the <emphasis>File</emphasis> menu in Visual Studio and choosing <emphasis>New Project</emphasis>.
 </para><para>3.
 When the New Project window appears, choose either <emphasis>Visual Basic</emphasis> or <emphasis>Visual C#</emphasis> as your programming language.</para><para>4.
 Within the language category, click on <emphasis>Windows</emphasis> and select <emphasis>Windows Form Application</emphasis> from the right-hand panel.
 </para><para>5.
 Choose a name for the project, for example <emphasis>VirtWindowsFormApplication</emphasis>, and click <emphasis>OK</emphasis>.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp02.png" /></figure></para><para>6.
 In the <emphasis>Toolbox</emphasis>, expand <emphasis>Data</emphasis> Controls and drag the <emphasis>DataGridView</emphasis> control onto the form.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp03.png" /></figure></para><para>7.
 Click on the little <emphasis>arrow</emphasis> in the top right of the <emphasis>DataGridView</emphasis> control.
 This loads the <emphasis>DataGridView Task</emphasis> menu.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp04.png" /></figure></para><para>8.
 Click on the <emphasis>Choose Data Source</emphasis> list box.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp05.png" /></figure></para><para>9.
 Click on the <emphasis>Add Project Data Source</emphasis> link to connect to a data source.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp06.png" /></figure></para><para>10.
 In the <emphasis>Data Source Configuration Wizard</emphasis> dialog <emphasis>Choose Data Source Type</emphasis> page, select the <emphasis>Database</emphasis> data source type and click <emphasis>Next</emphasis>.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp07.png" /></figure></para><para>11.
 In the <emphasis>Data Source Configuration Wizard</emphasis> dialog <emphasis>Choose your Data Connection</emphasis> page,select the <emphasis>New Connection</emphasis> button.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp08.png" /></figure></para><para>12.
 In the <emphasis>Choose Data Source</emphasis> dialog, select the <emphasis>OpenLink Virtuoso Data Source</emphasis> from the list and click <emphasis>Continue</emphasis>.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp09.png" /></figure></para><para>13.
 In the <emphasis>Connection Properties</emphasis> dialog, specify the <emphasis>hostname</emphasis>, <emphasis>portno</emphasis>, <emphasis>username</emphasis> and password for the target Virtuoso Server and check the <emphasis>Save Password</emphasis> check box.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp10.png" /></figure></para><para>14.
 Select the <emphasis>Select Database From List</emphasis> radio button and choose <emphasis>stores_demo</emphasis> from the drop down list.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp11.png" /></figure></para><para>15.
 Press the <emphasis>Test Connection</emphasis> dialog to verify that the database is accessible.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp12.png" /></figure></para><para>16.
 Leave the default connect string name--<emphasis>stores_demoConnectionString</emphasis>--and click <emphasis>Next</emphasis>.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp13.png" /></figure></para><para>17.
 From the list of available tables returned for the stores_demo database, select the <emphasis>msgs</emphasis> table to be associated with the <emphasis>DataGridView</emphasis> control.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp14.png" /></figure></para><para>18.
 The columns names of the select table will be displayed in the the DataGridView.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp15.png" /></figure></para><para>19.
 Resize the Form and DataGridView to allow all columns to be visible, if possible.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp16.png" /></figure></para><para>20.
 To test the application, simply hit <emphasis>Ctrl+F5</emphasis> within Visual Studio or select <emphasis>Start Debugging</emphasis>  from the <emphasis>Debug</emphasis> menu.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp17.png" /></figure></para><para>21.
 The data from the <emphasis>msgs</emphasis> table will be displayed in the <emphasis>DataGrid</emphasis>.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp18.png" /></figure></para><para>22.
 To make the <emphasis>DataGridView</emphasis> updateable, you will need to manually add some code to the project along with a suitable control to invoke the code. Drag a <emphasis>Button</emphasis> control onto the form.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp19.png" /></figure></para><para>23.
 Right click on the Button and select <emphasis>Properties</emphasis>.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp20.png" /></figure></para><para>24.
 In the Properties view, edit the button&#39;s <emphasis>Text</emphasis> property to read <emphasis>Save Changes</emphasis> and its <emphasis>(Name)</emphasis> property to read <emphasis>saveChanges</emphasis>.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp21.png" /></figure> <figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp22.png" /></figure></para><para>25.
 The button will now update to reflect these changes.</para><para>NOTE: You will need to resize the button to make the new text visible.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp23.png" /></figure></para><para>26.
 Double click the new button to generate the required event handler.
 It should take you directly to the area of code that will execute when the button is clicked.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp24.png" /></figure></para><para>27.
 Edit the saveChanges_Click event handler code to include the following line.</para><programlisting>
private void saveChanges_Click(object sender, EventArgs e)
{
  this.msgsTableAdapter.Update(this.stores_demoDataSet.msgs);
}

</programlisting><para> <figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp25.png" /></figure></para><para>28.
 Now test the application again by hitting <emphasis>Ctrl+F5</emphasis>. Scroll to the empty row at the bottom and enter data for a new row.
 Then, select <emphasis>Save Changes</emphasis> which will write the new row back to the database. Updates and deletes can be performed similarly.
<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp26.png" /></figure></para><para>29.
 You can use Interactive ISQL to test that the changes that have been written.
 Interactive ISQL Interface is detailed in the <ulink url="VirtINFLinkingObjects">Linking Informix tables into OpenLink Virtuoso</ulink> section.<figure><graphic fileref="VirtInformixVisualStudioDataGridFormsApp/VirtInfDataGridApp27.png" /></figure> The task is now complete . </para>
</section></docbook>