[XtraGrid] XtraGrid Option

.Net/XtraGrid 2013.01.24 09:32

링크 : http://blog.naver.com/hiphoptrain?Redirect=Log&logNo=130087380966 

저작자 표시 비영리 변경 금지
신고

'.Net > XtraGrid' 카테고리의 다른 글

[XtraGrid] XtraGrid Option  (0) 2013.01.24
[XtraGrid] Online Document  (0) 2012.04.13
[XtraGrid] Copy & Paste 구현  (0) 2012.04.11
[XtraGrid] How to make my grid columns read-only  (0) 2012.04.08
[XtraGrid] Checkbox 구현하기  (1) 2012.04.06
[XtraGrid] Fixed Columns  (0) 2012.04.05
posted by 뚱2

[XtraGrid] Online Document

.Net/XtraGrid 2012.04.13 17:04

링크 : http://documentation.devexpress.com/#WindowsForms/clsDevExpressXtraGridViewsGridGridViewtopic

저작자 표시 비영리 변경 금지
신고

'.Net > XtraGrid' 카테고리의 다른 글

[XtraGrid] XtraGrid Option  (0) 2013.01.24
[XtraGrid] Online Document  (0) 2012.04.13
[XtraGrid] Copy & Paste 구현  (0) 2012.04.11
[XtraGrid] How to make my grid columns read-only  (0) 2012.04.08
[XtraGrid] Checkbox 구현하기  (1) 2012.04.06
[XtraGrid] Fixed Columns  (0) 2012.04.05
posted by 뚱2

링크 : http://www.devexpress.com/Support/Center/p/A1266.aspx 

Copy 구현 : http://www.devexpress.com/Support/Center/p/A332.aspx

셀렉션 옵션 : http://documentation.devexpress.com/#WindowsForms/CustomDocument711  



using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;

using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.Utils.Drawing;


namespace KIS.DevExpressHelper
{
    public class GridLClipboardHelper
    {
        private const string CellDelimiter = "\t";
        private const string LineDelimiter = "\r\n";
        protected GridView _view;

        /// 생성자
        public GridLClipboardHelper(GridView view)
        {
            this.View = view;
        }
        public GridView View
        {
            get { return _view; }
            set
            {
                if ( _view != value )
                {
                    Detach();
                    Attach(value);
                }
            }
        }

        protected virtual void Attach(GridView view)
        {
            if ( view == null )
                return;
            this._view = view;

            if ( view.IsMultiSelect == false )
            {
                view.OptionsSelection.MultiSelect       = true;
                view.OptionsSelection.MultiSelectMode   = GridMultiSelectMode.RowSelect;
            }

            this.View.KeyDown       += new KeyEventHandler(View_KeyDown);
        }

        private bool CompareGrid(GridView srcView, GridView tgtView)
        {
            int srcCnt = srcView.Columns.Count;
            int tgtCnt = tgtView.Columns.Count;

            if ( srcView == null || tgtView == null )
            {
                return false;
            }

            if ( srcCnt != tgtCnt )
            {
                return false;
            }

            for ( int i = 0; i < srcCnt; i++ )
            {
                if ( srcView.Columns[i].ColumnType != tgtView.Columns[i].ColumnType 
                     || srcView.Columns[i].FieldName != tgtView.Columns[i].FieldName
                    )
                {
                    return false;
                }
            }

            return true;
        }

        void View_KeyDown(object sender, KeyEventArgs e)
        {
            GridView view = sender as GridView;

            // 붙여 넣기
            if ( this.CompareGrid(this._view, view) == true && view.IsMultiSelect == true && e.Control == true && e.KeyCode == Keys.V )
            {
                this.Paste(view);
            }
            // 복사하기
            else if ( this.CompareGrid(this._view, view) == true && view.IsMultiSelect == true && e.Control == true && e.KeyCode == Keys.C )
            {
                e.SuppressKeyPress = true;
                this.Copy(view);
            }
            // 모두 선택
            else if ( this.CompareGrid(this._view, view) == true && view.IsMultiSelect == true && e.Control == true && e.KeyCode == Keys.A )
            {
                this.SelectAll(view);
            }
            // 삭제
            else if ( this.CompareGrid(this._view, view) == true && view.IsMultiSelect == true &&  e.KeyCode == Keys.Delete )
            {
                this.DeleteRows(view);
            }
            // 오려내기
            else if ( this.CompareGrid(this._view, view) == true && view.IsMultiSelect == true && e.Control == true && e.KeyCode == Keys.X )
            {
                this.Copy(view);
                this.DeleteRows(view);
            }
        }

        /// 모두 선택
        public void SelectAll(GridView view)
        {
            view.SelectAll();
        }

        // 복사하기
        public void Copy(GridView view)
        {
            StringBuilder sb = new StringBuilder();
            int columnNameCnt = view.Columns.Count;
            for ( int i = 0; i < columnNameCnt; i++ )
            {
                try
                {
                    sb.Append(view.Columns[i].FieldName.ToString());
                }
                catch ( ArgumentException )
                {
                    sb.Append("");
                }

                if ( i+1 < columnNameCnt )
                    sb.Append(CellDelimiter);
            }
            sb.Append(LineDelimiter);


            int[] rows = view.GetSelectedRows();
            int rowsCnt = rows.Length;
            for ( int i = 0; i < rowsCnt; i++ )
            {
                int handle = rows[i];
                DataRowView rowView = view.GetRow(handle) as DataRowView;
                if ( rowView != null )
                {
                    for ( int j = 0; j < columnNameCnt; j++ )
                    {
                        try
                        {
                            sb.Append(rowView[view.Columns[j].FieldName].ToString());
                        }
                        catch ( ArgumentException )
                        {
                            sb.Append("");
                        }

                        if ( j+1 < columnNameCnt )
                            sb.Append(CellDelimiter);
                    }
                }
                if ( i+1 < rowsCnt )
                    sb.Append(LineDelimiter);
            }

            DataObject data = new DataObject();
            data.SetData(DataFormats.Text, sb.ToString());
            Clipboard.Clear();
            Clipboard.SetDataObject(data, true);
        }

        // 붙여넣기
        public void Paste(GridView view)
        {
            IDataObject data = Clipboard.GetDataObject();
            if ( data.GetDataPresent(DataFormats.Text) == true )
            {
                view.BeginUpdate();
                try
                {
                    string strData          = data.GetData(DataFormats.Text) as string;
                    string[] strRows        = strData.Split(new string[] { LineDelimiter }, StringSplitOptions.None);
                    string[] strColumnNames = strRows[0].Split(new string[] { CellDelimiter }, StringSplitOptions.None);

                    List< object > list = new List< object >();
                    int dataCount               = strRows.Length-1; // 헤더 개수 제외
                    int rowHandle               = view.FocusedRowHandle;
                    int targetDeleteRowCount    = view.DataRowCount - rowHandle + 1;

                    if ( rowHandle != GridControl.InvalidRowHandle && rowHandle != GridControl.NewItemRowHandle )
                    {
                        // 붙여 넣기할 Row가 현재 선택된 행부터 밑에 행보다 많다.
                        if ( targetDeleteRowCount > dataCount )
                        {
                            for ( int i = rowHandle + dataCount; i < view.DataRowCount; i++ )
                            {
                                list.Add(view.GetRow(i));
                            }
                        }

                        // 현재 선택된 행부터 끝까지 삭제한다.
                        for ( int i = view.DataRowCount-1; i >= rowHandle; i-- )
                        {
                            view.DeleteRow(i);
                        }
                    }
                    else if ( rowHandle == GridControl.NewItemRowHandle )
                    {
                        view.DeleteRow(rowHandle);
                    }

                    for ( int i = 1; i < strRows.Length; i++ )
                    {
                        view.AddNewRow();
                        int handle = view.FocusedRowHandle;

                        string[] strCells = strRows[i].Split(new string[] { CellDelimiter }, StringSplitOptions.None);
                        int colCnt = strColumnNames.Length;
                        for ( int j = 0; j < colCnt; j++ )
                        {
                            if ( strColumnNames[j].Trim().Equals("") == false && j < strCells.Length )
                            {
                                try
                                {
                                    Type t = view.Columns[j].ColumnType;
                                    object value = null;
                                    if ( t == typeof(int) )
                                    {
                                        if ( strCells[j] != null && strCells[j].ToString().Equals("") == false )
                                        {
                                            try
                                            {
                                                value = Convert.ToInt32(strCells[j]);
                                                if ( value != null )
                                                    view.SetRowCellValue(handle, strColumnNames[j], value);
                                            }
                                            catch ( Exception ex )
                                            {
                                                System.Console.WriteLine(ex.StackTrace);
                                            }
                                        }
                                    }
                                    else if ( t == typeof(DateTime) )
                                    {
                                        if ( strCells[j] != null && strCells[j].ToString().Equals("") == false )
                                        {
                                            try
                                            {
                                                value = Convert.ToDateTime(strCells[j]);
                                                if ( value != null )
                                                    view.SetRowCellValue(handle, strColumnNames[j], value);
                                            }
                                            catch ( Exception ex )
                                            {
                                                System.Console.WriteLine(ex.StackTrace);
                                            }
                                        }
                                    }
                                    else if ( t == typeof(string) )
                                    {
                                        if ( strCells[j] != null )
                                        {
                                            try
                                            {
                                                value = Convert.ToString(strCells[j]);
                                                if ( value != null )
                                                    view.SetRowCellValue(handle, strColumnNames[j], value);
                                            }
                                            catch ( Exception ex )
                                            {
                                                System.Console.WriteLine(ex.StackTrace);
                                            }
                                        }
                                    }
                                }
                                catch ( Exception ex)
                                {
                                    //MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
                                }
                            }//if ( strColumnNames[j].Trim().Equals("") == false )
                        }//for ( int j = 0; j < colCnt; j++ )
                    }//for ( int i = 1; i < strRows.Length; i++ )

                    DataView dv = view.DataSource as DataView;
                    for ( int i = 0; i < list.Count; i++ )
                    {
                        DataRowView drv = list[i] as DataRowView;
                        if ( drv != null )
                        {
                            DataRowView newDRV = dv.AddNew();
                            newDRV.BeginEdit();
                            try
                            {
                                int columNameCount= drv.Row.Table.Columns.Count;
                                for ( int j = 0; j < columNameCount; j++ )
                                {
                                    string fieldName = drv.Row.Table.Columns[j].ColumnName;
                                    newDRV[fieldName] = drv[fieldName];
                                }
                                newDRV.EndEdit();
                            }
                            catch ( Exception )
                            {
                                newDRV.CancelEdit();
                            }
                        }
                    }
                }
                catch ( Exception ex )
                {
                    MessageBox.Show(ex.StackTrace);
                }
                finally
                {
                    view.EndUpdate();
                }
            }//if ( data.GetDataPresent(DataFormats.Text) == true )
        }


        /// 현재 선택된 로우를 삭제한다.
        private void DeleteRows(GridView view)
        {
            view.BeginUpdate();
            int[] rows = view.GetSelectedRows();
            for ( int i = rows.Length-1; i >= 0 ; i-- )
            {
                view.DeleteRow(rows[i]);
            }
            view.EndUpdate();
        }

        protected virtual void Detach()
        {
            if ( this._view == null )
                return;

            this.View.KeyDown       -= new KeyEventHandler(View_KeyDown);
            _view = null;
        }
    }
}

저작자 표시 비영리 변경 금지
신고

'.Net > XtraGrid' 카테고리의 다른 글

[XtraGrid] XtraGrid Option  (0) 2013.01.24
[XtraGrid] Online Document  (0) 2012.04.13
[XtraGrid] Copy & Paste 구현  (0) 2012.04.11
[XtraGrid] How to make my grid columns read-only  (0) 2012.04.08
[XtraGrid] Checkbox 구현하기  (1) 2012.04.06
[XtraGrid] Fixed Columns  (0) 2012.04.05
posted by 뚱2

링크 : http://www.devexpress.com/Support/Center/KB/p/A281.aspx

저작자 표시 비영리 변경 금지
신고

'.Net > XtraGrid' 카테고리의 다른 글

