- [C#] Dependency Injection in Winform
- [SQLSERVER] Hướng dẫn tìm kiếm nâng cao trên sql
- [C#] Hướng dẫn sử dụng SetTimeOut trên Winform like Javascript
- [DATABASE] In cây thông noel bằng sqlserver
- [C#] Hướng dẫn fix lỗi hiển thị UTF-8 khi sử dụng WebClient Download String
- [DATABASE] Hướng dẫn mã hóa và giải mã sử dụng thuật toán AES 256 trên sqlserver
- [DATABASE] Base64 Encode and Decode trong Sqlserver
- [C#] Vì Mẹ anh bắt phải Fake địa chỉ MacAddress
- [C#] Hướng dẫn xuất dữ liệu từ DataGridview ra file Excel
- [C#] Hướng dẫn khởi động lại chương trình ứng dụng winform
- [C#] Sự khác nhau giữa String.IsNullOrEmpty và String.IsNullOrWhiteSpace
- [C#] Hướng dẫn đọc file hình ảnh định dạng WEBP và chuyển đổi WebP sang JPG
- [C#] Kiểm tra phiên bản Microsoft Office đang sử dụng trên máy tính
- [C#] Hướng dẫn chuyển đổi tập tin hình ảnh XPS sang Bitmap
- [C#] Giới thiệu Component WebView2 của Microsoft
- [C#] Hướng dẫn lưu tất cả hình ảnh từ File Excel vào thư mục window
- [DATABASE] Hướng dẫn import và export hình ảnh image từ Sqlserver
- [DATABASE] Hướng dẫn sử dụng Hàm ASCII trong sqlserver
- [C#] Hướng dẫn fix lỗi Visual Studio 2022 not Support Target Net Framework 4.5.2
- [C#] Giới thiệu thư viện Sunny UI thiết kế giao diện trên Winform
[DEVEXPRESS] Hướng dẫn load Json DataSource vào GridView
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 load dữ liệu Json Datasource vào GridView trên Devexpress Winform C#.
[DEVEXPRESS] Load data from json datasource to Gridview C#
Dưới đây, là giao diện demo ứng dụng:
Ở bài viết, này các bạn có đọc dữ liệu json từ file hoặc request từ web API.
Full source code C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.DataAccess.Json;
namespace JsonBinddingGridView
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
// 1. Get json from file
var jsonDataSource = new JsonDataSource();
Uri fileUri = new Uri("data.json", UriKind.RelativeOrAbsolute);
jsonDataSource.JsonSource = new UriJsonSource(fileUri);
// 2. Get json from API Website
//var jsonDataSource = new JsonDataSource();
//jsonDataSource.JsonSource = new UriJsonSource(
// new Uri("https://raw.githubusercontent.com/dinhtona/api-mssql-dapper/main/db.json"));
jsonDataSource.Fill();
gridControl1.DataSource = jsonDataSource;
}
}
}
Ở đoạn code trên các bạn có thể bỏ comment số 2, để chạy test load từ web API nhé.
Thanks for watching!