This section outlines the steps for step 3 of the DBBrowserGrid tutorial. Step 3 shows how the data representation can be changed at the DBBrowserGrid control level depending on the style applied to the current data source.
If you want to retain the work done in Step 1, create a separate copy of it.
Open the FrmAdoObjs form in the Designer.
Add a" Styles" item to the main menu.
Add following items to Styles:
Customers – Style 1
Customers – Style 2
Separator
Employees – Style 1
Add the following members to the FrmAdoObjs class declaration:
private Stingray.Grid.TableStyle m_tsCustomers1; private Stingray.Grid.TableStyle m_tsCustomers2; private Stingray.Grid.TableStyle m_tsEmployees; |
Add the following code to the function:
m_tsCustomers1 = new Stingray.Grid.TableStyle(); m_tsCustomers1.MappingName = "customers"; m_tsCustomers1.ItemOGStye.TextColor = System.Drawing.SystemColors.WindowText; m_tsCustomers1.ItemOGStye.Interior = Stingray.Grid.OGBrush.OGSolidBrush( System.Drawing.SystemColors.Window ); m_tsCustomers2 = new Stingray.Grid.TableStyle(); m_tsCustomers2.MappingName = "customers"; Stingray.Grid.Style style = new Stingray.Grid.Style(); style.Draw3dFrame = Stingray.Grid.Draw3dFrameType.Inset; Stingray.Grid.ColumnStyle colStyle = new Stingray.Grid.ColumnStyle( style, "Country", "Country", true ); m_tsCustomers2.ColumnStyles.Add( colStyle ); style = new Stingray.Grid.Style(); style.AllowEnter = false; colStyle = new Stingray.Grid.ColumnStyle( style, "City", "City", false ); m_tsCustomers2.ColumnStyles.Add( colStyle ); style = new Stingray.Grid.Style(); style.VerticalScroll = true; colStyle = new Stingray.Grid.ColumnStyle( style, "Customer Name", "CompanyName", false ); m_tsCustomers2.ColumnStyles.Add( colStyle ); m_tsEmployees = new Stingray.Grid.TableStyle(); m_tsEmployees.MappingName = "employees"; style = new Stingray.Grid.Style(); colStyle = new Stingray.Grid.ColumnStyle( style, "ID", "EmployeeID", true ); m_tsEmployees.ColumnStyles.Add( colStyle ); style = new Stingray.Grid.Style(); colStyle = new Stingray.Grid.ColumnStyle( style, "Last name", "LastName", false ); m_tsEmployees.ColumnStyles.Add( colStyle ); style = new Stingray.Grid.Style(); style.Control = Stingray.Grid.ControlType.DateTime; colStyle = new Stingray.Grid.ColumnStyle( style, "Hiring date", "HireDate", false ); m_tsEmployees.ColumnStyles.Add( colStyle ); |
This code creates two different styles for the "customer" table—one has only general table properties; the other includes particular column properties as well. A style for the "employee" table is created. This style demonstrates using controls in the column styles.
Return to the FrmAdoObjs designer, and double-click Styles | Customers – Style 1, Styles | Customers – Style 2, and Styles | Employees – Style 1 on the main menu. The code for
void menuItem6_Click(object sender, System.EventArgs e) void menuItem7_Click(object sender, System.EventArgs e) void menuItem9_Click(object sender, System.EventArgs e) |
appears. Enter the following code as the function body:
private void menuItem6_Click(object sender, System.EventArgs e) { if( !menuItem6.Checked ) { dbBrowserGrid1.TableStyles["customers"] = m_tsCustomers1; } else { dbBrowserGrid1.TableStyles.Remove( m_tsCustomers1 ); } menuItem6.Checked = !menuItem6.Checked; menuItem7.Checked = false; } private void menuItem7_Click(object sender, System.EventArgs e) { if( !menuItem7.Checked ) { dbBrowserGrid1.TableStyles["customers"] = m_tsCustomers2; } else { dbBrowserGrid1.TableStyles.Remove( m_tsCustomers2 ); } menuItem7.Checked = !menuItem7.Checked; menuItem6.Checked = false; } private void menuItem9_Click(object sender, System.EventArgs e) { if( !menuItem9.Checked ) { dbBrowserGrid1.TableStyles["employees"] = m_tsEmployees; } else { dbBrowserGrid1.TableStyles.Remove( m_tsEmployees ); } menuItem9.Checked = !menuItem9.Checked; } |
The code inserts or deletes the table styles created earlier in the TableStyles collection of the DBBrowserGrid control. Depending on the presence of the table style with the MappingName property matching the current data source, the control applies the style to the data representation.
Now you can run the application, bind the DBBrowserGrid control to the different data source components, and apply or remove the styles in random order. You can see how the data representation changes depending on the styles availability. Two styles with the same mapping name cannot co-exist in the TableStyles and ColumnStyles collections.
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.