[XtraGrid] Online Document  (0) 2012.04.13
[XtraGrid] Copy & Paste 구현  (0) 2012.04.11
[XtraGrid] How to make my grid columns read-only  (0) 2012.04.08
[XtraGrid] Checkbox 구현하기  (1) 2012.04.06
[XtraGrid] Fixed Columns  (0) 2012.04.05
[XtraGrid] DevExpress XtraGrid  (0) 2012.03.28
posted by 뚱2
사이트에 있는 예제를 약간 수정했다.
엑셀과 비슷하게 Shift + 클릭으로 범위를 클릭할수 있게 변경했다.
 
    public class GridCheckMarksMultiSelectionHelper
    {
        private readonly string             markFieldName = "CheckMarkSelection";
        protected GridView                  _view;
        protected ArrayList                 selection;
        protected GridColumn                column;
        protected RepositoryItemCheckEdit   edit;
        protected const int                 CheckboxIndent = 4;

        /// 
        /// 생성자
        /// 
        public GridCheckMarksMultiSelectionHelper()
        {
            selection = new ArrayList();
        }
        public GridCheckMarksMultiSelectionHelper(GridView view)
            : this()
        {
            this.View = view;
        }
        public GridView View
        {
            get { return _view; }
            set
            {
                if (_view != value)
                {
                    Detach();
                    Attach(value);
                }
            }
        }
        public string MarkFieldName
        {
            get
            {
                return this.markFieldName;
            }
        }

        private bool isMultiSelect = false;
        public bool IsMultiSelect
        {
            get
            {
                return this.isMultiSelect;
            }

            private set
            {
                this.isMultiSelect = value;
            }
        }


        public GridColumn CheckMarkColumn { get { return column; } }
        public int SelectedCount { get { return selection.Count; } }
        public object GetSelectedRow(int index)
        {
            return selection[index];
        }
        public int GetSelectedIndex(object row)
        {
            foreach (object record in selection)
                if ((record as DataRowView).Row == (row as DataRowView).Row)
                    return selection.IndexOf(record);
            return selection.IndexOf(row);
        }
        public void ClearSelection(GridView view)
        {
            selection.Clear();
            Invalidate(view);
        }
        public void SelectAll(GridView view)
        {
            selection.Clear();
            // fast (won't work if the grid is filtered)
            //if(_view.DataSource is ICollection)
            //	selection.AddRange(((ICollection)_view.DataSource));
            //else
            // slow:
            for (int i = 0; i < view.DataRowCount; i++)
                selection.Add(view.GetRow(i));
            Invalidate(view);
        }
        public void SelectGroup(int rowHandle, bool select, GridView view)
        {
            if (IsGroupRowSelected(rowHandle, view) && select) return;
            for (int i = 0; i < view.GetChildRowCount(rowHandle); i++)
            {
                int childRowHandle = view.GetChildRowHandle(rowHandle, i);
                if (view.IsGroupRow(childRowHandle))
                    SelectGroup(childRowHandle, select, view);
                else
                    SelectRow(childRowHandle, select, false, view);
            }
            Invalidate(view);
        }
        void SelectRow(int rowHandle, bool select, bool invalidate, GridView view)
        {
            if (IsRowSelected(rowHandle, view) == select) return;
            object row = view.GetRow(rowHandle);
            if (select)
                selection.Add(row);
            else
                selection.Remove(row);
            if (invalidate)
            {
                Invalidate(view);
            }
        }
        void SelectRow(object row, bool select, bool invalidate, GridView view)
        {
            if (IsRowSelected(row, view) == select) return;
            if (select)
                selection.Add(row);
            else
                selection.Remove(row);
            if (invalidate)
            {
                Invalidate(view);
            }
        }
        public void SelectRow(int rowHandle, bool select, GridView view)
        {
            SelectRow(rowHandle, select, true, view);
        }
        public void SelectRow(object row, bool select, GridView view)
        {
            SelectRow(row, select, true, view);
        }
        public void InvertRowSelection(int rowHandle, GridView view)
        {
            if (view.IsDataRow(rowHandle))
            {
                SelectRow(rowHandle, !IsRowSelected(rowHandle, view), view);
            }
            if (view.IsGroupRow(rowHandle))
            {
                SelectGroup(rowHandle, !IsGroupRowSelected(rowHandle, view), view);
            }
        }
        public bool IsGroupRowSelected(int rowHandle, GridView view)
        {
            for (int i = 0; i < view.GetChildRowCount(rowHandle); i++)
            {
                int row = _view.GetChildRowHandle(rowHandle, i);
                if (view.IsGroupRow(row))
                {
                    if (!IsGroupRowSelected(row, view)) return false;
                }
                else
                    if (!IsRowSelected(row, view)) return false;
            }
            return true;
        }
        public bool IsRowSelected(int rowHandle, GridView view)
        {
            if (view.IsGroupRow(rowHandle))
                return IsGroupRowSelected(rowHandle, view);

            object row = view.GetRow(rowHandle);

            return GetSelectedIndex(row) != -1;
        }
        public bool IsRowSelected(object row, GridView view)
        {
            return GetSelectedIndex(row) != -1;
        }
        protected virtual void Attach(GridView view)
        {
            if (view == null) return;
            selection.Clear();
            this._view = view;
            edit = view.GridControl.RepositoryItems.Add("CheckEdit") as RepositoryItemCheckEdit;
            column = view.Columns.Add();
            column.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
            column.Visible = true;
            column.VisibleIndex = 0;
            column.FieldName = this.MarkFieldName;
            column.Caption = "Mark";
            column.OptionsColumn.ShowCaption = false;
            column.OptionsColumn.AllowEdit = false;
            column.OptionsColumn.AllowSize = false;
            column.UnboundType = DevExpress.Data.UnboundColumnType.Boolean;
            column.Width = GetCheckBoxWidth();
            // 2012-04-05 ADDED BY KDJ
            column.Fixed = FixedStyle.Left;
            column.ColumnEdit = edit;

            view.Click                      += new EventHandler(View_Click);
            view.CustomDrawColumnHeader     += new ColumnHeaderCustomDrawEventHandler(View_CustomDrawColumnHeader);
            view.CustomDrawGroupRow         += new RowObjectCustomDrawEventHandler(View_CustomDrawGroupRow);
            view.CustomUnboundColumnData    += new CustomColumnDataEventHandler(view_CustomUnboundColumnData);
            view.KeyDown                    += new KeyEventHandler(view_KeyDown);
            view.RowStyle                   += new RowStyleEventHandler(view_RowStyle);

            // 2012-04-05 ADDED BY KDJ
            view.KeyUp                      += new KeyEventHandler(view_KeyUp);
            view.FocusedRowChanged          += new FocusedRowChangedEventHandler(view_FocusedRowChanged);
        }

        void view_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            this._view.BeginUpdate();
            
            // 클릭시 현재 Row 선택되게 하는 루틴
            //bool isSelection = this.IsRowSelected(row, view);
            //this.SelectRow(row, !isSelection, false, view);

            if (this.IsMultiSelect == true)
            {
                int start = 0, end = 0;

                if (e.PrevFocusedRowHandle <= e.FocusedRowHandle)
                {
                    start = e.PrevFocusedRowHandle;
                    end = e.FocusedRowHandle;
                }
                else
                {
                    start = e.FocusedRowHandle;
                    end = e.PrevFocusedRowHandle;
                }

                for (int i = start; i <= end; i++)
                {
                    this.SelectRow(i, true, false, this._view);
                }
                
            }

            this._view.EndUpdate();
        }

        public virtual void DetailViewAttach(GridView view)
        {
            if (view == null) return;
            this._view = view;
            _view.BeginUpdate();
            try
            {
                column = view.Columns[this.MarkFieldName];
                if (column == null)
                {
                    selection.Clear();
                    edit = view.GridControl.RepositoryItems.Add("CheckEdit") as RepositoryItemCheckEdit;
                    column = view.Columns.Add();
                    column.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
                    column.Visible = true;
                    column.VisibleIndex = 0;
                    column.FieldName = this.MarkFieldName;
                    column.Caption = "Mark";
                    column.OptionsColumn.ShowCaption = false;
                    column.OptionsColumn.AllowEdit = false;
                    column.OptionsColumn.AllowSize = false;
                    column.UnboundType = DevExpress.Data.UnboundColumnType.Boolean;
                    column.Width = GetCheckBoxWidth();
                    column.ColumnEdit = edit;
                }
                edit = view.Columns[this.MarkFieldName].ColumnEdit as RepositoryItemCheckEdit;//view.GridControl.RepositoryItems.Add("CheckEdit") as RepositoryItemCheckEdit;
                view.Click                      += new EventHandler(View_Click);
                view.CustomDrawColumnHeader     += new ColumnHeaderCustomDrawEventHandler(View_CustomDrawColumnHeader);
                view.CustomDrawGroupRow         += new RowObjectCustomDrawEventHandler(View_CustomDrawGroupRow);
                view.CustomUnboundColumnData    += new CustomColumnDataEventHandler(view_CustomUnboundColumnData);
                view.KeyDown                    += new KeyEventHandler(view_KeyDown);
                view.RowStyle                   += new RowStyleEventHandler(view_RowStyle);

                // 2012-04-05 ADDED BY KDJ
                view.KeyUp                      += new KeyEventHandler(view_KeyUp);
                view.FocusedRowChanged          += new FocusedRowChangedEventHandler(view_FocusedRowChanged);
            }
            finally
            {
                _view.EndUpdate();
            }
        }
        protected virtual void Detach()
        {
            if (_view == null) return;
            if (column != null)
                column.Dispose();
            if (edit != null)
            {
                _view.GridControl.RepositoryItems.Remove(edit);
                edit.Dispose();
            }

            _view.Click                     -= new EventHandler(View_Click);
            _view.CustomDrawColumnHeader    -= new ColumnHeaderCustomDrawEventHandler(View_CustomDrawColumnHeader);
            _view.CustomDrawGroupRow        -= new RowObjectCustomDrawEventHandler(View_CustomDrawGroupRow);
            _view.CustomUnboundColumnData   -= new CustomColumnDataEventHandler(view_CustomUnboundColumnData);
            _view.KeyDown                   -= new KeyEventHandler(view_KeyDown);
            _view.RowStyle                  -= new RowStyleEventHandler(view_RowStyle);

            // 2012-04-05 ADDED BY KDJ
            _view.KeyUp                     -= new KeyEventHandler(view_KeyUp);
            _view.FocusedRowChanged         -= new FocusedRowChangedEventHandler(view_FocusedRowChanged);

            _view = null;
        }
        public virtual void DetailViewDetach()
        {
            if (_view == null) return;

            _view.Click                     -= new EventHandler(View_Click);
            _view.CustomDrawColumnHeader    -= new ColumnHeaderCustomDrawEventHandler(View_CustomDrawColumnHeader);
            _view.CustomDrawGroupRow        -= new RowObjectCustomDrawEventHandler(View_CustomDrawGroupRow);
            _view.CustomUnboundColumnData   -= new CustomColumnDataEventHandler(view_CustomUnboundColumnData);
            _view.KeyDown                   -= new KeyEventHandler(view_KeyDown);
            _view.RowStyle                  -= new RowStyleEventHandler(view_RowStyle);

            // 2012-04-05 ADDED BY KDJ
            _view.KeyUp                     -= new KeyEventHandler(view_KeyUp);
            _view.FocusedRowChanged         -= new FocusedRowChangedEventHandler(view_FocusedRowChanged);

            _view = null;
        }
        protected int GetCheckBoxWidth()
        {
            DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo info = edit.CreateViewInfo() as DevExpress.XtraEditors.ViewInfo.CheckEditViewInfo;
            int width = 0;
            GraphicsInfo.Default.AddGraphics(null);
            try
            {
                width = info.CalcBestFit(GraphicsInfo.Default.Graphics).Width;
            }
            finally
            {
                GraphicsInfo.Default.ReleaseGraphics();
            }
            return width + CheckboxIndent * 2;
        }
        protected void DrawCheckBox(Graphics g, Rectangle r, bool Checked)
        {
            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();
        }
        void Invalidate(GridView view)
        {
            view.CloseEditor();
            view.BeginUpdate();
            view.EndUpdate();
        }
        void view_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
        {
            GridView view = sender as GridView;
            if (e.Column.Caption == "Mark")
            {
                if (e.IsGetData)
                    e.Value = /*IsRowSelected((view.DataSource as IList)[e.ListSourceRowIndex],view);*/  IsRowSelected(view.GetRowHandle(e.ListSourceRowIndex), view);
                else
                    SelectRow((view.DataSource as IList)[e.ListSourceRowIndex], (bool)e.Value, view);
            }
        }
        void view_KeyDown(object sender, KeyEventArgs e)
        {
            GridView view = sender as GridView;

            if (e.KeyCode == Keys.ShiftKey && this.isMultiSelect == false)
            {
                this.IsMultiSelect = true;
            }

            if (view.FocusedColumn.Caption != "Mark" || e.KeyCode != Keys.Space) return;
            InvertRowSelection(view.FocusedRowHandle, view);
        }

        void view_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.ShiftKey & this.isMultiSelect == true)
            {
                this.isMultiSelect = false;
            }
        }

        void View_Click(object sender, EventArgs e)
        {
            GridView view = sender as GridView;
            GridHitInfo info;
            Point pt = view.GridControl.PointToClient(Control.MousePosition);
            Point viewOffset = view.GetViewInfo().Bounds.Location;
            //pt.Offset(-viewOffset.X, -viewOffset.Y);
            info = view.CalcHitInfo(pt);
            if (info.Column != null && info.Column.Caption == "Mark")
            {
                if (info.InColumn)
                {
                    if (SelectedCount == view.DataRowCount)
                        ClearSelection(view);
                    else
                        SelectAll(view);
                }
                if (info.InRowCell)
                {
                    InvertRowSelection(info.RowHandle, view);
                }
            }
            if (info.InRow && view.IsGroupRow(info.RowHandle) && info.HitTest != GridHitTest.RowGroupButton)
            {
                InvertRowSelection(info.RowHandle, view);
            }
        }
        void View_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
        {

            if (e.Column != null && e.Column.Caption == "Mark")
            {
                GridView view = sender as GridView;
                e.Info.InnerElements.Clear();
                e.Painter.DrawObject(e.Info);
                DrawCheckBox(e.Graphics, e.Bounds, SelectedCount == view.DataRowCount);
                e.Handled = true;
            }
        }
        void View_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e)
        {
            GridView view = sender as GridView;
            DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo info;
            info = e.Info as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo;

            info.GroupText = "         " + info.GroupText.TrimStart();
            e.Info.Paint.FillRectangle(e.Graphics, e.Appearance.GetBackBrush(e.Cache), e.Bounds);
            e.Painter.DrawObject(e.Info);

            Rectangle r = info.ButtonBounds;
            r.Offset(r.Width + CheckboxIndent * 2 - 1, 0);
            DrawCheckBox(e.Graphics, r, IsGroupRowSelected(e.RowHandle, view));
            e.Handled = true;
        }
        void view_RowStyle(object sender, RowStyleEventArgs e)
        {
            GridView view = sender as GridView;
            if (IsRowSelected(e.RowHandle, view))
            {
                e.Appearance.BackColor = SystemColors.Highlight;
                e.Appearance.ForeColor = SystemColors.HighlightText;
            }
        }
    }


