Last active
April 18, 2017 21:09
-
-
Save cwensley/a5f72fe489f31cea190ab74a58de82b9 to your computer and use it in GitHub Desktop.
Shows how to use a DropDown control with per-item list of items.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Eto.Forms; | |
using Eto.Drawing; | |
namespace Eto.Test | |
{ | |
class MyItem | |
{ | |
public int SelectedItem { get; set; } | |
public ListItemCollection Items { get; set; } | |
} | |
public class TestCustomCellForm : Form | |
{ | |
public TestCustomCellForm() | |
{ | |
// create the custom cell | |
var cell = new CustomCell(); | |
cell.CreateCell = e => | |
{ | |
var dropDown = new DropDown(); | |
dropDown.BindDataContext(c => c.DataStore, (MyItem m) => m.Items); | |
dropDown.SelectedIndexBinding.BindDataContext((MyItem m) => m.SelectedItem); | |
return dropDown; | |
}; | |
cell.Paint += (sender, e) => | |
{ | |
// for GTK and WinForms | |
var item = e.Item as MyItem; | |
if (item != null) | |
{ | |
e.Graphics.DrawText(SystemFonts.Default(), SystemColors.ControlText, 0, 0, ""); | |
} | |
}; | |
// create the grid | |
var grid = new GridView { Size = new Size(300, 300) }; | |
grid.Columns.Add(new GridColumn { HeaderText = "Custom DropDown", Editable = true, DataCell = cell }); | |
// create some drop down item lists | |
var items1 = new ListItemCollection(new[] { | |
new ListItem { Text = "Item 1" }, | |
new ListItem { Text = "Item 2" } | |
}); | |
var items2 = new ListItemCollection(new[] { | |
new ListItem { Text = "Item 1" }, | |
new ListItem { Text = "Item 2" }, | |
new ListItem { Text = "Item 3" } | |
}); | |
// set the datastore of the grid | |
grid.DataStore = new List<MyItem>() | |
{ | |
new MyItem { SelectedItem = 0, Items = items1 }, | |
new MyItem { SelectedItem = 2, Items = items2 }, | |
new MyItem { SelectedItem = 1, Items = items1 } | |
}; | |
Content = grid; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment