标签:devexpress datagrid 常见用法 winform
刚接触DevExpress第三方控件,把DataGrid的常见用法整理一下,以供参考:
说明:
gcTest GridControl
gvText GridView
<span style="font-size:14px;"> DataTable dt=new DataTable ();//绑定
gcTest.DataSource = dt;
//隐藏最上面的GroupPanel
gvText.OptionsView.ShowGroupPanel = false;
//修改最上面的GroupPanel
gvText.GroupPanelText = "修改后的内容";
//单元格不可编辑
gvText.OptionsBehavior.Editable = false;
//某列标题居中 0是列索引
gvText.Columns[0].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
//某列内容居中 0是列索引
gvText.Columns[0].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
//冻结列
gvText.Columns[0].Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left;
//自动改变行高适应内容
gvText.OptionsView.RowAutoHeight = true;
//显示自动筛选行
gvText.OptionsView.ShowAutoFilterRow = false;
//不显示字表信息
gvText.OptionsView.ShowDetailButtons = false;
//自动调整列宽
gvText.BestFitColumns();
//特殊列设置 日期
string strDate="yyyy-MM-dd HH:mm";
RepositoryItemDateEdit ride = new RepositoryItemDateEdit();
ride.DisplayFormat.FormatString = strDate;
ride.EditFormat.FormatString = strDate;
ride.EditMask = strDate;
gvText.Columns["日期"].ColumnEdit = ride;
//特殊列设置 decimal 价格
/* 说明:
另一个项目的一些代码:
namespace CYSoft.TS.Common
{
public class Common
{
public const string MoneyFormatStr = "##,###,###,###,##0.00";
}
}
*/
RepositoryItemCalcEdit rice = new RepositoryItemCalcEdit();
rice.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
rice.DisplayFormat.FormatString = TS.Common.Common.MoneyFormatStr;
rice.EditFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
rice.EditFormat.FormatString = TS.Common.Common.MoneyFormatStr;
rice.EditMask = TS.Common.Common.MoneyFormatStr;
gv.Columns["价格"].ColumnEdit = rice;
//给单元格赋值
gvText.SetRowCellValue(3, gvText.Columns["列名或列索引"],"要赋的值");
//添加行
gvText.AddNewRow();
//添加列
DevExpress.XtraGrid.Columns.GridColumn col = new DevExpress.XtraGrid.Columns.GridColumn();
col.Caption = "列标题";
col.FieldName = "列字段值";
col.Visible = true;
col.VisibleIndex = gvText.Columns.Count;
gvText.Columns.Add(col);</span><span style="font-size:14px;"> /// <summary>
/// 获取选定行指定列单元格的值
/// </summary>
/// <param name="str">指定列的列名</param>
/// <returns>单元格的值</returns>
public string GetCellValue(string str) {
int[] pRows = this.gvText.GetSelectedRows();
if (pRows.GetLength(0) > 0){
return gvText.GetRowCellValue(pRows[0], str).ToString();
}
else {
return null;
}
}</span>标签:devexpress datagrid 常见用法 winform
原文地址:http://blog.csdn.net/u013816709/article/details/45043713