- [DEVEXPRESS] Hỗ trợ tìm kiếm highlight không dấu và không khoảng cách trên Gridview Filter
- [C#] Chia sẻ source code phần mềm Image Downloader tải hàng loạt hình ảnh từ danh sách link url
- [C#] Chụp hình và quay video từ camera trên winform
- [C#] Chia sẽ full source code tách file Pdf thành nhiều file với các tùy chọn
- Giới thiệu về Stock Tracker Widget - Công cụ theo dõi cổ phiếu và cảnh báo giá tăng giảm bằng C# và WPF
- [VB.NET] Chia sẻ công cụ nhập số tiền tự động định dạng tiền tệ Việt Nam
- [VB.NET] Hướng dẫn fill dữ liệu từ winform vào Microsoft word
- [VB.NET] Hướng dẫn chọn nhiều dòng trên Datagridview
- Hướng Dẫn Đăng Nhập Nhiều Tài Khoản Zalo Trên Máy Tính Cực Kỳ Đơn Giản
- [C#] Chia sẻ source code phần mềm đếm số trang tập tin file PDF
- [C#] Cách Sử Dụng DeviceId trong C# Để Tạo Khóa Cho Ứng Dụng
- [SQLSERVER] Loại bỏ Restricted User trên database MSSQL
- [C#] Hướng dẫn tạo mã QRcode Style trên winform
- [C#] Hướng dẫn sử dụng temp mail service api trên winform
- [C#] Hướng dẫn tạo mã thanh toán VietQR Pay không sử dụng API trên winform
- [C#] Hướng Dẫn Tạo Windows Service Đơn Giản Bằng Topshelf
- [C#] Chia sẻ source code đọc dữ liệu từ Google Sheet trên winform
- [C#] Chia sẻ source code tạo mã QR MOMO đa năng Winform
- [C#] Chia sẻ source code phần mềm lên lịch tự động chạy ứng dụng Scheduler Task Winform
- [C#] Hướng dẫn download file từ Minio Server Winform
Change value on another combobox column in gridcontrol devexpress - Thay đổi giá trị của combobox trên gridcontrol sử dụng LookupEdit
Lời đầu tiên thay mặt các thành viên trên LaptrinhVB.Net, xin gửi đến các anh chị và các bạn lời chúc sức khỏe, thành đạt và ít bug trong năm mới. Cám ơn tất cả mọi người đã quan tâm đến trang trong thời gian qua. Chúc các anh chị trong nhóm nhiều may mắn, thành công, và nghiên cứu ra nhiều cái hay để chia sẻ cho mọi người. Thằng em xin phép khai bút ạ ! :)) $$$
Và hôm nay xin giớ thiệu với các bạn cách thay đổi giá trị combobox trong grid. Bài này do anh Sơn Băng nghiên cứu theo ý tưởng của anh Cái Trí Minh đưa ra. Mình thấy hay nên share ra cho mọi người.
Mình sẽ tạo ra 2 cái combobox trong cùng 1 lưới, khi thay đổi giá trị combo1 thì combo2 sẽ lọc ra những dữ liệu ít hơn theo điều kiện của combo1 đã chọn. Thực hiện thêm combobox vào lưới tương tự như thêm button, chỉ khác là mình sẽ chọn thêm LookupEdit thay vì ButtonEdit:
https://laptrinhvb.net/bai-viet/devexpress/Them-Button-vao-GridControl-DevExpress/66f02903edd2a656.html 

Thực hiện tương tự cho combobox thứ 2. Xong, tiến hành đổ dữ liệu cho combobox.
1. Database:
create database DEMOGRID
go
use DEMOGRID
go
create table tinhthanh(
	matinhthanh varchar(3),
	tentinhthanh nvarchar(50)
)
go
create table quanhuyen(
	maquanhuyen varchar(3),
	matinhthanh varchar(3),
	tenquanhuyen nvarchar(50)
)
go
create table nhanvien(
	manv varchar(5),
	hoten nvarchar(50),
	cmnd varchar(11),
	matinhthanh varchar(3),
	maquanhuyen varchar(3)
)
go
insert into tinhthanh(matinhthanh,tentinhthanh) values ('1', N'Quảng Bình')
insert into tinhthanh(matinhthanh,tentinhthanh) values ('2', N'Đồng Nai')
insert into tinhthanh(matinhthanh,tentinhthanh) values ('3', N'Lạng Sơn')
insert into tinhthanh(matinhthanh,tentinhthanh) values ('4',N'Vũng Tàu')
insert into tinhthanh(matinhthanh,tentinhthanh) values ('5', N'Tp. Hồ Chí Minh')
insert into tinhthanh(matinhthanh,tentinhthanh) values ('6', N'Quảng Trị')
go
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('1','LT',N'Lệ Thủy')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('1','DH',N'Đồng Hới')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('2','BH',N'Biên Hòa')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('2','DG',N'Dầu Giây')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('3','NB',N'Nõ biết')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('4','DS',N'Đông Sơn')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('4','BR',N'Bà Rịa')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('5','Q1',N'Quận Nhất')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('5','BT',N'Bình Thạnh')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('5','GV',N'Gò Vấp')
insert into quanhuyen(matinhthanh,maquanhuyen,tenquanhuyen) values ('6','GL',N'Gio Linh')
go
insert into nhanvien(manv,hoten,cmnd,matinhthanh,maquanhuyen) values ('NV01', N'NGUYỄN ĐÌNH TONA', '0123123654', '5', 'Q1')
insert into nhanvien(manv,hoten,cmnd,matinhthanh,maquanhuyen) values ('NV02', N'NGUYỄN THẢO', '9999999999', '4', 'DS')
insert into nhanvien(manv,hoten,cmnd,matinhthanh,maquanhuyen) values ('NV03', N'CÁI TRÍ MINH', '888888888', '2', 'DG')
insert into nhanvien(manv,hoten,cmnd,matinhthanh,maquanhuyen) values ('NV04', N'HOÀNG THỊ THẢO', '111111111', '3', 'NB')
go2. Tiến hành đổ dữ liệu vào lưới chứa combobox:
Lưu ý: Khi đổ dữ liệu vào lưới, cần đổ dữ liệu vào combobox trước. Lý do thì mọi người cứ làm thử sau sẽ rõ :D.
 
Public Sub open_connect() 
        Try
            strconnect.ConnectionString = "Data Source=tona	ona;Initial Catalog=DEMOGRID;Integrated Security=True"
            strconnect.Open()
        Catch ex As Exception
        End Try
    End Sub
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet
    Public Function _load_data(ByVal strLenh As String) As DataSet
        Dim ds As New DataSet
        open_connect()
        Dim cmd As New SqlDataAdapter(strLenh, strconnect)
        cmd.Fill(ds)
        strconnect.Close()
        Return ds
    End Function
    Public Sub load_cbo_quanhuyen() 'đẩy dữ lieu vào combo quận huyện
        Dim dt As New DataTable
        dt = _load_data("select maquanhuyen,matinhthanh,tenquanhuyen from quanhuyen").Tables(0)
        cbo_quanhuyen.DataSource = dt
        cbo_quanhuyen.DisplayMember = "tenquanhuyen"
        cbo_quanhuyen.ValueMember = "maquanhuyen"
    End Sub
    Public Sub load_cbo_tinhthanh() 'lấy dữ lieu vào combo tỉnh thành
        Dim ds As New DataTable
        ds = _load_data("select * from tinhthanh").Tables(0)
        cbo_tinhthanh.DataSource = ds
        cbo_tinhthanh.DisplayMember = "tentinhthanh"
        cbo_tinhthanh.ValueMember = "matinhthanh"
    End Sub
    Public Sub load_grid() ' đổ dữ lieu vào lưới
        Dim ds As New DataSet
        ds = _load_data("select * from nhanvien")
        GridControl1.DataSource = ds.Tables(0)
    End Sub
'load khi chạy form
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        load_cbo_quanhuyen()
        load_cbo_tinhthanh()
        load_grid()
    End SubLúc này combobox quận huyện sẽ bung ra mọi thứ có trong bảng quanhuyen, cái mình cần là khi mình chọn tỉnh thì cbo quận huyện sẽ hiển thị chỉ những huyện thuộc tỉnh đó thôi. Mình thực hiện việc này trong event ShownEditor của AdvBandedGridView1. Lưu ý là AdvBandedGridView1 chứ không phải là GridControl1 nha. thực hiện với các câu lệnh sau:
Dim view As GridView = CType(sender, GridView)
        If view.FocusedColumn.FieldName = "maquanhuyen" AndAlso TypeOf view.ActiveEditor Is LookUpEdit Then 'Điều kiện là cột cần Filter là Mã Lớp
            Dim edit As LookUpEdit
            Dim table As DataTable
            Dim row As DataRow
            Dim clone As DataView
            edit = CType(view.ActiveEditor, LookUpEdit) 'Lấy đối tượng hiện tại để lookup Mã lớp
            table = CType(edit.Properties.DataSource, DataTable) ' Lấy datasource của đối tượng
            clone = New DataView(table) 'Chuyển sang DataView để filter
            row = view.GetDataRow(view.FocusedRowHandle) ' Lấy giá trị của dòng dữ liệu hiện tại trên advBanded
            Dim str As String = row("matinhthanh").ToString()
            clone.RowFilter = "[matinhthanh] = '" + row("matinhthanh").ToString() + "'" 'Filter makhoa theo strmakho của dòng hiện tại
            edit.Properties.DataSource = clone ' Gán datasource đã được filter cho đối tượng LookupEdit của Mã lớp
        End IfFull 5% :D (Câu này chả liên quan, fan Origin sẽ biết :3). Xong. Nhấn F5 để xem thành quả.

Chúc các bạn thành công, nhớ cho LaptrinhVB.Net biết kết quả của mọi người nhé !



![[DEVEXPRESS] Chia sẻ source code cách tạo biểu đồ sơ đồ tổ chức công ty Org Chart trên Winform C#](https://laptrinhvb.net/uploads/source/devexpress/org_chart_devexpress.png)
![[DEVEXPRESS] Hướng dẫn sử dụng MagnifierDialog lấy mã màu C#](https://laptrinhvb.net/uploads/source/devexpress/MagnifierDialog_thumb.png)
![[DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform](https://laptrinhvb.net/uploads/source/devexpress/label_report_thumb.png)
![[DEVEXPRESS] Hướng dẫn tạo Text Avatar (Stub Image) thành Image trong C#](https://laptrinhvb.net/uploads/source/devexpress/stubImage_thumb.jpg)
![[DEVEXPRESS] Hướng dẫn thêm icon chênh lệch tăng giảm trên gridview](https://laptrinhvb.net/uploads/source/devexpress/Format_condition_thumb.png)
![[DEVEXPRESS] Hướng dẫn sử dụng Gallery Control để thiết kế phần mềm quản lý cafe](https://laptrinhvb.net/uploads/source/devexpress/gallery_control_devexress_thumb.jpg)
![[DEVEXPRESS] Hướng dẫn sử dụng thư viện NHunspell để kiểm tra chính tả tiếng việt trong TextBox Winform](https://laptrinhvb.net/uploads/source/devexpress/spelling_checker_csharp_thumb.png)
![[DEVEXPRESS] Hướng dẫn sử dụng thuộc tính Context Buttons trên PictureEdit C#](https://laptrinhvb.net/uploads/source/devexpress/context_buttons_devexpress_thumb.png)
![[DEVEXPRESS] Fixed column Middle Left C# winform](https://laptrinhvb.net/uploads/source/devexpress/fixMiddleleft.gif)
![[DEVEXPRESS] Tích hợp Pause/Resume vào download Progress Cell Gridview](https://laptrinhvb.net/uploads/source/devexpress/pause_resume_donwload_csharp_thumb.jpg)

![[DEVEXPRESS] Hướng dẫn thêm icon vào GridView trong Winform](https://laptrinhvb.net/uploads/source/devexpress/icon_gridview_devexpress_thumb.png)
![[DEVEXPRESS] Hướng dẫn xuất dữ liệu nhiều Gridview ra một file Excel winform](https://laptrinhvb.net/uploads/source/devexpress/excel_export_multigridview_csharp.jpg)
![[DEVEXPRESS] Hướng dẫn phóng lớn zoom image trong PictureEdit C#](https://laptrinhvb.net/uploads/source/devexpress/zoom_pictureedite_thumb.png)
![[DEVEXPRESS] Hướng dẫn Custom Summary in Footer trong Gridview C#](https://laptrinhvb.net/uploads/source/devexpress/custom_summary_thumb.png)
![[DEVEXPRESS] Hướng dẫn cách hiển thị hình ảnh Glyph trên SearchLookupEdit](https://laptrinhvb.net/uploads/source/devexpress/image_search_lookup_edit.jpg)
![[DEVEXPRESS] Hướng dẫn sử dụng HTML and CSS Code Viewer trên Winform](https://laptrinhvb.net/uploads/source/devexpress/code_editor_thumb.png)
![[DEVEXPRESS] Hướng dẫn sử dụng TreeList Control load tất cả button trên Ribbon Form Menu để phân quyền ứng dụng](https://laptrinhvb.net/uploads/source/devexpress/permission_app_csharp.png)

![[DEVEXPRESS] Hướng dẫn sử dụng công cụ WindowsUI Button Panel](https://laptrinhvb.net/uploads/source/image_baiviet/89beb6fa5e9dfb113ce299b8fc6f371a.jpg)
![[DEVEXPRESS] Hướng dẫn chọn nhiều dòng multi select trong GridLookupEdit](https://laptrinhvb.net/uploads/source/devexpress/MultiSelectGridComboxLookup_thumb.png)
![[DEVEXPRESS] Hướng dẫn sử dụng hộp thoại XtraSaveFileDialog, XtraOpenFileDialog và XtraFolderBrowserDialog](https://laptrinhvb.net/uploads/source/devexpress/xtra_dialog_devexpress_thumb.jpg)

![[DEVEXPRESS] Đặt mật khẩu và bỏ mật khẩu tập tin file PDF](https://laptrinhvb.net/uploads/source/devexpress/Encrypt-and-decrypt-PDF-using-CSharp.jpg)
![[DEVEXPRESS] Hướng dẫn custome popup filter date range trong Gridview](https://laptrinhvb.net/uploads/source/image_baiviet/e8e01ed200cdae93aef14d1140edca33.jpg)
