1-) C# DEVEXPRESS RMOS - treeList1 columna checkbox ekleme ve genel bilgiler ShowCheckBoxes MultiSelect ShowAutoFilterRow
kaynak : https://www.devexpress.com/Support/Center/Question/Details/Q95627/header-checkbox
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.ViewInfo;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList.Nodes.Operations;
RepositoryItemCheckEdit checkEdit;
private void Form1_Load(object sender, EventArgs e)
{
treeList1.OptionsView.ShowCheckBoxes = true;
treeList1.OptionsSelection.MultiSelect = true;
treeList1.OptionsView.ShowAutoFilterRow = true;
treeList1.DataSource = dt;
treeList1.OptionsView.AutoWidth = false;
treeList1.BestFitColumns();
treeviewCountYaz(treeList1);
checkEdit = (RepositoryItemCheckEdit)treeList1.RepositoryItems.Add("CheckEdit");}
public void treeviewCountYaz(TreeList tree)
{
if (tree.Nodes.Count > 0)
{
tree.OptionsView.ShowSummaryFooter = true;
TreeListColumn column = tree.Columns["rez_hotel"];
column.AllNodesSummary = true;
column.SummaryFooterStrFormat = "{0:n0}";
column.SummaryFooter = SummaryItemType.Count;
}
}
// COLUMN A CHECKEDİT EKLEME --> using DevExpress.XtraTreeList.ViewInfo;
RepositoryItemCheckEdit checkEdit;
protected void DrawCheckBox(Graphics g, RepositoryItemCheckEdit edit, Rectangle r, bool Checked)
{
try
{
DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo info;
DevExpress.XtraEditors.Drawing.CheckEditPainter painter;
DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs args;
info = edit.CreateViewInfo() as DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo;
painter = edit.CreatePainter() as DevExpress.XtraEditors.Drawing.CheckEditPainter;
info.EditValue = Checked; //
info.Bounds = r;
info.CalcViewInfo(g);
args = new DevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs(info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
painter.Draw(args);
args.Cache.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("DrawCheckBox Hatası:" + ex.Message);
}
}
private void treeList1_CustomDrawColumnHeader(object sender, CustomDrawColumnHeaderEventArgs e)
{
try
{
if (e.Column != null && e.Column.FieldName.Equals("rez_id"))
{
Rectangle checkRect = new Rectangle(e.Bounds.Left + 3, e.Bounds.Top + 3, 12, 12);
ColumnInfo info = (ColumnInfo)e.ObjectArgs;
if (info.CaptionRect.Left < 30)
info.CaptionRect = new Rectangle(new Point(info.CaptionRect.Left + 15, info.CaptionRect.Top), info.CaptionRect.Size);
e.Painter.DrawObject(info);
DrawCheckBox(e.Graphics, checkEdit, checkRect, IsAllSelected(sender as TreeList));
e.Handled = true;
}
}
catch (Exception ex)
{
MessageBox.Show("CustomDrawColumnHeader Hatası:" + ex.Message);
}
}
private bool IsAllSelected(TreeList tree)
{
//return tree.Selection.Count > 0 && tree.Selection.Count == tree.AllNodesCount;
return tree.GetAllCheckedNodes().Count > 0 && tree.GetAllCheckedNodes().Count== tree.AllNodesCount;
}
private void treeList1_MouseUp(object sender, MouseEventArgs e)
{
try
{
TreeList tree = sender as TreeList;
Point pt = new Point(e.X, e.Y);
TreeListHitInfo hit = tree.GetHitInfo(pt);
if (hit.Column != null)
{
ColumnInfo info = tree.ViewInfo.ColumnsInfo[hit.Column];
Rectangle checkRect = new Rectangle(info.Bounds.Left + 3, info.Bounds.Top + 3, 12, 12);
if (checkRect.Contains(pt))
{
if (IsAllSelected(tree))
{
List<TreeListNode> nodes = treeList1.GetNodeList();
foreach (TreeListNode node in nodes)
{
node.Checked = false;
}
tree.Selection.Clear();
}
else
{
SelectAll(tree);
}
//throw new DevExpress.Utils.HideException(); // ben yorum satırı yaptım
}
}
}
catch (Exception ex)
{
MessageBox.Show("MouseUp Hatası:" + ex.Message);
}
}
class SelectNodeOperation : TreeListOperation
{
public override void Execute(TreeListNode node)
{
// node.Selected = true;
node.Checked = true; // !node.Checked
}
}
private void SelectAll(TreeList tree)
{
tree.BeginUpdate();
tree.NodesIterator.DoOperation(new SelectNodeOperation());
tree.EndUpdate();
}
private void treeList1_SelectionChanged(object sender, EventArgs e)
{
treeList1.InvalidateColumnPanel();
}