Skip to content

Instantly share code, notes, and snippets.

@ruyut
Created June 15, 2021 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruyut/332b0cac9c9791aa06d97c3d11dd4048 to your computer and use it in GitHub Desktop.
Save ruyut/332b0cac9c9791aa06d97c3d11dd4048 to your computer and use it in GitHub Desktop.
建立自訂類別,供GridControl讀取用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RuyutDXApplication1
{
class Dto
{
private string _name;
private List<Item> items = new List<Item>();
private bool _select;
public string Name
{
get => _name;
set => _name = value;
}
public List<Item> Items
{
get => items;
set => items = value;
}
public bool Select
{
get => _select;
set => _select = value;
}
public class Item
{
private string _key;
private string _value;
public Item(string key, string value)
{
_key = key;
_value = value;
}
public string Key
{
get => _key;
set => _key = value;
}
public string Value
{
get => _value;
set => _value = value;
}
}
}
}
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 RuyutDXApplication1
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
List<Dto> dtoList = new List<Dto>();
public Form1()
{
InitializeComponent();
Dto dto = new Dto();
dto.Name = "testName1";
dto.Select = true;
dto.Items.Add(new Dto.Item("key1", "value1"));
dto.Items.Add(new Dto.Item("key2", "value2"));
dtoList.Add(dto);
gridControl1.DataSource = dtoList; //綁定資料
//更新資料
BindingSource bdSource = new BindingSource();
bdSource.DataSource = dtoList;
gridControl1.DataSource = bdSource;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment