This repository was archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
52 lines (44 loc) · 1.58 KB
/
Form1.cs
File metadata and controls
52 lines (44 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace TestGroupedComboBoxDatasource
{
public partial class Form1 : Form
{
private int itemCounter = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var loadedDataSource = new List<DummyItem>();
Enumerable.Range(1, 3).ToList().ForEach(i =>
{
itemCounter++;
loadedDataSource.Add(new DummyItem { ItemId = Guid.NewGuid(), ItemName = string.Concat("Item ", itemCounter.ToString()), GroupName = "Main Group" });
});
cboComboBox.DataSource = loadedDataSource;
}
private void btnChangeDataSource_Click(object sender, EventArgs e)
{
var changedDataSource = new List<DummyItem>();
Enumerable.Range(1, 3).ToList().ForEach(i =>
{
itemCounter++;
changedDataSource.Add(new DummyItem { ItemId = Guid.NewGuid(), ItemName = string.Concat("Item ", itemCounter.ToString()), GroupName = "Main Group" });
});
cboComboBox.DataSource = changedDataSource;
}
}
/// <summary>
/// DummyItem class represents the Dto I'm using in my main project
/// </summary>
internal class DummyItem
{
public Guid ItemId { get; set; }
public string ItemName { get; set; }
public string GroupName { get; set; }
}
}