实例介绍
【实例简介】SuperGrid 实例
【实例截图】DotNetBar的GridView实例
【实例截图】DotNetBar的GridView实例
【核心代码】
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar.SuperGrid;
using DevComponents.DotNetBar.SuperGrid.Style;
namespace SuperGridDemo
{
public partial class DemoGroupHeader : Office2007Form
{
#region Private variables
private DataSet _DataSet;
private Random _Rand = new Random();
private int _BaseColumnCount;
private int _HeaderCount;
private int _StartColIndex;
private int _EndColIndex;
private GridColumn _HitColumn;
private ColumnGroupHeader _HitGroupHeader;
private List<ColumnGroupHeader> _SelectedGroupHeaders;
private Point[] _ChartData1;
private Point[] _ChartData2;
#endregion
public DemoGroupHeader()
{
InitializeComponent();
// Initialize the grid, bind to our grid data
// and set the sample description text
InitializeGrid();
ShellServices.LoadRtbText(richTextBox1,
"SuperGridDemo.Resources.DemoGroupHeader.rtf");
}
#region InitializeGrid
/// <summary>
/// Initializes the default grid
/// </summary>
private void InitializeGrid()
{
GridPanel panel = superGridControl1.PrimaryGrid;
panel.Name = "Customers";
panel.MinRowHeight = 20;
// Bind to our customer data and hook a few SuperGrid events.
BindCustomerData();
superGridControl1.ColumnHeaderClick = ColumnHeaderClick;
superGridControl1.ColumnGroupHeaderClick = GroupHeaderClick;
superGridControl1.PostRenderColumnGroupHeader = SuperGridControl1PostRenderColumnGroupHeader;
superGridControl1.ColumnGroupHeaderResized = SuperGridControl1ColumnGroupHeaderResized;
superGridControl1.ColumnGroupHeaderMarkupLinkClick = SuperGridControl1ColumnGroupHeaderMarkupLinkClick;
superGridControl1.ColumnHeaderMarkupLinkClick = SuperGridControl1ColumnHeaderMarkupLinkClick;
superGridControl1.DataBindingComplete = SuperGridControl1DataBindingComplete;
}
#region BindCustomerData
/// <summary>
/// Creates and binds our data to the grid
/// </summary>
private void BindCustomerData()
{
string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) "\\Resources";
if (location != null)
{
// Get and fill the Northwind db
_DataSet = new DataSet();
string path = Path.Combine(location, "nwind.mdb");
using (OleDbConnection cn =
new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
path ";User Id=admin;Password=;"))
{
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Customers;", cn);
adapter.Fill(_DataSet, "Customers");
}
// Add a few extraneous columns to our db, for
// us to use as 'fill data' in various layouts.
DataTable table = _DataSet.Tables["Customers"];
_BaseColumnCount = table.Columns.Count;
AddNewColumns(table, new string[] { "MTD", "YTD", "LTD" });
AddNewColumns(table, new string[] { "P1", "P2", "P3", "P4" });
AddNewColumns(table, new string[] { "T1", "T2", "T3" });
// Fill the newly added columns with
// 'useful' data.
foreach (DataRow row in table.Rows)
{
double d = _Rand.NextDouble() * 1000;
row["MTD"] = d;
row["YTD"] = d * 4;
row["LTD"] = d * 4 * _Rand.Next(10, 50);
row["P1"] = _Rand.NextDouble();
row["P2"] = _Rand.NextDouble();
row["P3"] = _Rand.NextDouble();
row["p4"] = _Rand.NextDouble();
row["T1"] = _Rand.NextDouble() * 10000;
row["T2"] = _Rand.NextDouble() * 20000;
row["T3"] = _Rand.NextDouble() * 30000;
}
// Bind our grid to the created dataset.
superGridControl1.PrimaryGrid.DataSource = _DataSet;
superGridControl1.PrimaryGrid.DataMember = "Customers";
}
}
#region AddNewColumns
/// <summary>
/// Adds a set of new columns to the given table
/// </summary>
/// <param name="table"></param>
/// <param name="names"></param>
private void AddNewColumns(DataTable table, IEnumerable<string> names)
{
Type type = Type.GetType("System.Decimal");
foreach (string name in names)
table.Columns.Add(new DataColumn(name, type));
}
#endregion
#endregion
#endregion
#region SuperGridControl1DataBindingComplete
/// <summary>
/// This routine is called after the data bind operation has
/// been completed. This call-out lets you customize the display
/// or visibility of the data however the application needs.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SuperGridControl1DataBindingComplete(
object sender, GridDataBindingCompleteEventArgs e)
{
GridPanel panel = e.GridPanel;
GridColumnCollection columns = panel.Columns;
// Set a few default panel properties
panel.DefaultRowHeight = 40;
panel.UseAlternateRowStyle = true;
// Set initial column defaults
foreach (GridColumn col in columns)
{
col.CellStyles.Default.AllowWrap = Tbool.True;
col.ColumnSortMode = ColumnSortMode.Multiple;
col.EnableHeaderMarkup = true;
}
SetColumnTw(columns, "CustomerId", "ID", 50);
SetColumnTw(columns, "CompanyName", "Company", 100);
SetColumnTw(columns, "ContactName", "Name", 70);
SetColumnTw(columns, "ContactTitle", "Title", 100);
SetColumnTw(columns, "PostalCode", "Postal Code", 100);
SetColumnTw(columns, "City", "City", 50);
SetColumnTw(columns, "Country", "Country", 100);
SetColumnTw(columns, "Region", "Region", 50);
SetupCurrencyColumns(columns, new string[] {"MTD", "YTD", "LTD", "T1", "T2", "T3"});
SetupPctColumns(columns, new string[] {"P1", "P2", "P3", "P4"});
ResetLayout();
}
#region SetColumnTw
/// <summary>
/// Sets the header text and width for the given column.
/// </summary>
/// <param name="columns"></param>
/// <param name="name"></param>
/// <param name="text"></param>
/// <param name="width"></param>
private void SetColumnTw(GridColumnCollection columns,
string name, string text, int width)
{
GridColumn col = columns[name];
if (col != null)
{
col.HeaderText = text;
col.Width = width;
}
}
#endregion
#region SetupCurrencyColumns
/// <summary>
/// Sets up the given columns to render/edit
/// as a center-aligned Currency column.
/// </summary>
/// <param name="columns"></param>
/// <param name="names"></param>
private void SetupCurrencyColumns(GridColumnCollection columns, string[] names)
{
foreach (string name in names)
{
GridColumn column = columns[name];
column.EditorType = typeof (MyCurrencyEditControl);
column.CellStyles.Default.Alignment = Alignment.MiddleCenter;
}
}
#region MyCurrencyEditControl
/// <summary>
/// Currency DoubleInput edit control
/// </summary>
public class MyCurrencyEditControl : GridDoubleInputEditControl
{
public MyCurrencyEditControl()
{
DisplayFormat = "C";
}
}
#endregion
#endregion
#region SetupPctColumns
/// <summary>
/// Sets up the given column to render/edit
/// as a center-aligned "percent" column.
/// </summary>
/// <param name="columns"></param>
/// <param name="names"></param>
private void SetupPctColumns(GridColumnCollection columns, string[] names)
{
foreach (string name in names)
{
GridColumn column = columns[name];
column.EditorType = typeof(MyPercentEditControl);
column.CellStyles.Default.Alignment = Alignment.MiddleCenter;
}
}
#region MyPercentEditControl
/// <summary>
/// Percent DoubleInput edit control
/// </summary>
public class MyPercentEditControl : GridDoubleInputEditControl
{
public MyPercentEditControl()
{
DisplayFormat = "P";
}
}
#endregion
#endregion
#endregion
#region SetupLayout
/// <summary>
/// Performs setup needed when user
/// selects a new grid layout.
/// </summary>
private void SetupLayout()
{
// Reset everything back to default in
// preparation of moving everything around again.
ResetLayout();
// Initiate the setup of the chosen layout.
if (cbInternal.Checked == true)
SetupInternalLayout();
else if (cbSales.Checked == true)
SetupSalesLayout();
else if (cbMarketing.Checked == true)
SetupMarketingLayout();
else if (cbAdvertising.Checked == true)
SetupAdvertisingLayout();
else if (cbCorporate.Checked == true)
SetupCorporateLayout();
}
#region SetupInternalLayout
/// <summary>
/// Sets up the 'Internal' layout.
/// </summary>
private void SetupInternalLayout()
{
GridPanel panel = superGridControl1.PrimaryGrid;
GridColumnCollection columns = panel.Columns;
// Move the 'Country' column to position 7
columns["Country"].DisplayIndex = 7;
// Create the 'AdditionalInfo' header and add
// it to the panel's root GroupHeader collection.
ColumnGroupHeader cgh = GetIlAdditionalInfoHeader(columns);
panel.ColumnHeader.GroupHeaders.Add(cgh);
}
#region GetIlAdditionalInfoHeader
/// <summary>
/// Creates the 'AdditionalInfo" GroupHeader
/// </summary>
/// <param name="columns"></param>
/// <returns>Created header</returns>
private ColumnGroupHeader GetIlAdditionalInfoHeader(GridColumnCollection columns)
{
// Create the 'AddInfo' GroupHeader
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "AddInfo";
cgh.HeaderText = "Additional Information";
cgh.MinRowHeight = 36;
// Get the subordinate 'Contact' and 'RegInfo'
// GroupHeaders and add them to our header.
ColumnGroupHeader cshContact = GetAdContactHeader(columns);
ColumnGroupHeader cshRegInfo = GetAdRegInfoHeader(columns);
cgh.GroupHeaders.Add(cshContact);
cgh.GroupHeaders.Add(cshRegInfo);
return (cgh);
}
#region GetAdContactHeader
/// <summary>
/// Gets the 'Contact' group header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetAdContactHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.MinRowHeight = 36;
cgh.Name = "ContactInfo";
cgh.HeaderText = "Contact";
// Set the start and end Display Index which the
// group header is associated with.
cgh.StartDisplayIndex = columns.GetDisplayIndex(columns["ContactName"]);
cgh.EndDisplayIndex = columns.GetDisplayIndex(columns["ContactTitle"]);
return (cgh);
}
#endregion
#region GetAdRegInfoHeader
/// <summary>
/// Gets the 'Regional" group header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetAdRegInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "RegInfo";
cgh.HeaderText = "Regional Information";
cgh.MinRowHeight = 36;
// Get the subordinate 'AdrInfo' and 'CommInfo'
// GroupHeaders and add them to our header.
ColumnGroupHeader cshAddr = GetRiAddrHeader(columns);
ColumnGroupHeader cshComm = GetRiCommHeader(columns);
cgh.GroupHeaders.Add(cshAddr);
cgh.GroupHeaders.Add(cshComm);
return (cgh);
}
#region GetRiAddrHeader
/// <summary>
/// Gets the 'Address" info group header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetRiAddrHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "AddrInfo";
cgh.HeaderText = "Address Information";
cgh.MinRowHeight = 36;
// Set the start and end Display Index that the
// group header is associated with.
cgh.StartDisplayIndex = columns.GetDisplayIndex(columns["Address"]);
cgh.EndDisplayIndex = columns.GetDisplayIndex(columns["PostalCode"]);
return (cgh);
}
#endregion
#region GetRiCommHeader
private ColumnGroupHeader GetRiCommHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "CommInfo";
cgh.HeaderText = "Communication";
cgh.MinRowHeight = 36;
cgh.StartDisplayIndex = columns.GetDisplayIndex(columns["Phone"]);
cgh.EndDisplayIndex = columns.GetDisplayIndex(columns["Fax"]);
return (cgh);
}
#endregion
#endregion
#endregion
#endregion
#region SetupSalesLayout
/// <summary>
/// Sets up the 'Sales' layout
/// </summary>
private void SetupSalesLayout()
{
GridPanel panel = superGridControl1.PrimaryGrid;
GridColumnCollection columns = panel.Columns;
// Hide a few columns, and move a few around
// to achieve the ordering we need for this layout.
HideColumn(columns, "Address");
HideColumn(columns, "PostalCode");
columns["City"].DisplayIndex = 2;
columns["Country"].DisplayIndex = 3;
columns["Region"].DisplayIndex = 4;
columns["ContactName"].DisplayIndex = 5;
columns["ContactTitle"].DisplayIndex = 6;
columns["Phone"].DisplayIndex = 7;
columns["Fax"].DisplayIndex = 8;
ShowColumn(columns, "MTD", 9, "Quarterly");
ShowColumn(columns, "YTD", 10, "Yearly");
ShowColumn(columns, "LTD", 11, "Lifetime");
// Add our headers to the root GroupHeader
panel.ColumnHeader.GroupHeaders.Add(GetSlCompanyInfoHeader(columns));
panel.ColumnHeader.GroupHeaders.Add(GetSlRegionalInfoHeader(columns));
panel.ColumnHeader.GroupHeaders.Add(GetSlContactInfoHeader(columns));
panel.ColumnHeader.GroupHeaders.Add(GetSlSalesInfoHeader(columns));
}
#region GetSlCompanyInfoHeader
/// <summary>
/// Creates and returns the 'Company Info' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetSlCompanyInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "Company";
// Set the header to not show the root column headers, and
// perform some misc Style/display related setup.
cgh.ShowColumnHeaders = Tbool.False;
cgh.MinRowHeight = 36;
cgh.HeaderStyles.Default.Image = imageList1.Images["Cog"];
cgh.HeaderStyles.Default.ImageAlignment = Alignment.MiddleCenter;
cgh.HeaderStyles.Default.Background = new Background(Color.LightBlue, Color.CadetBlue);
cgh.HeaderStyles.MouseOver.Background = new Background(Color.CadetBlue, Color.LightBlue);
// Set the header's start and end Display Indecees
cgh.StartDisplayIndex = GetDisplayIndex(columns, "CustomerId");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "CompanyName");
return (cgh);
}
#endregion
#region GetSlRegionalInfoHeader
/// <summary>
/// Creates and returns the 'Regional Info' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetSlRegionalInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "RegionalInfo";
cgh.HeaderText = "Regional Information";
// Set the header to not show the root column headers, and
// perform some misc Style/display related setup.
cgh.ShowColumnHeaders = Tbool.False;
cgh.MinRowHeight = 36;
cgh.HeaderStyles.Default.Image = imageList2.Images["Region"];
cgh.HeaderStyles.Default.ImageAlignment = Alignment.MiddleRight;
cgh.HeaderStyles.Default.ImageOverlay = ImageOverlay.Bottom;
cgh.HeaderStyles.Default.ImagePadding = new DevComponents.DotNetBar.SuperGrid.Style.Padding(6);
// Set the header's start and end Display Indexes
cgh.StartDisplayIndex = GetDisplayIndex(columns, "City");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "Region");
return (cgh);
}
#endregion
#region GetSlContactInfoHeader
/// <summary>
/// Creates and returns the 'Contact Info' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetSlContactInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "ContactInfo";
cgh.HeaderText = "Contact Information";
cgh.MinRowHeight = 36;
cgh.HeaderStyles.Default.Image = imageList2.Images["Contact"];
cgh.HeaderStyles.Default.ImageAlignment = Alignment.MiddleRight;
cgh.HeaderStyles.Default.ImageOverlay = ImageOverlay.Bottom;
cgh.HeaderStyles.Default.ImagePadding = new DevComponents.DotNetBar.SuperGrid.Style.Padding(6);
cgh.HeaderStyles.Default.Background = new Background(Color.LightYellow, Color.Khaki);
cgh.HeaderStyles.MouseOver.Background = new Background(Color.Khaki, Color.LightYellow);
// Set the header's start and end Display Indecees
cgh.StartDisplayIndex = GetDisplayIndex(columns, "ContactName");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "Fax");
return (cgh);
}
#endregion
#region GetSlSalesInfoHeader
/// <summary>
/// Creates and returns the 'Sales Info' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetSlSalesInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "SalesInfo";
cgh.HeaderText = "Sales Figures";
cgh.MinRowHeight = 36;
cgh.HeaderStyles.Default.Image = imageList2.Images["Sales"];
cgh.HeaderStyles.Default.ImageAlignment = Alignment.MiddleRight;
cgh.HeaderStyles.Default.ImageOverlay = ImageOverlay.Bottom;
cgh.HeaderStyles.Default.ImagePadding = new DevComponents.DotNetBar.SuperGrid.Style.Padding(6);
// Set the header's start and end Display Indecees
cgh.StartDisplayIndex = GetDisplayIndex(columns, "MTD");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "LTD");
return (cgh);
}
#endregion
#endregion
#region SetupMarketingLayout
/// <summary>
/// Sets up the 'Marketing' Layout
/// </summary>
private void SetupMarketingLayout()
{
GridPanel panel = superGridControl1.PrimaryGrid;
GridColumnCollection columns = panel.Columns;
const string revShare = "<div align=\"center\">"
"<font color=\"Green\">Revenue</font><br/>"
"<font color=\"DarkRed\">Share</font></div>";
const string unitShare = "<div align=\"center\">"
"<font color=\"blue\">Unit</font><br/>"
"<font color=\"DarkRed\">Share</font></div>";
// Hide, show, and rearrange the columns for this layout
HideColumn(columns, "CompanyName");
HideColumn(columns, "ContactName");
HideColumn(columns, "ContactTitle");
HideColumn(columns, "Address");
HideColumn(columns, "Phone");
HideColumn(columns, "Region");
HideColumn(columns, "Fax");
ShowColumn(columns, "CustomerID", 0, null);
ShowColumn(columns, "City", 1, null);
ShowColumn(columns, "PostalCode", 2, null);
ShowColumn(columns, "Country", 3, null);
ShowColumn(columns, "P1", 4, unitShare);
ShowColumn(columns, "P2", 5, revShare);
ShowColumn(columns, "P3", 6, "Pyramid");
ShowColumn(columns, "P4", 7, "Momentum");
columns["CustomerID"].HeaderStyles.MouseOver.Background = new Background(Color.Yellow);
// Add the Market group header to the root
// GroupHeader collection.
panel.ColumnHeader.GroupHeaders.Add(GetMlMarketHeader(columns));
}
#region GetMlMarketHeader
/// <summary>
/// Creates and returns the 'Market' group header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetMlMarketHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "Market";
cgh.MinRowHeight = 46;
// Enable MiniMarkup and set the header text as needed
cgh.EnableHeaderMarkup = true;
cgh.HeaderText = "<div align=\"center\"><font size=\"14\">Market Data</font> "
"<font size=\"7\" color=\"darkred\">(Intl and Domestic)</font></div>";
cgh.HeaderStyles.MouseOver.Background = new Background(Color.Yellow);
// Create and add the subordinate group headers
ColumnGroupHeader cshArea = GetMlMarketAreaHeader(columns);
ColumnGroupHeader cshPop = GetMlMarketPopHeader(columns);
cgh.GroupHeaders.Add(cshArea);
cgh.GroupHeaders.Add(cshPop);
// We want the header to also contain the 'City' column
// so we must include it in the display range.
cgh.StartDisplayIndex = GetDisplayIndex(columns, "City");
return (cgh);
}
#endregion
#region GetMlMarketAreaHeader
/// <summary>
/// Creates and returns the 'Market Area' group header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetMlMarketAreaHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "MarketArea";
cgh.HeaderText = "Market Area";
cgh.HeaderStyles.Default.Background = new Background(Color.Goldenrod, Color.Yellow, BackFillType.HorizontalCenter);
cgh.HeaderStyles.MouseOver.Background = new Background(Color.Yellow);
cgh.MinRowHeight = 36;
// Set the group's start and end display indicees
cgh.StartDisplayIndex = GetDisplayIndex(columns, "PostalCode");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "Country");
return (cgh);
}
#endregion
#region GetMlMarketPopHeader
/// <summary>
/// Creates and returns the 'Market Population' group header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetMlMarketPopHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "MarketPop";
cgh.HeaderText = "Market Population";
cgh.HeaderStyles.Default.Background = new Background(Color.ForestGreen, Color.GreenYellow, BackFillType.HorizontalCenter);
cgh.HeaderStyles.MouseOver.Background = new Background(Color.Yellow);
cgh.MinRowHeight = 36;
// Set the group's start and end display indicees.
cgh.StartDisplayIndex = GetDisplayIndex(columns, "P3");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "P4");
return (cgh);
}
#endregion
#endregion
#region SetupAdvertisingLayout
/// <summary>
/// Sets up the 'Advertising Info' header
/// </summary>
private void SetupAdvertisingLayout()
{
GridPanel panel = superGridControl1.PrimaryGrid;
GridColumnCollection columns = panel.Columns;
// Hide, show, and rearrange a few columns to
// achieve the layout we want.
HideColumn(columns, "CustomerID");
HideColumn(columns, "CompanyName");
HideColumn(columns, "ContactName");
HideColumn(columns, "ContactTitle");
HideColumn(columns, "Address");
HideColumn(columns, "City");
HideColumn(columns, "Phone");
HideColumn(columns, "Fax");
ShowColumn(columns, "PostalCode", 0, null);
ShowColumn(columns, "Region", 1, null);
ShowColumn(columns, "Country", 2, null);
ShowColumn(columns, "T1", 3, "Past");
ShowColumn(columns, "T2", 4, "Potential");
ShowColumn(columns, "MTD", 5, null);
ShowColumn(columns, "YTD", 6, null);
ShowColumn(columns, "LTD", 7, "Lifetime");
// Have the 'Country' column base header to be hidden, and
// set its HeaderText to contain a MiniMarkup link (when the
// link is clicked we will count how many unique countries
// there are in the grid column).
GridColumn col = columns["Country"];
col.EnableHeaderMarkup = true;
col.HeaderText = "<div align=\"center\">Country<br/>"
"<font size=\"7\"><a href=\"MoreInfo\">(Count)</a></font></div>";
// Create and add the sub-headers to the group.
panel.ColumnHeader.GroupHeaders.Add(GetAlPostalInfoHeader(columns));
panel.ColumnHeader.GroupHeaders.Add(GetAlAdvertisingInfoHeader(columns));
}
#region GetAlPostalInfoHeader
/// <summary>
/// Creates and returns the 'Postal Info' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetAlPostalInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "PostalInfo";
cgh.HeaderText = "Postal Information";
cgh.MinRowHeight = 36;
// Create the 'LocaleInfo' header and add
// it to the postal group header.
ColumnGroupHeader cshLocaleInfo = GetAlLocaleInfoHeader(columns);
cgh.GroupHeaders.Add(cshLocaleInfo);
// Here we want to extend the range of the postal header
// to also include the 'Country' column, so we must
// set the EndDisplayIndex to reflect that.
cgh.EndDisplayIndex = GetDisplayIndex(columns, "Country");
return (cgh);
}
#region GetAlLocaleInfoHeader
/// <summary>
/// Creates and returns the 'Locale Info' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetAlLocaleInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "LocaleInfo";
cgh.HeaderText = "Locale";
cgh.MinRowHeight = 36;
// Set the groups start and end display index
cgh.StartDisplayIndex = GetDisplayIndex(columns, "PostalCode");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "Region");
return (cgh);
}
#endregion
#endregion
#region GetAlAdvertisingInfoHeader
/// <summary>
/// Creates and returns the 'Advertising Info' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetAlAdvertisingInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "AdInfo";
cgh.MinRowHeight = 36;
// Enable MiniMarkup for the header, and set the Header Text
// to present a Markup link for the user to click for more info.
cgh.EnableHeaderMarkup = true;
cgh.HeaderText = "<div align=\"center\">Advertising Breakdown<br/>"
"<font size=\"7\"><a href=\"MoreInfo\">(More Info)</a></font></div>";
cgh.HeaderStyles.Default.Padding = new DevComponents.DotNetBar.SuperGrid.Style.Padding(4);
// Create the subordinate headers and add them to the group
ColumnGroupHeader cshAcquisition = GetAdRevenueHeader(columns);
ColumnGroupHeader cshReturn = GetAdReturnHeader(columns);
cgh.GroupHeaders.Add(cshAcquisition);
cgh.GroupHeaders.Add(cshReturn);
return (cgh);
}
#region GetAdRevenueHeader
/// <summary>
/// Creates and returns the 'Revenue' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetAdRevenueHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "Revenue";
cgh.MinRowHeight = 36;
// Set the group's start and end display indicees
cgh.StartDisplayIndex = GetDisplayIndex(columns, "T1");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "T2");
return (cgh);
}
#endregion
#region GetAdReturnHeader
/// <summary>
/// Creates and returns the 'Return Info' header
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetAdReturnHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "ReturnInfo";
cgh.HeaderText = "Return on Investment";
cgh.MinRowHeight = 36;
// Set the group's start and end display indicees
cgh.StartDisplayIndex = GetDisplayIndex(columns, "MTD");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "LTD");
return (cgh);
}
#endregion
#endregion
#endregion
#region SetupCorporateLayout
/// <summary>
/// Sets up the 'Corporate' layout
/// </summary>
private void SetupCorporateLayout()
{
GridPanel panel = superGridControl1.PrimaryGrid;
GridColumnCollection columns = panel.Columns;
// Hide and show various columns to achieve
// the layout we need for this header grouping.
HideColumn(columns, "ContactName");
HideColumn(columns, "ContactTitle");
HideColumn(columns, "Address");
HideColumn(columns, "City");
HideColumn(columns, "PostalCode");
HideColumn(columns, "Phone");
HideColumn(columns, "Region");
HideColumn(columns, "Fax");
ShowColumn(columns, "T1", 90, "Total\nInv. Cost");
ShowColumn(columns, "MTD", 91, null);
ShowColumn(columns, "YTD", 92, null);
ShowColumn(columns, "LTD", 93, "Lifetime");
ShowColumn(columns, "T2", 94, "Market\nPotential");
ShowColumn(columns, "T3", 95, "Market\nMomentum");
columns["CompanyName"].HeaderStyles.Default.Image = imageList3.Images["factory"];
columns["CompanyName"].HeaderStyles.Default.ImageAlignment = Alignment.BottomCenter;
columns["CompanyName"].HeaderStyles.Default.ImagePadding = new DevComponents.DotNetBar.SuperGrid.Style.Padding(0, 0, 0, 15);
// Create and add the subordinate headers
panel.ColumnHeader.GroupHeaders.Add(GetClCurrentInfoHeader(columns));
panel.ColumnHeader.GroupHeaders.Add(GetClProjectedInfoHeader(columns));
}
#region GetClCurrentInfoHeader
/// <summary>
/// Creates and returns the 'Current Info' header.
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetClCurrentInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "CurrentState";
cgh.HeaderText = "Current Balance";
cgh.MinRowHeight = 36;
// Create the 'Sales' header and add it to the group
ColumnGroupHeader cshSales = GetCiSalesHeader(columns);
cgh.GroupHeaders.Add(cshSales);
// We want to also include the "T1" column to the left
// of the added sales range, so we must set the start
// display index to include it.
cgh.StartDisplayIndex = GetDisplayIndex(columns, "T1");
return (cgh);
}
#region GetCiSalesHeader
/// <summary>
/// Creates and returns the 'Sales Info' header.
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetCiSalesHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "SalesInfo";
cgh.HeaderText = "Sales";
cgh.MinRowHeight = 36;
// Set the group's start and end display indicees
cgh.StartDisplayIndex = GetDisplayIndex(columns, "MTD");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "LTD");
return (cgh);
}
#endregion
#endregion
#region GetClProjectedInfoHeader
/// <summary>
/// Creates and returns the 'Projected Info' header.
/// </summary>
/// <param name="columns"></param>
/// <returns></returns>
private ColumnGroupHeader GetClProjectedInfoHeader(GridColumnCollection columns)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "ProjectedInfo";
cgh.HeaderText = "Market Projection";
cgh.MinRowHeight = 36;
// Set the group's start and end indicees
cgh.StartDisplayIndex = GetDisplayIndex(columns, "T2");
cgh.EndDisplayIndex = GetDisplayIndex(columns, "T3");
return (cgh);
}
#endregion
#endregion
#region GetDisplayIndex
/// <summary>
/// Gets the DisplayIndex for the column with the given name.
/// </summary>
/// <param name="columns"></param>
/// <param name="name"></param>
/// <returns></returns>
private int GetDisplayIndex(GridColumnCollection columns, string name)
{
return (columns.GetDisplayIndex(columns[name]));
}
#endregion
#region RemoveColumn
/// <summary>
/// Hides the column with the given name.
/// </summary>
/// <param name="columns"></param>
/// <param name="name"></param>
private void HideColumn(GridColumnCollection columns, string name)
{
columns[name].Visible = false;
}
#endregion
#region ShowColumn
/// <summary>
/// Shows, orders, and set the header text of the
/// column with the given name.
/// </summary>
/// <param name="columns"></param>
/// <param name="name"></param>
/// <param name="dindex"></param>
/// <param name="headerText"></param>
private void ShowColumn(
GridColumnCollection columns, string name, int dindex, string headerText)
{
GridColumn col = columns[name];
col.Visible = true;
col.DisplayIndex = dindex;
if (headerText != null)
col.HeaderText = headerText;
}
#endregion
#endregion
#region ResetLayout
/// <summary>
/// Reset the grid layout back to its default.
/// </summary>
private void ResetLayout()
{
GridPanel panel = superGridControl1.PrimaryGrid;
GridColumnCollection columns = panel.Columns;
for (int i = 0; i < columns.Count; i )
{
GridColumn col = columns[i];
col.Visible = (i < _BaseColumnCount);
col.DisplayIndex = -1;
col.HeaderStyles.Default.Image = null;
col.HeaderStyles.Default.Background = null;
col.HeaderStyles.MouseOver.Background = null;
col.CellStyles.Default.Background = null;
}
columns["Country"].HeaderText = null;
panel.ColumnHeader.GroupHeaders.Clear();
panel.ClearAll();
}
#endregion
#region SuperGridControl1ColumnHeaderMarkupLinkClick
/// <summary>
/// Handles ColumnHeader MarkupLink clicks,
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SuperGridControl1ColumnHeaderMarkupLinkClick(
object sender, GridColumnHeaderMarkupLinkClickEventArgs e)
{
// Do a simple-minded summation of the unique
// country names present in the grid.
int colIndex = e.GridColumn.ColumnIndex;
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (GridRow row in e.GridPanel.FlatRows)
{
string s = row.GetCell(colIndex).Value.ToString();
if (dict.ContainsKey(s) == false)
dict.Add(s, s);
}
MessageBoxEx.Show("There are " dict.Count " unique countries.");
}
#endregion
#region SuperGridControl1ColumnGroupHeaderMarkupLinkClick
/// <summary>
/// Handles GroupHeader MarkupLink clicks.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SuperGridControl1ColumnGroupHeaderMarkupLinkClick(
object sender, GridColumnGroupHeaderMarkupLinkClickEventArgs e)
{
if (e.GroupHeader.Name.Equals("AdInfo") == true)
MessageBoxEx.Show("For More Information, please contact:\n\nDave Stanton at x3227");
}
#endregion
#region SuperGridControl1ColumnGroupHeaderResized
/// <summary>
/// Handles Colum GroupHeader size change notifications
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SuperGridControl1ColumnGroupHeaderResized(object sender, GridColumnGroupHeaderResizedEventArgs e)
{
// If the "ProjectedInfo" size has changed, then clear out our chart
// data so that we can recalc new data based upon the new header size.
if (e.GroupHeader.Name.Equals("ProjectedInfo") == true)
_ChartData1 = _ChartData2 = null;
}
#endregion
#region SuperGridControl1PostRenderColumnGroupHeader
/// <summary>
/// Handles Post rendering of Column GroupHeaders
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SuperGridControl1PostRenderColumnGroupHeader(
object sender, GridPostRenderColumnGroupHeaderEventArgs e)
{
// If the grid is rendering the background of the 'ProjectedInfo'
// GroupHeader, then draw a couple simple 'line charts'.
if ((e.RenderParts & RenderParts.Background) == RenderParts.Background)
{
ColumnGroupHeader cgh = e.GroupHeader;
if (cgh.Name.Equals("ProjectedInfo") == true)
{
Rectangle r = e.Bounds;
r.Inflate(-8, -8);
if (_ChartData1 == null)
_ChartData1 = GetChartData(r, 15);
if (_ChartData2 == null)
_ChartData2 = GetChartData(r, 10);
SmoothingMode sm = e.Graphics.SmoothingMode;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
if (_ChartData1 != null)
e.Graphics.DrawLines(Pens.LightGreen, GetChartPoints(r, _ChartData1));
if (_ChartData2 != null)
e.Graphics.DrawLines(Pens.LightSalmon, GetChartPoints(r, _ChartData2));
e.Graphics.SmoothingMode = sm;
}
}
}
#region GetChartData
/// <summary>
/// Gets chart data, given the current GroupHeader bounds
/// </summary>
/// <param name="r"></param>
/// <param name="dx"></param>
/// <returns></returns>
private Point[] GetChartData(Rectangle r, int dx)
{
int xc = r.Width / dx;
Point[] pts = new Point[xc 1];
Random rand = new Random();
for (int i = 0; i <= xc; i )
pts[i] = new Point(i * dx, -rand.Next(0, r.Height));
return (pts);
}
#endregion
#region GetChartPoints
/// <summary>
/// Gets chart points given the current position of the GroupHeader.
/// </summary>
/// <param name="r"></param>
/// <param name="pts1"></param>
/// <returns></returns>
private Point[] GetChartPoints(Rectangle r, Point[] pts1)
{
Point[] pts2 = new Point[pts1.Length];
for (int i = 0; i < pts2.Length; i )
{
pts2[i].X = pts1[i].X r.X;
pts2[i].Y = pts1[i].Y r.Bottom;
}
return (pts2);
}
#endregion
#endregion
#region ColumnHeaderClick
/// <summary>
/// Handles Column Header clicks.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ColumnHeaderClick(object sender, GridColumnHeaderClickEventArgs e)
{
// If it is a right-mouse click, save of some selection
// info for later use (context menu selection).
if (e.MouseEventArgs.Button == MouseButtons.Right)
{
_HitColumn = e.GridColumn;
GetSelectedColumnRange();
ShowContextMenu(InColumnHeader);
}
}
#region GetSelectedColumnRange
/// <summary>
/// Gets the current range of selected columns.
/// </summary>
private void GetSelectedColumnRange()
{
GridPanel panel = superGridControl1.PrimaryGrid;
GridColumnCollection columns = panel.Columns;
if (_HitColumn.IsSelected == true)
{
int hitIndex = columns.GetDisplayIndex(_HitColumn);
ColumnGroupHeader hitParent = panel.ColumnHeader.GetParentHeader(hitIndex);
_StartColIndex = GetStartDisplayIndex(panel, hitIndex, hitParent);
_EndColIndex = GetEndDisplayIndex(panel, hitIndex, hitParent);
}
else
{
_StartColIndex = columns.GetDisplayIndex(_HitColumn);
_EndColIndex = _StartColIndex;
}
}
#region GetStartDisplayIndex
/// <summary>
/// Gets the starting display index, relative to the
/// given item.
/// </summary>
/// <param name="panel"></param>
/// <param name="hitIndex"></param>
/// <param name="hitParent"></param>
/// <returns></returns>
private int GetStartDisplayIndex(
GridPanel panel, int hitIndex, ColumnGroupHeader hitParent)
{
// Walk backward through all siblings of the given item.
int index = hitIndex;
for (int i = hitIndex; i >= 0; i--)
{
if (IsChildColumn(panel, hitParent, i) == false)
break;
index = i;
}
return (index);
}
#endregion
#region GetEndDisplayIndex
/// <summary>
/// Gets the ending display index relative to the
/// given item.
/// </summary>
/// <param name="panel"></param>
/// <param name="hitIndex"></param>
/// <param name="hitParent"></param>
/// <returns></returns>
private int GetEndDisplayIndex(
GridPanel panel, int hitIndex, ColumnGroupHeader hitParent)
{
// Walk forward through each of the item's siblings.
int index = hitIndex;
for (int i = hitIndex; i < panel.Columns.Count; i )
{
if (IsChildColumn(panel, hitParent, i) == false)
break;
index = i;
}
return (index);
}
#endregion
#region IsChildColumn
/// <summary>
/// Determines if the given column is a child of the given parent item.
/// </summary>
/// <param name="panel"></param>
/// <param name="hitParent"></param>
/// <param name="index"></param>
/// <returns></returns>
private bool IsChildColumn(GridPanel panel, ColumnGroupHeader hitParent, int index)
{
GridColumn column = panel.Columns.ColumnAtDisplayIndex(index);
if (column.Visible == true)
{
if (column.IsSelected == false)
return (false);
ColumnGroupHeader parent = panel.ColumnHeader.GetParentHeader(index);
if (parent != hitParent)
return (false);
}
return (true);
}
#endregion
#endregion
#endregion
#region GroupHeaderClick
/// <summary>
/// Handles Group Header clicks.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void GroupHeaderClick(object sender, GridColumnGroupHeaderClickEventArgs e)
{
if (e.MouseEventArgs.Button == MouseButtons.Right)
{
// Right-mouse button clicks will
// result in context menu being displayed.
_HitGroupHeader = e.GroupHeader;
_SelectedGroupHeaders = GetSelectedHeaders(e);
if (_SelectedGroupHeaders.Count > 1)
ShowContextMenu(InMultipleHeader);
else
ShowContextMenu(InSingleHeader);
}
else if (e.MouseEventArgs.Button == MouseButtons.Left)
{
// Clicking in the PostalInfo header will cause a
// 'cycling' sort on the PostalCode and Country columns.
if (e.GroupHeader.Name.Equals("PostalInfo"))
{
if (e.GridPanel.ColumnGroupHeaderClickBehavior == ColumnHeaderClickBehavior.SortAndReorder)
{
GridColumn[] sortCols = new GridColumn[]
{e.GridPanel.Columns["PostalCode"], e.GridPanel.Columns["Country"]};
if (e.GridPanel.SortColumns.Count == 2)
e.GridPanel.SetSort(sortCols, GetSortDir(sortCols));
else
e.GridPanel.SetSort(sortCols);
e.Cancel = true;
}
}
}
}
#region GetSortDir
/// <summary>
/// Gets the cyclic sort direction for the Postal columns.
/// </summary>
/// <param name="cols"></param>
/// <returns></returns>
private SortDirection[] GetSortDir(GridColumn[] cols)
{
int d1 = (int)(cols[0].SortDirection);
int d2 = (int)(cols[1].SortDirection);
if ( d2 > 2)
{
d2 = 1;
if ( d1 > 2)
d1 = 1;
}
return (new SortDirection[] { (SortDirection)d1, (SortDirection)d2 });
}
#endregion
#region GetSelectedHeaders
/// <summary>
/// Retrieves a list of selected GroupHeaders
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
private List<ColumnGroupHeader> GetSelectedHeaders(GridColumnGroupHeaderClickEventArgs e)
{
List<ColumnGroupHeader> list = new List<ColumnGroupHeader>();
if (_HitGroupHeader.IsSelected == true)
{
// If the header is currently selected, then loop through
// each of the supordinate headers and add them to the list.
ColumnGroupHeaderCollection collection = e.GroupHeader.Collection;
foreach (ColumnGroupHeader cgh in collection)
{
if (cgh.IsSelected == true)
list.Add(cgh);
}
}
else
{
// Not selected, add the single header to the list.
list.Add(_HitGroupHeader);
}
return (list);
}
#endregion
#endregion
#region ShowContextMenu
/// <summary>
/// Shows the given context menu at the
/// current mouse position.
/// </summary>
/// <param name="cm"></param>
private void ShowContextMenu(ButtonItem cm)
{
cm.Popup(MousePosition);
}
#endregion
#region ColumnHeader ClickBehavior change
/// <summary>
/// Handles ColumnHeader ClickBehavior.None events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CbChNoActionCheckedChanged(object sender, EventArgs e)
{
SetColHeaderAction(ColumnHeaderClickBehavior.None);
}
/// <summary>
/// Handles ColumnHeader ClickBehavior.Select events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CbChSelectCheckedChanged(object sender, EventArgs e)
{
SetColHeaderAction(ColumnHeaderClickBehavior.Select);
}
/// <summary>
/// Handles ColumnHeader ClickBehavior.SortAndReorder events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CbChReorderCheckedChanged(object sender, EventArgs e)
{
SetColHeaderAction(ColumnHeaderClickBehavior.SortAndReorder);
}
/// <summary>
/// Sets the ColumnHeader click behavior and then
/// returns focus to the SuperGrid.
/// </summary>
/// <param name="cmode"></param>
private void SetColHeaderAction(ColumnHeaderClickBehavior cmode)
{
superGridControl1.PrimaryGrid.ColumnHeaderClickBehavior = cmode;
superGridControl1.Focus();
}
#endregion
#region GroupHeader ClickBehavior change
/// <summary>
/// Handles GroupHeader ClickBehavior.None events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CbShNoActionCheckedChanged(object sender, EventArgs e)
{
SetGroupHeaderAction(ColumnHeaderClickBehavior.None);
}
/// <summary>
/// Handles GroupHeader ClickBehavior.Select events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CbShSelectCheckedChanged(object sender, EventArgs e)
{
SetGroupHeaderAction(ColumnHeaderClickBehavior.Select);
}
/// <summary>
/// Handles GroupHeader ClickBehavior.SortAndReorder events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CbShReorderCheckedChanged(object sender, EventArgs e)
{
SetGroupHeaderAction(ColumnHeaderClickBehavior.SortAndReorder);
}
/// <summary>
/// Sets the GroupHeader click behavior and then
/// returns focus to the SuperGrid.
/// </summary>
/// <param name="cmode"></param>
private void SetGroupHeaderAction(ColumnHeaderClickBehavior cmode)
{
superGridControl1.PrimaryGrid.ColumnGroupHeaderClickBehavior = cmode;
superGridControl1.Focus();
}
#endregion
#region CbLayoutCheckedChanged
/// <summary>
/// Handle user Layout change requests
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CbLayoutCheckedChanged(object sender, EventArgs e)
{
CheckBoxX cb = sender as CheckBoxX;
if (cb != null && cb.Checked == true)
SetupLayout();
superGridControl1.Focus();
}
#endregion
#region CmiAddHeader
/// <summary>
/// Handles user requests to add a group header.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CmiAddHeader(object sender, EventArgs e)
{
List<ColumnGroupHeader> list = _SelectedGroupHeaders;
if (list.Count > 0)
{
SelectedRange range = GetColumnRange(list);
if (range != null)
{
// The user has selected a range of headers to
// to include in a new GroupHeader, so get a new header
// and set it's start and end display indicees accordingly.
ColumnGroupHeader cgh = GetNewHeader(range.StartIndex, range.EndIndex);
// To add the range of headers to the new header, we must remove them
// from their current collection, and add them to the new header
// collection.
ColumnGroupHeaderCollection pcsc = list[0].Collection;
for (int i = list.Count - 1; i >= 0; i--)
{
pcsc.Remove(list[i]);
cgh.GroupHeaders.Add(list[i]);
}
// Now add the new header to the parent collection.
pcsc.Add(cgh);
}
}
}
#region GetColumnRange
/// <summary>
/// Gets the current selected column range
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
private SelectedRange GetColumnRange(IEnumerable<ColumnGroupHeader> list)
{
SelectedElements items = new SelectedElements();
foreach (ColumnGroupHeader cgh in list)
items.AddRange(cgh.StartDisplayIndex, cgh.EndDisplayIndex);
if (items.Ranges.Count == 1)
return (items.Ranges[0]);
MessageBoxEx.Show("Invalid header range selection.");
return (null);
}
#endregion
#endregion
#region GetNewHeader
/// <summary>
/// Creates and initializes a new GroupHeader.
/// </summary>
/// <param name="start">StartDisplayIndex</param>
/// <param name="end">EndDisplayIndex</param>
/// <returns></returns>
private ColumnGroupHeader GetNewHeader(int start, int end)
{
ColumnGroupHeader cgh = new ColumnGroupHeader();
cgh.Name = "New Header " _HeaderCount ;
cgh.HeaderText = cgh.Name;
cgh.MinRowHeight = 36;
cgh.HeaderStyles.Default.AllowWrap = Tbool.True;
cgh.StartDisplayIndex = start;
cgh.EndDisplayIndex = end;
return (cgh);
}
#endregion
#region DeleteHeader
/// <summary>
/// Handles user delete header requests
/// </summary>
/// <param name="cgh"></param>
private void DeleteHeader(ColumnGroupHeader cgh)
{
ColumnGroupHeaderCollection csc = cgh.Collection;
csc.Remove(cgh);
foreach (ColumnGroupHeader gh in cgh.GroupHeaders)
csc.Add(gh);
}
#endregion
#region CmiChangeSingleHeaderText
/// <summary>
/// Handles Group Header Text change requests
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CmiChangeSingleHeaderText(object sender, EventArgs e)
{
HeaderTextForm form = new HeaderTextForm();
form.HeaderText = _HitGroupHeader.HeaderText;
if (form.ShowDialog() == DialogResult.OK)
_HitGroupHeader.HeaderText = form.HeaderText;
}
#endregion
#region CmiDeleteSingleHeader
/// <summary>
/// Handles Deleting single header requests
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CmiDeleteSingleHeader(object sender, EventArgs e)
{
DeleteHeader(_HitGroupHeader);
}
#endregion
#region CmiDeleteMultipleHeader
/// <summary>
/// Handles Deleting multiple header requests
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CmiDeleteMultipleHeader(object sender, EventArgs e)
{
List<ColumnGroupHeader> list = _SelectedGroupHeaders;
if (list.Count > 0)
{
foreach (ColumnGroupHeader cgh in list)
DeleteHeader(cgh);
}
}
#endregion
#region CmiAddColumnHeader
/// <summary>
/// Handles add column header requests
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CmiAddColumnHeader(object sender, EventArgs e)
{
GridPanel panel = superGridControl1.PrimaryGrid;
ColumnGroupHeader cgh = GetNewHeader(_StartColIndex, _EndColIndex);
// If the _HitColumn has no parent header, then we are at the root
// GroupHeader, defined by the GroupHeaders member in the ColumnHeader.
ColumnGroupHeader pcgh = panel.ColumnHeader.GetParentHeader(_HitColumn) as ColumnGroupHeader;
if (pcgh != null)
pcgh.GroupHeaders.Add(cgh);
else
panel.ColumnHeader.GroupHeaders.Add(cgh);
}
#endregion
#region InSingleHeaderVisibility
#region InSingleHeaderVisibilityPopupShowing
/// <summary>
/// Updates the ShowColumnHeaders context menu display
/// to reflect the current ShowColumnHeaders setting.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InSingleHeaderVisibilityPopupShowing(object sender, EventArgs e)
{
switch (_HitGroupHeader.ShowColumnHeaders)
{
case Tbool.True:
InHeaderVisibilityTrue.FontBold = true;
InHeaderVisibilityFalse.FontBold = false;
InHeaderVisibilityNotSet.FontBold = false;
break;
case Tbool.False:
InHeaderVisibilityTrue.FontBold = false;
InHeaderVisibilityFalse.FontBold = true;
InHeaderVisibilityNotSet.FontBold = false;
break;
default:
InHeaderVisibilityTrue.FontBold = false;
InHeaderVisibilityFalse.FontBold = false;
InHeaderVisibilityNotSet.FontBold = true;
break;
}
}
#endregion
#region InSingleSetVisNotSetClick
/// <summary>
/// Handles user setting ShowColumnHeaders = NotSet.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InSingleSetVisNotSetClick(object sender, EventArgs e)
{
_HitGroupHeader.ShowColumnHeaders = Tbool.NotSet;
}
#endregion
#region InSingleSetVisTrueClick
/// <summary>
/// Handles user setting ShowColumnHeaders = True.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InSingleSetVisTrueClick(object sender, EventArgs e)
{
_HitGroupHeader.ShowColumnHeaders = Tbool.True;
}
#endregion
#region InSingleSetVisFalseClick
/// <summary>
/// Handles user setting ShowColumnHeaders = False.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InSingleSetVisFalseClick(object sender, EventArgs e)
{
_HitGroupHeader.ShowColumnHeaders = Tbool.False;
}
#endregion
#endregion
#region CpColumnHeaderSelectedColorChanged
/// <summary>
/// Handles user Column Header color selection.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CpColumnHeaderSelectedColorChanged(object sender, EventArgs e)
{
ColorPickerDropDown cpd = sender as ColorPickerDropDown;
if (cpd != null)
{
// If the user selects 'White' then reset the colors back
// to their default state.
if (Color.White.ToArgb() == cpd.SelectedColor.ToArgb())
{
if (_HitColumn.IsSelected == true)
{
foreach (GridColumn column in superGridControl1.PrimaryGrid.SelectedColumns)
ResetHeaderBackground(column);
}
else
{
ResetHeaderBackground(_HitColumn);
}
}
else
{
Color color1 = ControlPaint.LightLight(cpd.SelectedColor);
if (_HitColumn.IsSelected == true)
{
foreach (GridColumn column in superGridControl1.PrimaryGrid.SelectedColumns)
SetHeaderBackground(column, color1, cpd.SelectedColor);
}
else
{
SetHeaderBackground(_HitColumn, color1, cpd.SelectedColor);
}
}
superGridControl1.PrimaryGrid.ClearAll();
}
}
#region SetHeaderBackground
/// <summary>
/// Sets the Column header background (Default and MouseOver), as well
/// as the background color of the column cells.
/// </summary>
/// <param name="column"></param>
/// <param name="color1"></param>
/// <param name="color2"></param>
private void SetHeaderBackground(GridColumn column, Color color1, Color color2)
{
column.HeaderStyles.Default.Background = new Background(color1, color2);
column.HeaderStyles.MouseOver.Background = new Background(color2, color1);
column.CellStyles.Default.Background = new Background(ControlPaint.Light(color1));
}
#endregion
#region ResetHeaderBackground
/// <summary>
/// Handles resetting user set header/cell colors.
/// </summary>
/// <param name="column"></param>
private void ResetHeaderBackground(GridColumn column)
{
column.HeaderStyles.Default.Background = null;
column.HeaderStyles.MouseOver.Background = null;
column.CellStyles.Default.Background = null;
}
#endregion
#endregion
#region CpHeaderSelectedColorChanged
/// <summary>
/// Handles user Group Header color selection.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CpHeaderSelectedColorChanged(object sender, EventArgs e)
{
ColorPickerDropDown cpd = sender as ColorPickerDropDown;
if (cpd != null)
{
List<ColumnGroupHeader> list = _SelectedGroupHeaders;
if (list.Count > 0)
{
// If the user selects 'White' then reset the colors back
// to their default state.
if (Color.White.ToArgb() == cpd.SelectedColor.ToArgb())
{
foreach (ColumnGroupHeader cgh in list)
ResetHeaderBackground(cgh);
}
else
{
Color color1 = ControlPaint.LightLight(cpd.SelectedColor);
foreach (ColumnGroupHeader cgh in list)
SetHeaderBackground(cgh, color1, cpd.SelectedColor);
}
}
superGridControl1.PrimaryGrid.ClearAll();
}
}
#region SetHeaderBackground
/// <summary>
/// Sets the Group header background (Default and MouseOver), as well
/// as the background color of the column cells contained in the Group.
/// </summary>
/// <param name="cgh"></param>
/// <param name="color1"></param>
/// <param name="color2"></param>
private void SetHeaderBackground(ColumnGroupHeader cgh, Color color1, Color color2)
{
GridColumnCollection columns = superGridControl1.PrimaryGrid.Columns;
cgh.HeaderStyles.Default.Background = new Background(color1, color2);
cgh.HeaderStyles.MouseOver.Background = new Background(color2, color1);
Color color3 = ControlPaint.LightLight(color1);
for (int i = cgh.StartDisplayIndex; i <= cgh.EndDisplayIndex; i )
columns.ColumnAtDisplayIndex(i).CellStyles.Default.Background = new Background(color3);
}
#endregion
#region ResetHeaderBackground
/// <summary>
/// Handles resetting user set Group Header colors.
/// </summary>
/// <param name="cgh"></param>
private void ResetHeaderBackground(ColumnGroupHeader cgh)
{
GridColumnCollection columns = superGridControl1.PrimaryGrid.Columns;
cgh.HeaderStyles.Default.Background = null;
cgh.HeaderStyles.MouseOver.Background = null;
for (int i = cgh.StartDisplayIndex; i <= cgh.EndDisplayIndex; i )
columns.ColumnAtDisplayIndex(i).CellStyles.Default.Background = null;
}
#endregion
#endregion
#region InSingleHeaderPopupClose
/// <summary>
/// Clears all current selection when the InSingleHeader
/// popup menu is closed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InSingleHeaderPopupClose(object sender, EventArgs e)
{
superGridControl1.PrimaryGrid.ClearAll();
}
#endregion
}
}
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


支持(0) 盖楼(回复)
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)