- [DEVEXPRESS] Đặt mật khẩu và bỏ mật khẩu tập tin file PDF
- [C#] Thêm ứng dụng vào Taskbar sử dụng SharpShell DeskBand
- [C#] Hướng dẫn thêm text vào hình ảnh icon winform
- [C#] Chia sẽ tổng hợp source code đồ án về Csharp
- [C#] Hướng dẫn viết ứng dụng quay màn hình video winform, Screen Recorder
- [C#] Hướng dẫn sử dụng thư viện Input Simulator để làm việc với Keyboard, Mouse Virtual
- [DEVEXPRESS] Hướng dẫn tích Filter Contain khi click chuột phải vào cell selection trên Gridview
- [C#] Tra cứu mã số thuế cá nhân bằng CMND hoặc CCCD
- [C#] Convert hình ảnh image thành Blurhash sử dụng trong loading image winform
- [POWERSHELL] Script sao lưu backup và nén database sqlserver
- [C#] Giới thiệu thư viện Autofac Dependency Injection
- [C#] Hướng dẫn tạo Windows Services đơn giản Winform
- [C#] Một click chuột điều khiển máy tính từ xa sử dụng Ultraviewer
- Hướng dẫn đóng gói phần mềm sử dụng Powershell biên dịch script thành file exe
- [C#] Hướng dẫn sử dụng Task Dialog trên NET 5
- [C#] Hướng dẫn xem lịch sử các trang web đã truy cập trên Chrome Browser
- [C#] Hướng dẫn lấy thông tin Your ID và Password của Ultraviewer Winform
- [C#] Hướng dẫn lấy thông tin Your ID và Password của Teamviewer Winform
- [C#] Hướng dẫn build code động xuất file exe trên Winform
- [C#] Điều khiển ứng dụng từ xa và rất xa với Telegram Bot Winform
[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!