This commit is contained in:
240
source/WinFormApp/UtilGridColumnSelector.cs
Normal file
240
source/WinFormApp/UtilGridColumnSelector.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using Infragistics.Win.UltraWinGrid;
|
||||
using System.Data;
|
||||
using log4net;
|
||||
|
||||
namespace AyaNova
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UtilGridColumnSelector.
|
||||
/// </summary>
|
||||
public class UtilGridColumnSelector : System.Windows.Forms.Form
|
||||
{
|
||||
// Create a logger for use in this class
|
||||
//case 1039 private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.Container components = null;
|
||||
|
||||
|
||||
//attributes
|
||||
private Infragistics.Win.UltraWinGrid.UltraGridBand mBand;
|
||||
private Infragistics.Win.UltraWinGrid.UltraGrid gridColumns;
|
||||
private System.Data.DataSet dsColumns;
|
||||
|
||||
public UtilGridColumnSelector()
|
||||
{
|
||||
//
|
||||
// Required for Windows Form Designer support
|
||||
//
|
||||
InitializeComponent();
|
||||
HideColumns.Add("REMOVE","REMOVE");
|
||||
|
||||
|
||||
}
|
||||
|
||||
//columns that should not be even shown to be
|
||||
//made visible
|
||||
private Hashtable mHideColumns=new Hashtable();
|
||||
|
||||
public Hashtable HideColumns
|
||||
{
|
||||
get
|
||||
{
|
||||
return mHideColumns;
|
||||
}
|
||||
}
|
||||
|
||||
public Infragistics.Win.UltraWinGrid.UltraGridBand BandToEdit
|
||||
{
|
||||
set
|
||||
{
|
||||
mBand=value;
|
||||
FillColumnList();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose( bool disposing )
|
||||
{
|
||||
if( disposing )
|
||||
{
|
||||
if(components != null)
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
}
|
||||
base.Dispose( disposing );
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UtilGridColumnSelector));
|
||||
this.gridColumns = new Infragistics.Win.UltraWinGrid.UltraGrid();
|
||||
((System.ComponentModel.ISupportInitialize)(this.gridColumns)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// gridColumns
|
||||
//
|
||||
this.gridColumns.Cursor = System.Windows.Forms.Cursors.Default;
|
||||
this.gridColumns.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ResizeAllColumns;
|
||||
this.gridColumns.DisplayLayout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No;
|
||||
this.gridColumns.DisplayLayout.Override.AllowColMoving = Infragistics.Win.UltraWinGrid.AllowColMoving.NotAllowed;
|
||||
this.gridColumns.DisplayLayout.Override.AllowColSwapping = Infragistics.Win.UltraWinGrid.AllowColSwapping.NotAllowed;
|
||||
this.gridColumns.DisplayLayout.Override.AllowDelete = Infragistics.Win.DefaultableBoolean.False;
|
||||
this.gridColumns.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False;
|
||||
this.gridColumns.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.True;
|
||||
this.gridColumns.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortSingle;
|
||||
this.gridColumns.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
|
||||
this.gridColumns.DisplayLayout.Override.RowSizing = Infragistics.Win.UltraWinGrid.RowSizing.AutoFixed;
|
||||
this.gridColumns.DisplayLayout.Override.SelectTypeCell = Infragistics.Win.UltraWinGrid.SelectType.None;
|
||||
this.gridColumns.DisplayLayout.Override.SelectTypeCol = Infragistics.Win.UltraWinGrid.SelectType.None;
|
||||
this.gridColumns.DisplayLayout.Override.SelectTypeRow = Infragistics.Win.UltraWinGrid.SelectType.None;
|
||||
this.gridColumns.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.gridColumns.Location = new System.Drawing.Point(0, 0);
|
||||
this.gridColumns.Name = "gridColumns";
|
||||
this.gridColumns.Size = new System.Drawing.Size(323, 699);
|
||||
this.gridColumns.TabIndex = 0;
|
||||
this.gridColumns.AfterCellUpdate += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.gridColumns_AfterCellUpdate);
|
||||
//
|
||||
// UtilGridColumnSelector
|
||||
//
|
||||
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
|
||||
this.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.ClientSize = new System.Drawing.Size(323, 699);
|
||||
this.Controls.Add(this.gridColumns);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "UtilGridColumnSelector";
|
||||
this.ShowInTaskbar = false;
|
||||
this.Closing += new System.ComponentModel.CancelEventHandler(this.UtilGridColumnSelector_Closing);
|
||||
((System.ComponentModel.ISupportInitialize)(this.gridColumns)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
private void FillColumnList()
|
||||
{
|
||||
//case 1039 //log.Debug("FillColumnList");
|
||||
|
||||
dsColumns=new DataSet();
|
||||
dsColumns.Tables.Add();
|
||||
|
||||
dsColumns.Tables[0].Columns.Add("Column",typeof(string));
|
||||
dsColumns.Tables[0].Columns.Add("Show",typeof(bool));
|
||||
dsColumns.Tables[0].Columns.Add("Key",typeof(string));
|
||||
|
||||
DataRow dr;
|
||||
foreach(UltraGridColumn c in mBand.Columns)
|
||||
{
|
||||
|
||||
|
||||
if(!Util.PrivateColumns.Contains(c.Key) &&
|
||||
!mHideColumns.Contains(c.Key) &&
|
||||
c.DataType.ToString()!="Infragistics.Win.UltraWinGrid.ChapteredColumnType")
|
||||
{
|
||||
dr=dsColumns.Tables[0].NewRow();
|
||||
dr["Show"]=!c.Hidden;
|
||||
dr["Column"]=c.Header.Caption;
|
||||
dr["Key"]=c.Key;
|
||||
dsColumns.Tables[0].Rows.Add(dr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
gridColumns.DataSource=dsColumns;
|
||||
gridColumns.DisplayLayout.Bands[0].Columns["Key"].Hidden=true;
|
||||
gridColumns.DisplayLayout.Bands[0].Columns["Column"].CellActivation=Activation.NoEdit;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save changes back into grid
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void UtilGridColumnSelector_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//case 1039 //log.Debug("UtilGridColumnSelector_Closing");
|
||||
|
||||
//Ensure all changes are committed in the grid
|
||||
//required because clicking on close will not trigger the update since
|
||||
//close X in corner of screen doesnt' take focus which means grid doesn't lose focus
|
||||
//which means updates aren't committed
|
||||
gridColumns.UpdateData();
|
||||
|
||||
DataRow dr;
|
||||
|
||||
//Case 197
|
||||
bool bOneVisible = false;
|
||||
foreach (DataRow r in dsColumns.Tables[0].Rows)
|
||||
{
|
||||
if ((bool)r["Show"] == true)
|
||||
{
|
||||
bOneVisible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bOneVisible)
|
||||
{
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(int x=0;x<dsColumns.Tables[0].Rows.Count;x++)
|
||||
{
|
||||
dr=dsColumns.Tables[0].Rows[x];
|
||||
foreach(UltraGridColumn c in mBand.Columns)
|
||||
{
|
||||
if(c.Key==(string)dr["Key"])
|
||||
c.Hidden=!(bool)dr["Show"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Case 1252
|
||||
//If there is a remove column, make sure it's still the rightmost
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void gridColumns_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
|
||||
{
|
||||
//see if there is at least one checked column, if not then check this cell
|
||||
foreach(UltraGridRow r in gridColumns.Rows)
|
||||
{
|
||||
if((bool)r.Cells["Show"].Value==true)
|
||||
{
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Oops, none are checked, can't have that...
|
||||
e.Cell.Value=true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user