본문 바로가기

C#

C# 개발 Devexpress Grid 버튼 이벤트 추가 !

반응형

DevExpress.XtraGrid.Views.Grid;

 

using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Shown += Form1_Shown;
            this.simpleButton1.Click += simpleButton1_Click;
            this.simpleButton2.Click += simpleButton2_Click;
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            InitGridContorl();
            this.gridControl1.DataSource = GetData();
        }

        private void InitGridContorl()
        {
            GridView gv = this.gridControl1.MainView as GridView;
            gv.OptionsView.ShowGroupPanel = false;
            gv.OptionsBehavior.Editable = false;
        }
        public DataTable GetData()
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("Age");
            dataTable.Columns.Add("Grade");
            dataTable.Columns.Add("Score");

            dataTable.Rows.Add(new string[] { "이준호","28","1","60"});
            dataTable.Rows.Add(new string[] { "이가영", "25", "2", "70" });
            dataTable.Rows.Add(new string[] { "조진연", "15", "3", "80" });
            dataTable.Rows.Add(new string[] { "윤진", "88", "4", "100" });
            return dataTable;
            
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            gridView1.AddNewRow();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            gridView1.DeleteRow(gridView1.FocusedRowHandle);
        }
    }
}

반응형