devexpress的Gridview控件,如何获取Gridview DataItemTemplate中定义的控件的焦点???
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了devexpress的Gridview控件,如何获取Gridview DataItemTemplate中定义的控件的焦点???相关的知识,希望对你有一定的参考价值。
public Control FindRowCellTemplateControl(int visibleIndex,
GridViewDataColumn gridViewDataColumn,
string id
)
AspxGridView有找到模板中控件的API,上面是其中一个例子,可以去官网查一下 . 找到控件后就可以像普通的一样操作了.
或者这样?GridView1.Rows[].Cells[] 这是单元格
你要所有的不就是集合么?
参考技术B 是AspxGridview吧?
1如何给devexpress的gridview控件绘制全选按钮
1 首先注册gridview的this.edibandedGridView.CustomDrawColumnHeader += EdibandedGridView_CustomDrawColumnHeader事件,然后在事件中写入如下代码:
private void EdibandedGridView_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{
RepositoryItemCheckEdit checkItem = new RepositoryItemCheckEdit();
GridView _view = sender as GridView;
_view.DrawHeaderCheckBox(checkItem, "Check", e);
}
其中DrawHeaderCheckBox方法为其扩展方法:
public static void DrawHeaderCheckBox(this GridView view, RepositoryItemCheckEdit checkItem, string fieldName, ColumnHeaderCustomDrawEventArgs e)
{
if (e.Column != null && e.Column.FieldName.Equals(fieldName))
{
e.Info.InnerElements.Clear();
e.Painter.DrawObject(e.Info);
DrawCheckBox(checkItem, e.Graphics, e.Bounds, getCheckedCount2(view, fieldName) == view.DataRowCount);
e.Handled = true;
}
}
private static void DrawCheckBox(RepositoryItemCheckEdit checkItem, Graphics g, Rectangle r, bool Checked)
{
CheckEditViewInfo _info;
CheckEditPainter _painter;
ControlGraphicsInfoArgs _args;
_info = checkItem.CreateViewInfo() as CheckEditViewInfo;
_painter = checkItem.CreatePainter() as CheckEditPainter;
_info.EditValue = Checked;
_info.Bounds = r;
_info.PaintAppearance.ForeColor = Color.Black;
_info.CalcViewInfo(g);
_args = new ControlGraphicsInfoArgs(_info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
_painter.Draw(_args);
_args.Cache.Dispose();
}
然后注册 this.edibandedGridView.MouseDown += EdibandedGridView_MouseDown事件实现全选和单选:
private void EdibandedGridView_MouseDown(object sender, MouseEventArgs e)
{
GridView _view = sender as GridView;
_view.SyncCheckStatus("Check", e);
}
SyncCheckStatus方法为扩张方法。DrawHeaderCheckBoxExtension类为所有所需方法的封装类
public static class DrawHeaderCheckBoxExtension
{
public static void SyncCheckStatus(this GridView view, string fieldeName, MouseEventArgs e)
{
if (e.Clicks == 1 && e.Button == MouseButtons.Left)
{
view.ClearSorting();
view.PostEditor();
GridHitInfo _info;
Point _pt = view.GridControl.PointToClient(Control.MousePosition);
_info = view.CalcHitInfo(_pt);
if (_info.InColumn && _info.Column.FieldName.Equals(fieldeName))
{
if (getCheckedCount(view, fieldeName) == view.DataRowCount)
UnChekAll(view, fieldeName);
else
CheckAll(view, fieldeName);
}
}
}
private static int getCheckedCount(GridView view, string filedName)
{
int count = 0;
for (int i = 0; i < view.DataRowCount; i++)
{
object _cellValue = view.GetRowCellValue(i, view.Columns[filedName]);
if (_cellValue == null) continue;
if (string.IsNullOrEmpty(_cellValue.ToString().Trim())) continue;
bool _checkStatus = false;
if (bool.TryParse(_cellValue.ToString(), out _checkStatus))
{
//if ((bool)_cellValue)
if (_checkStatus)
count++;
}
}
return count;
}
private static void CheckAll(GridView view, string fieldName)
{
for (int i = 0; i < view.DataRowCount; i++)
{
var row = view.GetRow(i) as GIDManager.Utility.GIDAPIDataServiceAPI.EDISearchEntity;
if (row!=null)
{
row.Check = true;
}
}
view.RefreshData();
}
private static void UnChekAll(GridView view, string fieldName)
{
for (int i = 0; i < view.DataRowCount; i++)
{
var row = view.GetRow(i) as GIDManager.Utility.GIDAPIDataServiceAPI.EDISearchEntity;
if (row != null)
{
row.Check = false;
}
//view.SetRowCellValue(i, col, false);
}
view.RefreshData();
}
public static void DrawHeaderCheckBox(this GridView view, RepositoryItemCheckEdit checkItem, string fieldName, ColumnHeaderCustomDrawEventArgs e)
{
if (e.Column != null && e.Column.FieldName.Equals(fieldName))
{
e.Info.InnerElements.Clear();
e.Painter.DrawObject(e.Info);
DrawCheckBox(checkItem, e.Graphics, e.Bounds, getCheckedCount2(view, fieldName) == view.DataRowCount);
e.Handled = true;
}
}
private static void DrawCheckBox(RepositoryItemCheckEdit checkItem, Graphics g, Rectangle r, bool Checked)
{
CheckEditViewInfo _info;
CheckEditPainter _painter;
ControlGraphicsInfoArgs _args;
_info = checkItem.CreateViewInfo() as CheckEditViewInfo;
_painter = checkItem.CreatePainter() as CheckEditPainter;
_info.EditValue = Checked;
_info.Bounds = r;
_info.PaintAppearance.ForeColor = Color.Black;
_info.CalcViewInfo(g);
_args = new ControlGraphicsInfoArgs(_info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
_painter.Draw(_args);
_args.Cache.Dispose();
}
private static int getCheckedCount2(GridView view, string filedName)
{
int count = 0;
for (int i = 0; i < view.DataRowCount; i++)
{
object _cellValue = view.GetRowCellValue(i, view.Columns[filedName]);
if (_cellValue == null) continue;
if (string.IsNullOrEmpty(_cellValue.ToString().Trim())) continue;
bool _checkStatus = false;
if (bool.TryParse(_cellValue.ToString(), out _checkStatus))
{
if (_checkStatus)
count++;
}
}
return count;
}
}
以上是关于devexpress的Gridview控件,如何获取Gridview DataItemTemplate中定义的控件的焦点???的主要内容,如果未能解决你的问题,请参考以下文章
如何在DevExpress的GridView控件里面添加多选框的列
1如何给devexpress的gridview控件绘制全选按钮
C# DevExpress控件 repositoryItemCheckEdit
devexpress gridview 中选择多行 剪切,粘帖功能怎么做?
用DevExpress中的GridView控件时,设置模板列为RichTextEdit类型,默认显示的字体更改不过来是啥问题?