- [C#] Di chuyển và thay đổi kích thước Control Winform khi ứng dụng đang chạy
- [VB.NET] Chia sẻ source tạo sắp xếp đội hình bóng đá Line-ups đội bóng
- [C#] Hướng dẫn chỉnh sửa Text của label trực tiếp trên winform
- [C#] Hướng dẫn custom TextBox giống Ultraviewer trên Winform
- [C#] Show Modal Winform like Bootstrap
- [DATABASE] Thứ tự thực hiện mệnh đề truy vấn SELECT trong Sqlserver
- [C#] Hướng dẫn viết addin Excel Lấy hình ảnh từ URL internet vào Excel
- [DATABASE] TSQL view max length all column data trên table Sqlserver
- [DEVEXPRESS] Hướng dẫn sử dụng MailMerge kèm Hình ảnh trên Winform
- [DATABASE] Hướng dẫn truy vấn xem kích thước lưu trữ của từng bảng ghi Table trên sqlserver
- [C#] Hướng dẫn Fake Date Time sử dụng thư viện Harmony
- [DATABASE] Phân biệt câu lệnh DDL và DML trong sqlserver
- [C#] Hướng dẫn convert file mã HTML sang file Pdf trên winform
- [DEVEXPRESS] Tạo các loại mã vạch Barcode trực tiếp trên Devexpress Barcode API
- [DEVEXPRESS] Hướng dẫn custom Simple button thành Progressbar
- [DATABASE] Tách số và chữ từ chuỗi - hàm tối ưu hóa tách số và chữ trong Sqlserver
- [C#] Tìm kiếm gần đúng Full Text Search sử dụng thư viện Lucene.NET
- [C#] Chia sẻ tài liệu, sdk và source code máy chấm công dòng máy ZKTeco
- [C#] Memory Cache là gì, và sử dụng trong ứng dụng Winform
- [DATABASE] Khóa chính Primary Key trong Sqlserver
[DEVEXPRESS] Hướng dẫn show Form chọn dữ liệu từ Form2 trả về Form1 trên C#
Xin chào các bạn, bài viết hôm nay mình tiếp tục hướng dẫn các bạn, cách tạo Form2 như hộp thoại dialog chọn thông tin Employee và trả về kết quả cho Form1 trên lập trình C# Winform.
[DEVEXPRESS] Get muli select value from Form Show Dialog Devexpress
Chi tiết các bạn có thể xem video Demo mình ở bên dưới:
Ở hình trên các bạn thấy, khi mình click vào button chọn Employee ở Form1.
Hệ thống sẽ hiển thị dữ liệu từ Form2 lên, và chúng ta sẽ chọn dữ liệu Employee, và khi bấm nút OK thì kết quả chọn sẻ trả về cho Form1.
Source code Form1.cs:
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 DemoGetValueFormDialog
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
}
private void btnSelect_Click(object sender, EventArgs e)
{
var frm = new FrmSelectEmployee();
var dialogResult = frm.ShowDialog();
if (dialogResult == DialogResult.OK) {
var data = frm.listEmployeeSelectedReturn;
gridControl1.DataSource = data;
// show this to Gridview
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
const string cacheKey = "Employees";
var employees = FrmSelectEmployee.cache.Get(cacheKey) as List<Employee>;
var b = employees;
}
}
}
Source code Form2.cs
using DevExpress.XtraEditors;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DemoGetValueFormDialog
{
public partial class FrmSelectEmployee : DevExpress.XtraEditors.XtraForm
{
public List<Employee> listEmployeeSelectedReturn = new List<Employee>();
string URL_API = "https://raw.githubusercontent.com/dinhtona/api-mssql-dapper/main/db.json";
public FrmSelectEmployee()
{
InitializeComponent();
this.Load += FrmSelectEmployee_Load;
}
public static readonly MemoryCache cache = MemoryCache.Default;
public List<Employee> GetEmployees()
{
const string cacheKey = "Employees";
var employees = cache.Get(cacheKey) as List<Employee>;
if (employees == null)
{
employees = GetEmployeesFromAPI();
cache.Add(cacheKey, employees, DateTimeOffset.Now.AddMinutes(30));
}
return employees;
}
public List<Employee> GetEmployeesFromAPI() {
var dataEmployees = new WebClient().DownloadString(URL_API);
var listEmployee = JsonConvert.DeserializeObject<List<Employee>>(dataEmployees);
return listEmployee;
}
private void FrmSelectEmployee_Load(object sender, EventArgs e)
{
gridControl1.DataSource = GetEmployees();
}
private void btnOK_Click(object sender, EventArgs e)
{
var employeeSelected = gridView1.GetSelectedRows(); // this return rowHandle
if (employeeSelected.Length == 0) {
XtraMessageBox.Show("Please select an Employee.", "Message");
return;
}
// get list employee
foreach (var rowHandle in employeeSelected)
{
var employee = gridView1.GetRow(rowHandle) as Employee;
listEmployeeSelectedReturn.Add(employee);
}
DialogResult= DialogResult.OK; // return OK
this.Close();
}
private void btnClose_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
this.Close();
}
}
}
Thanks for watching!