This section lists the steps required to create the first iteration of the DBBrowserGrid application. The first iteration of the application is a MDI Windows Forms application with a main form serving as a MDI main window and a child form containing Objective Grid for Microsoft .NET DBBrowserGrid control. In addition child form contains an array populated with simple objects, and has a menu commands which allow add/remove elements to the array and bind the array to the DBBrowserGrid control.
Open Microsoft Visual Studio.
Create a new, blank solution, using the menu option File | New | Blank Solution.
Name the solution "DBBrowserGrid".
Give the solution any valid location (path) desired.
In the solution explorer, right-click the DBBrowserGrid solution. A context menu appears. From the context menu, select Add | New Project.
Click Visual C# Projects.
Select Windows Application.
Name the project "Step 1".
Click OK. A main form (Form1) is automatically added to the project, and displayed. The form is displayed in Design mode. Resize the form as desired.
Select Form1. If the properties for Form1 are not already displayed, right-click the form; a context menu is displayed. Select Properties from the context menu.
In the resulting property grid for the form, change the following properties:
Text = "DBBrowserGrid Tutorial"
Name = "FrmMain"
IsMdiContainer = True
Select File | Save file as… from Visual Studio main menu and save the file as FrmMain.cs.
Switch to the source code view of the FrmMain.cs file, and replace the code in the static void Main() function:
Application.Run(new Form()); |
with the following:
Application.Run(new FrmMain()); |
Switch back to design view, and drag a MainMenu component onto FrmMain.
Add an item to the main menu with the title "&Bind to…"
Add an item to the "Bind to.." submenu with the title "&Array".
Now create an MDI child form: In the Solution Explorer, right-click Step 1, and in the popup menu select Add | Add Windows Form… .
In the Add new item dialog, enter "FrmArrays.cs" as a file name and click Open.
A new form (FrmArrays) is automatically added to the project and displayed in Design mode. Resize the form as desired.
Select FrmArrays. If the properties for FrmArrays are not already displayed, right-click the form; a context menu is displayed. Select Properties from the context menu.
In the resulting property grid for the form, change the following properties.
Text = Binding to arrays
Drag a MainMenu component onto FrmArrays.
Add an item to the main menu with the title "&Array".
Add items to the "Array" submenu with the following titles:
Bind
Add item
Remove item
Return to the FrmMain designer and double-click Bind to… | Arrays on the main menu. The code for
private void menuItem2_Click(object sender, System.EventArgs e) |
appears. Enter the following code as the function body:
FrmArrays frm = new FrmArrays(); frm.MdiParent = this; frm.Show(); |
This creates the instance of FrmArrays and adds it as an MDI child to the main application window.
Add a class with instances that will populate an array: In the Solution Explorer, right-click Step 1. In the popup menu, select Add | Add Class… .
Enter ItemClass.cs as the file name and click Open. Populate ItemClass.cs file with the following code:
using System; namespace Step_1 { /// <summary> /// Summary description for ItemClass. /// </summary> public class ItemClass { public ItemClass() { // // TODO: Add constructor logic here // m_nA = countA++; m_bC = (countC = !countC); m_strB = m_nA.ToString() + " " + m_bC.ToString(); } private static int countA = 1; private int m_nA; public int nA { get { return m_nA; } set { m_nA = value; } } private string m_strB; public string strB { get { return m_strB; } set { m_strB = value; } } private static bool countC = true; private bool m_bC; public bool bC { get { return m_bC; } set { m_bC = value; } } } } |
This creates a simple generic class with three properties.
Switch back to the FrmArray and add a DBBrowserGrid control to FrmArray.
Select and drag a DBBrowserGrid from the Toolbox onto the form.
Select the DBBrowserGrid control. In the property grid for the control, change the following Grid Control properties:
Dock = Fill
BorderStyle = Fixed3D
Add the following member to the FrmArrays class:
System.Collections.ArrayList arrList; |
and following initialization code to the FrmArray class constructor:
arrList = new System.Collections.ArrayList(); |
Return to the FrmArrays designer, and double-click Array | Bind, Array | Add Item, and Array | Remove Item on the main menu. The code for
void menuItem2_Click(object sender, System.EventArgs e) void menuItem3_Click(object sender, System.EventArgs e) void menuItem4_Click(object sender, System.EventArgs e) |
appears. Enter the following code as the function body:
private void menuItem2_Click(object sender, System.EventArgs e) { if( !menuItem2.Checked ) { dbBrowserGrid1.SetDataBinding( this.arrList, null ); } else { dbBrowserGrid1.SetDataBinding( null, null ); } menuItem2.Checked = !menuItem2.Checked; menuItem3.Enabled = !menuItem2.Checked; menuItem4.Enabled = !menuItem2.Checked; } private void menuItem3_Click(object sender, System.EventArgs e) { arrList.Add( new ItemClass() ); } private void menuItem4_Click(object sender, System.EventArgs e) { if( arrList.Count > 0 ) { arrList.RemoveAt( 0 ); } } |
Build and run the application. Create the MDI child window, click several times on the Array | Add Item item and on the Array | Bind item. You can see the properties values of the new object in the browser grid. You can edit them, un-bind and bind back, and see the changes actually stored in the objects. You cannot change read-only properties.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.