NEWS

[DEVEXPRESS] Hướng dẫn sử dụng Unbound Column trên GridView C#

[DEVEXPRESS] Hướng dẫn sử dụng Unbound Column trên GridView C#
Đăng bởi: Thảo Meo - Lượt xem: 6387 08:49:47, 25/05/2020EBOOK

Xin chào các bạn bài viết hôm nay mình sẽ hướng dẫn các bạn cách sử dụng Unbound Column trên Gridview Devexpress C# winform.

[DEVEXPRESS] USING UNBOUND COLUMN GRIDVIEW C#

Ví dụ: các bạn theo dõi hình ảnh demo dưới đây.

unbound_column_gridview

Khi thiết lập đơn hàng hay xuất hàng, các bạn sẽ có 2 cột dữ liệu: QuantityPrice (số lương và đơn giá)

Còn thành tiền, thì mình sẽ không có lưu dưới cơ sở dữ liệu database.

Vậy khi hiển thị mình mong muốn hiển thị thêm cột Thành Tiền tự động được tính bằng Số lượng * Đơn giá.

Thì ở Column Total Money: các bạn không điền filedname, và setup Unbound column như hình dưới đây.

Do kiểu Total Money nên mình chọn là kiểu Decimal nhé.

unbound_devexpress

Hoặc bạn có thể chỉnh Unbound column runtime ở đây:

unbound_gridview

Full source code Unbound Column C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace unBoundColumn
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            var table = new DataTable();
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("Name", typeof(string));           
            table.Columns.Add("Quantity", typeof(decimal));
            table.Columns.Add("Price", typeof(decimal));

            table.Rows.Add(1, "Apple", 5, 12.5);
            table.Rows.Add(1, "Banana", 8, 5.25);
            table.Rows.Add(1, "Tomato", 3, 4.23);
            table.Rows.Add(1, "Oranges", 7, 15.28);
            table.Rows.Add(1, "Lemon", 15, 12.36);
            table.Rows.Add(1, "Water Lemon", 23, 9.63);
            table.Rows.Add(1, "Cherry", 9, 7.5);
            table.Rows.Add(1, "Coconuts", 18, 20.1);
            table.Rows.Add(1, "Kiwi", 2, 15.23);

            gridControl1.DataSource = table;
        }

        private void btn_expression_Click(object sender, EventArgs e)
        {
            gridView1.ShowUnboundExpressionEditor(colTotalMoney);
        }

        private void labelControl1_Click(object sender, EventArgs e)
        {

        }
    }
}

Happy coding :)

DOWNLOAD SOURCE

 

Tags: unbound column devexpressunbound gridview column c#

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[DEVEXPRESS] Hướng dẫn sử dụng Unbound Column trên GridView C#
Đăng bởi: Thảo Meo - Lượt xem: 6387 08:49:47, 25/05/2020EBOOK