- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
- [VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App
[DEVEXPRESS] Hướng dẫn thêm icon vào GridView trong Winform
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 thêm Icon vào Gridview trong lập trình Devexpress C# Winform.
[DEVEXPRESS] How to set Icon to Gridview C#
Ở bài demo này, mình sẽ có một dữ liệu table, gồm các ngôn ngữ lập trình: C#, PHP, Java, Python, Flutter...
Trong mỗi ngôn ngữ này, sẽ có một điểm Rating: Từ 0 => 10.
Vậy khi show dữ liệu lên GridView, mình muốn hiển thị thêm icon Star để nhìn cho trực quan.
Bài này mình chia ra 3 Rating:
- Từ 0 => 5
- Từ 5 => 7
- Từ 7 => 10
Tương ứng với từng khoảng điểm đánh giá Rating, mình sẽ cho hiển thị Icon tương ứng.
Dưới đây, là giao diện demo ứng dụng thêm Icon vào GridView Devexpress C#:
Full source code demo thêm icon gridview C#:
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
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 SetIconGridView
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
}
public DataTable InitData()
{
var table = new DataTable();
table.Columns.Add("id", typeof(int));
table.Columns.Add("language", typeof(string));
table.Columns.Add("author", typeof(string));
table.Columns.Add("rating", typeof(double));
table.Rows.Add(1, "C# Winform", "Microsoft", 9.5);
table.Rows.Add(2, "C# WPF", "Microsoft", 8.5);
table.Rows.Add(3, "ASP NET CORE", "Microsoft", 7);
table.Rows.Add(4, "Flutter", "Google", 6.5);
table.Rows.Add(5, "React Native", "Facebook", 7.3);
table.Rows.Add(6, "C++", "Bjarne Stroustrup", 2.5);
table.Rows.Add(7, "Python", "Guido van Rossum ", 4.6);
table.Rows.Add(8, "Java", "Sun System", 6.5);
table.Rows.Add(9, "Kotlin", "Jet Brain", 4.7);
table.Rows.Add(10, "Dart", "Google", 8.2);
table.Rows.Add(11, "PHP", "Rasmus Lerdorf", 7.1);
table.Rows.Add(12, "VB.NET", "Microsoft", 5.4);
return table;
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
var table = InitData();
gridControl1.DataSource = table;
GridFormatRule gridFormatRule = new GridFormatRule();
FormatConditionRuleIconSet formatConditionRuleIconSet = new FormatConditionRuleIconSet();
FormatConditionIconSet iconSet = formatConditionRuleIconSet.IconSet = new FormatConditionIconSet();
FormatConditionIconSetIcon icon1 = new FormatConditionIconSetIcon();
FormatConditionIconSetIcon icon2 = new FormatConditionIconSetIcon();
FormatConditionIconSetIcon icon3 = new FormatConditionIconSetIcon();
icon1.PredefinedName = "Stars3_1.png";
icon2.PredefinedName = "Stars3_2.png";
icon3.PredefinedName = "Stars3_3.png";
iconSet.ValueType = FormatConditionValueType.Number;
icon1.Value = 7; // target range: 7 <= value <= 10
icon1.ValueComparison = FormatConditionComparisonType.GreaterOrEqual;
icon2.Value = 5; // target range: 5 <= value <7
icon2.ValueComparison = FormatConditionComparisonType.GreaterOrEqual;
icon3.Value = 0; // target range: 5 < value
icon3.ValueComparison = FormatConditionComparisonType.GreaterOrEqual;
iconSet.Icons.Add(icon1);
iconSet.Icons.Add(icon2);
iconSet.Icons.Add(icon3);
gridFormatRule.Rule = formatConditionRuleIconSet;
gridFormatRule.Column = colRating;
gridView1.FormatRules.Add(gridFormatRule);
}
}
}
Thanks for watching!