DevExpress 에서 GridControl 열 헤드 를 구현 하여 Checkbox 를 그 리 는 방법
3176 단어 DevExpressGridControl
주요 기능 코드 는 다음 과 같 습 니 다.
/// <summary>
/// CheckBox
/// </summary>
/// <param name="view">GridView</param>
/// <param name="checkItem">RepositoryItemCheckEdit</param>
/// <param name="fieldName"> Checkbox </param>
/// <param name="e">ColumnHeaderCustomDrawEventArgs</param>
public static void DrawHeaderCheckBox(this GridView view, RepositoryItemCheckEdit checkItem, string fieldName, ColumnHeaderCustomDrawEventArgs e)
{
/* :
* :https://www.devexpress.com/Support/Center/Question/Details/Q354489
* CustomDrawColumnHeader
*eg:
* private void gvCabChDetail_CustomDrawColumnHeader(object sender, DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e)
* {
* GridView _view = sender as GridView;
* _view.DrawHeaderCheckBox(CheckItem, "Check", 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, getCheckedCount(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 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 (_checkStatus)
count++;
}
}
return count;
}
코드 사용 방법 은 다음 과 같 습 니 다.
RepositoryItemCheckEdit CheckItem = new RepositoryItemCheckEdit();
const string gcCheckFieldName = "Checked";
private void gvLampConfig_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{
GridView _view = sender as GridView;
_view.DrawHeaderCheckBox(CheckItem, gcCheckFieldName, e);
}
코드 실행 효 과 는 다음 그림 과 같 습 니 다.이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
DevExpress GridControl 데이터 바인딩본인은 재주가 없군요. 두 시간 넘게 고생해서야 데이터를 연결했습니다.이제 더 많은 친구들을 돕기 위해 고생 과정을 기록해 두고, 자신도 복습해 보자. 코드로 바로 올라갔네... WPF 하 xaml 파일 이상 주의:...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.