轉帖|其它|編輯:郝浩|2012-01-03 21:59:03.000|閱讀 2124 次
概述:DevExpess的GridView控件,和傳統WinFrom的GridView有很大的不同,如他沒有GetSelectedRow的行集合操作,但可以通過GetSelectedRows獲取制定的行序號,通過行序號來進行操作,如要獲得指定行,制定列的內容,可以通過GetRowCellDisplayText 獲取文本或者通過GetRowCellValue獲取對應的值。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
獲取選定行制定列的內容,用于刪除記錄的操作代碼如下:
DevExpess的GridView控件,和傳統WinFrom的GridView有很大的不同,如他沒有GetSelectedRow的行集合操作,但可以通過GetSelectedRows獲取制定的行序號,通過行序號來進行操作,如要獲得指定行,制定列的內容,可以通過GetRowCellDisplayText 獲取文本或者通過GetRowCellValue獲取對應的值。
如果需要獲取當前選定行(焦點所在行)的制定列的數據,那么可以通過函數GetFocusedRowCellDisplayText("ID")來獲取。
private void winGridViewPager1_OnDeleteSelected(object sender, EventArgs e)
{
if (MessageUtil.ShowYesNoAndTips("您確定刪除選定的記錄么?") == DialogResult.No)
{
return;
}
int[] rowSelected = this.winGridViewPager1.GridView1.GetSelectedRows();
foreach (int iRow in rowSelected)
{
string ID = this.winGridViewPager1.GridView1.GetRowCellDisplayText(iRow, "ID");
BLLFactory<ItemDetail>.Instance.Delete(ID);
}
BindData();
}
為GridView行提示信息以及顯示行號,有時候為了方便數據的顯示,需要在GridView的第一列顯示該列的行信息以及行號,那么需要為GridView控件添加一個ToolTipController控件,然后實現該控件的GetActiveObjectInfo事件,在事件里面添加下面代碼以及實現GridView控件的CustomDrawRowIndicator事件即可,如下代碼所示。
private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{
if (e.SelectedControl != gridControl1) return;
ToolTipControlInfo info = null;
//Get the view at the current mouse position
GridView view = gridControl1.GetViewAt(e.ControlMousePosition) as GridView;
if (view == null) return;
//Get the view's element information that resides at the current position
GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
//Display a hint for row indicator cells
if (hi.HitTest == GridHitTest.RowIndicator)
{
//An object that uniquely identifies a row indicator cell
object o = hi.HitTest.ToString() + hi.RowHandle.ToString();
StringBuilder sb = new StringBuilder();
sb.AppendLine("行數據基本信息:");
foreach (GridColumn gridCol in view.Columns)
{
if (gridCol.Visible)
{
sb.AppendFormat(" {0}:{1}\r\n", gridCol.Caption, view.GetRowCellDisplayText(hi.RowHandle, gridCol.FieldName));
}
}
info = new ToolTipControlInfo(o, sb.ToString());
}
//Supply tooltip information if applicable, otherwise preserve default tooltip (if any)
if (info != null)
{
e.Info = info;
}
}
private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
if (ShowLineNumber)
{
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
if (e.Info.IsRowIndicator)
{
if (e.RowHandle >= 0)
{
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
}
}
}
以上雖然是使用了我的DevExpress分頁控件,不過分頁控件的內部就是使用了DevExpress的GridControl控件的。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:網絡轉載