📄 form1.cs
字号:
}
private void menuClearAllGroups_Click(object sender, EventArgs e)
{
outlookGrid1.ClearGroups();
}
private void menuSkinDefault_Click(object sender, EventArgs e)
{
this.outlookGrid1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Info;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.outlookGrid1.DefaultCellStyle = dataGridViewCellStyle2;
this.outlookGrid1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2;
DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Desktop;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.outlookGrid1.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
this.outlookGrid1.GridColor = System.Drawing.SystemColors.ControlDarkDark;
this.outlookGrid1.RowTemplate.Height = 23;
this.outlookGrid1.BackgroundColor = System.Drawing.SystemColors.AppWorkspace;
this.outlookGrid1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
this.outlookGrid1.RowHeadersVisible = true;
this.outlookGrid1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
this.outlookGrid1.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
this.outlookGrid1.AllowUserToAddRows = true;
this.outlookGrid1.AllowUserToDeleteRows = true;
this.outlookGrid1.AllowUserToResizeRows = true;
this.outlookGrid1.EditMode = DataGridViewEditMode.EditOnF2;
this.outlookGrid1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
private void menuSkinOutlook_Click(object sender, EventArgs e)
{
this.outlookGrid1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.outlookGrid1.DefaultCellStyle = dataGridViewCellStyle2;
this.outlookGrid1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2;
DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Desktop;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.outlookGrid1.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
this.outlookGrid1.GridColor = System.Drawing.SystemColors.Control;
this.outlookGrid1.RowTemplate.Height = 19;
this.outlookGrid1.BackgroundColor = System.Drawing.SystemColors.Window;
this.outlookGrid1.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal;
this.outlookGrid1.RowHeadersVisible = false;
this.outlookGrid1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.outlookGrid1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
this.outlookGrid1.AllowUserToAddRows = false;
this.outlookGrid1.AllowUserToDeleteRows = false;
this.outlookGrid1.AllowUserToResizeRows = false;
this.outlookGrid1.EditMode = DataGridViewEditMode.EditProgrammatically;
this.outlookGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.outlookGrid1.ClearGroups(); // reset
}
#endregion menu handlers
#region conversion helper function
private void ConverCSVToXml()
{
TextReader file = File.OpenText(@"D:\Projects\cs2005\OutlookGridApp\Data\invoices.txt");
DataTable table = new DataTable("invoice");
string line = file.ReadLine();
foreach (string s in line.Split('\t'))
table.Columns.Add(s);
line = file.ReadLine();
while (line != null)
{
table.Rows.Add(line.Split('\t'));
line = file.ReadLine();
}
file.Close();
table.WriteXml(@"D:\Projects\cs2005\OutlookGridApp\Data\invoices.xml");
}
#endregion
}
#region Comparers - used to sort CustomerInfo objects and DataRows of a DataTable
/// <summary>
/// reusable custom DataRow comparer implementation, can be used to sort DataTables
/// </summary>
public class DataRowComparer : IComparer
{
ListSortDirection direction;
int columnIndex;
public DataRowComparer(int columnIndex, ListSortDirection direction)
{
this.columnIndex = columnIndex;
this.direction = direction;
}
#region IComparer Members
public int Compare(object x, object y)
{
DataRow obj1 = (DataRow)x;
DataRow obj2 = (DataRow)y;
return string.Compare(obj1[columnIndex].ToString(), obj2[columnIndex].ToString()) * (direction == ListSortDirection.Ascending ? 1 : -1);
}
#endregion
}
// custom object comparer implementation
public class ContactInfoComparer : IComparer
{
private int propertyIndex;
ListSortDirection direction;
public ContactInfoComparer(int propertyIndex, ListSortDirection direction)
{
this.propertyIndex = propertyIndex;
this.direction = direction;
}
#region IComparer Members
public int Compare(object x, object y)
{
ContactInfo obj1 = (ContactInfo)x;
ContactInfo obj2 = (ContactInfo)y;
switch (propertyIndex)
{
case 1:
return CompareStrings(obj1.Name, obj2.Name);
case 2:
return CompareDates(obj1.Date, obj2.Date);
case 3:
return CompareStrings(obj1.Subject, obj2.Subject);
case 4:
return CompareNumbers(obj1.Concentration, obj2.Concentration);
default:
return CompareNumbers((double)obj1.Id, (double)obj2.Id);
}
}
#endregion
private int CompareStrings(string val1, string val2)
{
return string.Compare(val1, val2) * (direction == ListSortDirection.Ascending ? 1 : -1);
}
private int CompareDates(DateTime val1, DateTime val2)
{
if (val1 > val2) return (direction == ListSortDirection.Ascending ? 1 : -1);
if (val1 < val2) return (direction == ListSortDirection.Ascending ? -1 : 1);
return 0;
}
private int CompareNumbers(double val1, double val2)
{
if (val1 > val2) return (direction == ListSortDirection.Ascending ? 1 : -1);
if (val1 < val2) return (direction == ListSortDirection.Ascending ? -1 : 1);
return 0;
}
}
#endregion Comparers
#region ContactInfo - example business object implementation
public class ContactInfo
{
public ContactInfo()
{
}
public ContactInfo(int id, string name, DateTime date, string subject, double con)
{
this.id = id;
this.name = name;
this.date = date;
this.subject = subject;
this.concentration = con;
}
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private DateTime date;
public DateTime Date
{
get { return date; }
set { date = value; }
}
private string subject;
public string Subject
{
get { return subject; }
set { subject = value; }
}
private double concentration;
public double Concentration
{
get { return concentration; }
set { concentration = value; }
}
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -