97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
using DevExpress.XtraGrid.Columns;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
public partial class FrmPositioningColumn : BaseForm
|
|
{
|
|
/// <summary>
|
|
/// 显示列的列名和对应名称
|
|
/// </summary>
|
|
public Dictionary<string, string> ColumnInformation = new Dictionary<string, string>();
|
|
/// <summary>
|
|
/// 查找列名称
|
|
/// </summary>
|
|
public string FindName;
|
|
|
|
public FrmPositioningColumn()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public FrmPositioningColumn(Dictionary<string, string> columnInformation)
|
|
{
|
|
InitializeComponent();
|
|
this.ColumnInformation = columnInformation;
|
|
this.CreateColumn();
|
|
|
|
this.gridView.DoubleClick += GridView_DoubleClick;
|
|
}
|
|
|
|
|
|
|
|
private void CreateColumn()
|
|
{
|
|
GridColumn Caption = new GridColumn();
|
|
Caption.Caption = "用户名称";
|
|
Caption.FieldName = "Caption";
|
|
Caption.MinWidth = 38;
|
|
Caption.Visible = true;
|
|
Caption.VisibleIndex = 1;
|
|
Caption.Width = 100;
|
|
Caption.OptionsColumn.AllowEdit = false;
|
|
|
|
GridColumn FieldName = new GridColumn();
|
|
FieldName.Caption = "系统名称";
|
|
FieldName.FieldName = "FieldName";
|
|
FieldName.MinWidth = 38;
|
|
FieldName.Visible = true;
|
|
FieldName.VisibleIndex = 0;
|
|
FieldName.Width = 150;
|
|
FieldName.OptionsColumn.AllowEdit = false;
|
|
|
|
this.gridView.Columns.AddRange(new GridColumn[] {
|
|
FieldName,
|
|
Caption,
|
|
});
|
|
|
|
// 初始化DataTable
|
|
if (this.ColumnInformation.Count > 0)
|
|
{
|
|
DataTable dataTable = new DataTable();
|
|
dataTable.Columns.Add("Caption", typeof(string));
|
|
dataTable.Columns.Add("FieldName", typeof(string));
|
|
|
|
|
|
foreach (string item in ColumnInformation.Keys)
|
|
{
|
|
string value = ColumnInformation[item];
|
|
dataTable.Rows.Add(value, item);
|
|
}
|
|
this.gridControl.DataSource = dataTable;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void GridView_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
this.FindName = string.Empty;
|
|
DataRow rowItem = this.gridView.GetFocusedDataRow();
|
|
if (rowItem != null)
|
|
{
|
|
this.FindName = rowItem["FieldName"] + "";
|
|
this.Close();
|
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
|
}
|
|
}
|
|
}
|
|
}
|