Devexpress gridview Dinamik Satır Ekleme (sil butonuyla)

Bir tane devexpress gridview yarat ve kodlar aşağıda

 

 

 
using DevExpress.XtraEditors.Repository;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TIPEXE
{
    public partial class Form1 : Form
    {
        public class BILGILER
        {

            public BILGILER()
            {
            }

            public string BARKOD { get; set; }
            public string ADI { get; set; }
            public string SİL { get; set; }

        }
        public BindingList _Grid_data;
        public Form1()
        {
            InitializeComponent();

        }
        private void button3_Click(object sender, EventArgs e)
        {
            _Grid_data.Add(new BILGILER()
            {
                BARKOD = "asd",
                ADI = "assaas"
            });
            RepositoryItemButtonEdit SILDUGMESI = new RepositoryItemButtonEdit();
            SILDUGMESI.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
            SILDUGMESI.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
            SILDUGMESI.Buttons[0].Image = Bitmap.FromFile("resimler\\simgeler\\SIL.png");
            SILDUGMESI.Buttons[0].Caption = "SİL";
            SILDUGMESI.ButtonClick += SILDUGMESI_ButtonClick;
            gridControl1.RepositoryItems.Add(SILDUGMESI);
            gridView1.Columns["SİL"].ColumnEdit = SILDUGMESI;
        }
        private void SILDUGMESI_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            gridView1.DeleteSelectedRows();
        }
        private void bunifuFlatButton3_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _Grid_data = new BindingList();
            gridControl1.DataSource = _Grid_data;
            gridView1.PopulateColumns();
            //bunifuFlatButton4.BackColor = Color.Teal;
            //bunifuFlatButton4.Activecolor = Color.Teal;
        }
    }
}

Devexpress gridview export customised header

using DevExpress.XtraPrinting;
using DevExpress.Printing.ExportHelpers;
using DevExpress.Export;

private void simpleButton1_Click(object sender, EventArgs e) {
// Ensure that the data-aware export mode is enabled.
DevExpress.Export.ExportSettings.DefaultExportType = ExportType.DataAware;
// Create a new object defining how a document is exported to the XLSX format.
XlsxExportOptionsEx options = new XlsxExportOptionsEx();
// Subscribe to the CustomizeSheetHeader event.
options.CustomizeSheetHeader += options_CustomizeSheetHeader;
// Export the grid data to the XLSX format.
string file = "grid-export.xlsx";
gridControl.ExportToXlsx(file, options);
// Open the created document.
System.Diagnostics.Process.Start(file);
}

void options_CustomizeSheetHeader(DevExpress.Export.ContextEventArgs e) {
// Create a new row.
CellObject row = new CellObject();
// Specify row values.
row.Value = "The document is exported from the IssueList database.";
// Specify row formatting.
XlFormattingObject rowFormatting = new XlFormattingObject();
rowFormatting.Font = new XlCellFont { Bold = true, Size = 14 };
rowFormatting.Alignment = new DevExpress.Export.Xl.XlCellAlignment { HorizontalAlignment = DevExpress.Export.Xl.XlHorizontalAlignment.Center, VerticalAlignment = DevExpress.Export.Xl.XlVerticalAlignment.Top };
row.Formatting = rowFormatting;
// Add the created row to the output document.
e.ExportContext.AddRow(new [] {row});
// Add an empty row to the output document.
e.ExportContext.AddRow();
// Merge cells of two new rows.
e.ExportContext.MergeCells(new DevExpress.Export.Xl.XlCellRange(new DevExpress.Export.Xl.XlCellPosition(0, 0), new DevExpress.Export.Xl.XlCellPosition(5, 1)));
}

Devexpress grid databar

            GridFormatRule gridFormatRule = new GridFormatRule();
            FormatConditionRuleDataBar formatConditionRuleDataBar = new FormatConditionRuleDataBar();
            gridFormatRule.Column = gridView1.Columns[“Bakiye”];
            formatConditionRuleDataBar.PredefinedName = “Blue Gradient”;
            gridFormatRule.Rule = formatConditionRuleDataBar;
            this.gridView1.FormatRules.Add(gridFormatRule);

Devexpress gridview export to excel with savefiledialog

            string filename;
            saveFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.ShowDialog();
            filename = saveFileDialog1.FileName;
            if (filename == "") filename = "";
            else
            {
                gridView1.ExportToXlsx(filename);
                System.Diagnostics.Process.Start(filename);
            }

vs 2013 c# Devexpress gridview sağ tıklayarak excel dosyası olarak kaydet

Forma 1 adet contextMenuStrip1 ve 1 adet saveFileDialog1 at gridControl1de ki dataları excele kaydetmek için;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.OleDb;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;

contextMenuStrip1  tıkla Excele kaydet item yarat ve çift tıkla ve yaz;

            //excele kaydet
            string filename;
            saveFileDialog1.Filter = “xlsx files (*.xlsx)|*.xlsx”;
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.ShowDialog();
            filename = saveFileDialog1.FileName;
            if (filename == “”) filename = “”; else gridView1.ExportToXlsx(filename);

Daha sonra gridcontrola tıkla ve contextmenustripini contextMenuStrip1 olarak seç