저작자 표시 비영리 변경 금지
신고

'.Net > XtraGrid' 카테고리의 다른 글

[XtraGrid] Online Document  (0) 2012.04.13
[XtraGrid] Copy & Paste 구현  (0) 2012.04.11
[XtraGrid] How to make my grid columns read-only  (0) 2012.04.08
[XtraGrid] Checkbox 구현하기  (1) 2012.04.06
[XtraGrid] Fixed Columns  (0) 2012.04.05
[XtraGrid] DevExpress XtraGrid  (0) 2012.03.28
posted by 뚱2

[XtraGrid] Fixed Columns

.Net/XtraGrid 2012.04.05 13:22

링크 : http://documentation.devexpress.com/#WindowsForms/CustomDocument651

저작자 표시 비영리 변경 금지
신고

'.Net > XtraGrid' 카테고리의 다른 글

[XtraGrid] Online Document  (0) 2012.04.13
[XtraGrid] Copy & Paste 구현  (0) 2012.04.11
[XtraGrid] How to make my grid columns read-only  (0) 2012.04.08
[XtraGrid] Checkbox 구현하기  (1) 2012.04.06
[XtraGrid] Fixed Columns  (0) 2012.04.05
[XtraGrid] DevExpress XtraGrid  (0) 2012.03.28
posted by 뚱2

* 옵션

링크 : http://blog.naver.com/hiphoptrain?Redirect=Log&logNo=130087380966 


* checkbox 구성 하는 방법

링크 : http://www.devexpress.com/Support/Center/KB/p/A371.aspx#E990

저작자 표시 비영리 변경 금지
신고

'.Net > XtraGrid' 카테고리의 다른 글

[XtraGrid] Online Document  (0) 2012.04.13
[XtraGrid] Copy & Paste 구현  (0) 2012.04.11
[XtraGrid] How to make my grid columns read-only  (0) 2012.04.08
[XtraGrid] Checkbox 구현하기  (1) 2012.04.06
[XtraGrid] Fixed Columns  (0) 2012.04.05
[XtraGrid] DevExpress XtraGrid  (0) 2012.03.28
posted by 뚱2