این هم توابع کار با DevExpress Grid حدود 1 هفته زمان برد
#region DevExpressGridControl
/// <summary>
/// انتقال به سلول
/// </summary>
/// <param name="cellDisplayIndex">ایندکس سطون</param>
/// <param name="rowIndex">gridControl.GetRowHandleByVisibleI ndex ایندکس ردیف</param>
/// <param name="editMode">به حالت ویرایش برود</param>
/// uxTableView_MoreBarCode.FocusedRowHandle
///uxTableView_MoreBarCode.FocusedColumn.VisibleIndex
/// <returns>در حالت ویرایش است</returns>
public static bool FocusCell(GridControl gridControl, int rowIndex, int cellDisplayIndex, bool editMode = false)
{
bool returnEditMode = false;
gridControl.View.FocusedRowHandle = rowIndex;
gridControl.SelectItem(rowIndex);
if (gridControl.View.NavigationStyle == GridViewNavigationStyle.Cell)
{
if (gridControl.Columns.Count > cellDisplayIndex)
{
//tableView.FocusedRowHandle = rowIndex;
if (gridControl.IsValidRowHandle(rowIndex))
{
var cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
if (cellEleent != null && cellEleent.IsVisible)
{
gridControl.Columns[cellDisplayIndex].Focus();
gridControl.View.FocusedRowHandle = rowIndex;
cellEleent.Focus();
if (editMode && cellEleent.IsEnabled)
{
//System.Windows.Threading.Dispatcher.BeginInvoke(ne w Action(() => {
gridControl.View.ShowEditor(true);
//}), DispatcherPriority.Render);
returnEditMode = true;
}
}
}
}
}
return returnEditMode;
}
/// <summary>
/// مقدار سلول
/// </summary>
public static object GetCellValue(GridControl gridControl, int rowIndex, int cellDisplayIndex)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return null;
return gridControl.GetCellValue(rowIndex, gridControl.Columns[cellDisplayIndex]);
}
/// <summary>
/// دادن مقدار به سلول
/// در تابع CellValueChanged استفاده نشود!!!!
/// مگر با استفاده از این شرط
/// var currentCellData = e.Value;
/// if (currentCellData == null || e.Value.ToString() == e.OldValue.ToString())
/// {
/// return;
/// }
///
/// uxTableView_MoreBarCode.FocusedRowHandle
///uxTableView_MoreBarCode.FocusedColumn.VisibleIndex
/// </summary>
public static bool SetCellValue(GridControl gridControl, int rowIndex, int cellDisplayIndex, object cellData)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return false;
try
{
gridControl.SetCellValue(rowIndex, gridControl.Columns[cellDisplayIndex], cellData);
return true;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// دادن خطا یا پاک کردن خطا ولیدیت در سلول
/// uxTableView_MoreBarCode.FocusedRowHandle
///uxTableView_MoreBarCode.FocusedColumn.VisibleIndex
/// </summary>
public static bool SetCellValidator(GridControl gridControl, int rowIndex, int cellDisplayIndex)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return false;
try
{
gridControl.View.FocusedRowHandle = rowIndex;
gridControl.SelectItem(rowIndex);
if (gridControl.View.NavigationStyle == GridViewNavigationStyle.Cell)
{
if (gridControl.Columns.Count > cellDisplayIndex)
{
//tableView.FocusedRowHandle = rowIndex;
if (gridControl.IsValidRowHandle(rowIndex))
{
FrameworkElement cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
gridControl.Columns[cellDisplayIndex].Focus();
gridControl.View.FocusedRowHandle = rowIndex;
cellEleent.Focus();
var cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
// var validationError = BaseEdit.ShowErrorProperty(cellElement.CellData);
//BorderThickness
DevExpress.Xpf.Grid.LightweightCellEditor lightweightCellEditor = (DevExpress.Xpf.Grid.LightweightCellEditor)cellEle ent;
var readerItem = ((InplaceBaseEdit)lightweightCellEditor.Content);
var testboxTemp = readerItem.Settings;
if (testboxTemp is DevExpress.Xpf.Editors.Settings.TextEditSettings)
{
var eee= ((DevExpress.Xpf.Editors.Settings.TextEditSettings )testboxTemp);
}
//}), DispatcherPriority.Render);
return true;
}
}
}
return true;
}
catch (Exception)
{
return false;
}
}
///// <summary>
///// آیا سلول خطا دارد
///uxTableView_MoreBarCode.FocusedRowHandle
///uxTableView_MoreBarCode.FocusedColumn.VisibleIndex
///// </summary>
public static bool GetCellValidate(GridControl gridControl, int rowIndex, int cellDisplayIndex)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return false;
var cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
var result = cellElement.GetType()
.InvokeMember("HasEditorError",
BindingFlags.InvokeMethod |
BindingFlags.NonPublic |
BindingFlags.Instance,
null,
cellElement,
null);
if (result == null)
{
return false;
}
return (bool)result;
}
///// <summary>
///// سلول در حالت ویرایش قرار میدهد
///uxTableView_MoreBarCode.FocusedRowHandle
///uxTableView_MoreBarCode.FocusedColumn.VisibleIndex
///// </summary>
public static bool CellEditMode(GridControl gridControl, int rowIndex, int cellDisplayIndex)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return false;
var cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
var cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
DevExpress.Xpf.Grid.LightweightCellEditor lightweightCellEditor = (DevExpress.Xpf.Grid.LightweightCellEditor)cellEle ent;
var result = lightweightCellEditor.Edit.IsReadOnly;
if (result == null)
{
return false;
}
cellElement.Focus();
cellElement.ShowEditor();
return true;
}
///// <summary>
///// آیا سلول در حالت ویرایش است؟
///uxTableView_MoreBarCode.FocusedRowHandle
///uxTableView_MoreBarCode.FocusedColumn.VisibleIndex
///// </summary>
public static bool CellIsEditMode(GridControl gridControl, int rowIndex, int cellDisplayIndex)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return false;
CellEditorBase cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
var cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
DevExpress.Xpf.Grid.LightweightCellEditor lightweightCellEditor = (DevExpress.Xpf.Grid.LightweightCellEditor)cellEle ent;
if (cellElement.IsFocusedCell )
{
var result = lightweightCellEditor.Edit.IsReadOnly;
if (result == null || (bool)result != false)
{
return false;
}
if (!cellElement.CanShowEditor())
{
return false;
}
//if (!cellElement.Edit.IsEditorActive)
//{
// return false;
//}
//return cellEleent.IsKeyboardFocused;
return true;
}
return false;
// (bool)readOnlyData;
//cellElement.CanShowEditor();
// CanShowEditor
//cellEleent.IsKeyboardFocused;
}
///// <summary>
///// رفتن به سلول مورد نظر
///// </summary>
public static void MoveToCell(GridControl gridControl, int rowIndex, int cellDisplayIndex)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return;
CellEditorBase cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
var cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
cellEleent.Focus();
//cellElement.ShowEditor();
}
/////// <summary>
/////// دادن رنگ به سلول
/////// </summary>
//public static void SetCellBorderColor(GridControl gridControl, int rowIndex, int cellDisplayIndex, System.Windows.Media.Brush borderColor)
//{
// if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
// return;
// CellEditorBase cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
// var cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
// DevExpress.Xpf.Grid.LightweightCellEditor lightweightCellEditor = (DevExpress.Xpf.Grid.LightweightCellEditor)cellEle ent;
// lightweightCellEditor.BorderBrush = borderColor;
//}
///// <summary>
///// دادن رنگ به سلول
///// </summary>
public static void SetCellColor(GridControl gridControl, int rowIndex, int cellDisplayIndex, System.Windows.Media.Brush backgroundColor)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return;
CellEditorBase cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
var cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
DevExpress.Xpf.Grid.LightweightCellEditor lightweightCellEditor = (DevExpress.Xpf.Grid.LightweightCellEditor)cellEle ent;
lightweightCellEditor.Background = backgroundColor;
}
///// <summary>
///// دادن رنگ به ردیف
///// </summary>
public static void SetRowColor(GridControl gridControl, int rowIndex, System.Windows.Media.Brush backgroundColor)
{
if (!gridControl.IsValidRowHandle(rowIndex))
return;
var rowEleent = gridControl.View.GetRowElementByRowHandle(rowIndex );
DevExpress.Xpf.Grid.RowControl lightweightRowControl = (DevExpress.Xpf.Grid.RowControl)rowEleent;
lightweightRowControl.Background = backgroundColor;
}
///// <summary>
///// دادن اندازه قلم به سلول
///uxTableView_MoreBarCode.FocusedRowHandle
///uxTableView_MoreBarCode.FocusedColumn.VisibleIndex
///// </summary>
public static void SetCellFontSize(GridControl gridControl, int rowIndex, int cellDisplayIndex,double fontSize)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return;
CellEditorBase cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
var cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
DevExpress.Xpf.Grid.LightweightCellEditor lightweightCellEditor = (DevExpress.Xpf.Grid.LightweightCellEditor)cellEle ent;
lightweightCellEditor.FontSize = fontSize;
}
///// <summary>
///// دادن اندازه قلم به یک ردیف خواص
///uxTableView_MoreBarCode.FocusedRowHandle
///uxTableView_MoreBarCode.FocusedColumn.VisibleIndex 2
///// </summary>
public static void SetRowFontSize(GridControl gridControl, int rowIndex, int cellDisplayIndex, System.Windows.Media.FontFamily fontFamily)
{
if (!gridControl.IsValidRowHandle(rowIndex) || gridControl.Columns.Count < cellDisplayIndex)
return;
CellEditorBase cellElement = (CellEditorBase)gridControl.View.GetCellElementByR owHandleAndColumn(rowIndex, gridControl.Columns[cellDisplayIndex]);
var cellEleent = gridControl.View.GetCellElementByRowHandleAndColum n(rowIndex, gridControl.Columns[cellDisplayIndex]);
DevExpress.Xpf.Grid.LightweightCellEditor lightweightCellEditor = (DevExpress.Xpf.Grid.LightweightCellEditor)cellEle ent;
lightweightCellEditor.FontFamily = fontFamily;
}
#endregion
واقا کار سختی بود و تو اینترنت هم هیچ کجا کدی در این باره نبود همش وصل اش میکردن به معماری mvvm داغون