- [C#] Viết ứng dụng xem và dò kết quả xổ số kiến thiết miền nam
- [EBOOK] Chia sẽ giáo trình học lập trình C - Giáo sư Phạm Văn Ất
- [C#] Hướng dẫn viết ứng dụng theo dõi máy in bao nhiêu trang (Monitor Printer)
- [C#] Lấy thông tin cấu hình máy tính xuất ra text file winform
- [C#] Chia sẽ class Install, Uninstall, Start và Stop Services Winform
- [C#] Tìm kiếm tập tin file nhanh chóng trên Winform sử dụng thư viện FastSearchLibrary
- [C#] Giới thiệu thư viện Fluent FTP Awesome dùng để làm việc với FTP
- [C#] Sử dụng thư viện Mini Profiler Integrations ghi log thực hiện các câu lệnh SQL
- [DEVEXPRESS] Thiết kế Dropdown ButtonBarItem trên Form Ribbon
- [C#] Lưu trạng thái các control trên Winform vào Registry Windows
- [C#] Ứng dụng ví dụ Simple Observer Pattern tăng giảm số lượng trên winform
- [C#] Hướng dẫn lấy thời gian thực server time trên winform
- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
[DEVEXPRESS] Hướng dẫn sử dụng chọn nhiều dòng trên GridLookupEdit C#
Xin chào các bạn, bài viết hôm nay mình sẻ tiếp tục hướng dẫn các bạn cách chọn nhiều dòng dữ liệu trên GridLookupEdit Devexpress C#.
[DEVEXPRESS] MultiSelection Gridlookupedit C#
Trên công cụ, Gridlookupedit bình thường các bạn chỉ có thể hiển thị được một dòng dữ liệu.
Còn các bạn muốn chọn nhiều dòng thì thường sử dụng công cụ: CheckedComboboxEdit
Từ phiên bản Devexpress 18.2.5 trở lên, devexpress đã cho phép tính năng chọn nhiều dòng trên trên Gridlookupedit.
Thường khi chúng ta sử dụng Gridlookupedit, để lấy giá trị chúng ta sử dụng ValueMember
, và hiển thị dữ liệu chúng ta sử dụng DisplayValue
.
Tuy nhiên, trong bài này mình sẽ bật tính năng cho phép chọn nhiều dòng dữ liệu trên GridView.
- Set EditValue = null
- Set NullText = với các giá trị chúng ta đã chọn
Hình ảnh demo ứng dụng chọn nhiều dòng với GridLookupEdit C#:
Full source code c#:
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.Windows.Forms;
namespace DXApplication2
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
DataTable data;
public Form1()
{
InitializeComponent();
data = new DataTable();
data.Columns.Add("id", typeof(string));
data.Columns.Add("name", typeof(string));
data.Columns.Add("address", typeof(string));
data.Rows.Add("MASV001", "Nguyễn Thảo", "Vũng Tàu");
data.Rows.Add("MASV002", "Nguyễn Đình Tuyên", "Quảng Bình");
data.Rows.Add("MASV003", "Nguyễn Phương Nhi", "Kiên Giang");
data.Rows.Add("MASV004", "Nguyễn Thị Cẩm Tú", "TP.HCM");
data.Rows.Add("MASV005", "Cái Trí Minh", "Đồng Nai");
data.Rows.Add("MASV006", "Võ Sơn Băng", "Vĩnh Long");
gridLookUpEdit1.Properties.DataSource = data;
gridLookUpEdit1.Properties.ValueMember = "id";
gridLookUpEdit1.Properties.DisplayMember = "name";
gridLookUpEdit1View.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CheckBoxRowSelect;
gridLookUpEdit1View.OptionsSelection.MultiSelect = true;
gridLookUpEdit1View.OptionsSelection.UseIndicatorForSelection = true;
gridLookUpEdit1View.OptionsBehavior.Editable = false;
gridLookUpEdit1.CloseUp += GridLookUpEdit1_CloseUp;
gridLookUpEdit1View.SelectionChanged += GridLookUpEdit1View_SelectionChanged;
gridLookUpEdit1.Properties.NullText = "";
}
private void GridLookUpEdit1View_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
{
GridView view = sender as GridView;
if (view != null)
view.GetSelectedRows();
}
int[] selectedRows;
private void GridLookUpEdit1_CloseUp(object sender, DevExpress.XtraEditors.Controls.CloseUpEventArgs e)
{
selectedRows = (((DevExpress.XtraEditors.GridLookUpEditBase)(sender)).Properties).View.GetSelectedRows();
var displayText = string.Join(", ",selectedRows.Select(x => gridLookUpEdit1View.GetDataRow(x)["name"].ToString()));
var result = string.Join(", ", selectedRows.Select(x => gridLookUpEdit1View.GetDataRow(x)["id"].ToString()));
gridLookUpEdit1.Properties.NullText = displayText;
gridLookUpEdit1.EditValue = null;
lbl_result.Text = "Items selected: " + result;
}
private void gridLookUpEdit1_Properties_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
{
selectedRows = (((DevExpress.XtraEditors.GridLookUpEditBase)(sender)).Properties).View.GetSelectedRows();
var displayText = string.Join(", ", selectedRows.Select(x => gridLookUpEdit1View.GetDataRow(x)["name"].ToString()));
e.DisplayText = displayText;
}
private void gridLookUpEdit1View_RowCellClick(object sender, RowCellClickEventArgs e)
{
GridView view = sender as GridView;
int i = view.FocusedRowHandle;
if (view.Columns.Contains( view.FocusedColumn))
{
if (view.IsRowSelected(i))
{
view.UnselectRow(i);
}
else
{
view.SelectRow(i);
}
}
}
}
}
Thanks for watching!