C1FlexDataGrid數據源設爲DataTable後,如何通過界面獲取DataRow

C1FlexDataGrid數據源設爲DataTable後不能直接獲取當前行或指定行關聯Datarow,只能通過如下方法變通後取得:

DataView dv = new DataView(CurTable);  //獲取DataTable的一個視圖
Column col = ctrl_dataView.SortColumn; //獲取C1FlexDataGrid當前用於排序的列
if (col != null)
{
    string s = col.Sort == SortFlags.Descending ? "desc" : "asc";//獲取升序或降序方式對應的字符串
    dv.Sort = string.Format("{0} {1}", col.Name, s);//爲DataView定義一個與C1FlexDataGrid一樣的索引
}
int rowIdx = row - ctrl_dataView.FixedRows];
DataRow dtRow = dv[rowIdx].Row;  //獲取C1FlexDataGrid中對應的行關聯的DataRow
//如果想獲取具體的Cell對應的數據項繼續往下看:
int colIdx = ctrl_dataView.ColumnCollection[col].DataIndex;
object data = dtRow[colIdx];     //即需要取得的DataTable中對應的數據,可以在編輯完成後立即對dtRow[colIdx]進預賦值,看數據是否滿足要求,如果不滿足則阻止更新。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章