Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions samples/ControlGallery/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public MainForm ()
tree.Items.Add ("Button", ImageLoader.Get ("button.png"));
tree.Items.Add ("CheckBox", ImageLoader.Get ("button.png"));
tree.Items.Add ("ComboBox", ImageLoader.Get ("button.png"));
tree.Items.Add ("DataGridView", ImageLoader.Get ("button.png"));
tree.Items.Add ("Dialogs", ImageLoader.Get ("button.png"));
tree.Items.Add ("FileDialogs", ImageLoader.Get ("button.png"));
tree.Items.Add ("FlowLayoutPanel", ImageLoader.Get ("button.png"));
Expand Down Expand Up @@ -90,6 +91,8 @@ private void Tree_ItemSelected (object? sender, EventArgs<TreeViewItem> e)
return new CheckBoxPanel ();
case "ComboBox":
return new ComboBoxPanel ();
case "DataGridView":
return new DataGridViewPanel ();
case "Dialogs":
return new DialogPanel ();
case "FileDialogs":
Expand Down
92 changes: 92 additions & 0 deletions samples/ControlGallery/Panels/DataGridViewPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Modern.Forms;
using SkiaSharp;

namespace ControlGallery.Panels
{
public class DataGridViewPanel : BasePanel
{
public DataGridViewPanel ()
{
Controls.Add (new Label { Text = "DataGridView - Cell Selection with Row Headers (Tab/Shift-Tab to navigate, double-click or F2 to edit)", Left = 10, Top = 10, Width = 760 });

var dgv1 = new DataGridView {
Left = 10,
Top = 30,
Width = 750,
Height = 250,
SelectionMode = DataGridViewSelectionMode.CellSelect,
ColumnHeadersHeight = 36,
RowHeadersVisible = true,
RowHeadersWidth = 30
};

// Customize column header style
dgv1.ColumnHeadersDefaultCellStyle.BackgroundColor = Theme.AccentColor;
dgv1.ColumnHeadersDefaultCellStyle.ForegroundColor = SKColors.White;

// Customize alternating row style
dgv1.AlternatingRowsDefaultCellStyle.BackgroundColor = new SKColor (150, 200, 225);

dgv1.Columns.Add ("Name", 150);
dgv1.Columns.Add ("Age", 60);
dgv1.Columns.Add ("City", 120);
dgv1.Columns.Add ("Occupation", 150);
dgv1.Columns.Add ("Email", 200);

dgv1.Rows.Add ("Alice Johnson", "32", "New York", "Engineer", "alice@example.com");
dgv1.Rows.Add ("Bob Smith", "45", "Los Angeles", "Designer", "bob@example.com");
dgv1.Rows.Add ("Carol Williams", "28", "Chicago", "Teacher", "carol@example.com");
dgv1.Rows.Add ("David Brown", "51", "Houston", "Doctor", "david@example.com");
dgv1.Rows.Add ("Eve Davis", "39", "Phoenix", "Lawyer", "eve@example.com");
dgv1.Rows.Add ("Frank Miller", "22", "Philadelphia", "Student", "frank@example.com");
dgv1.Rows.Add ("Grace Wilson", "36", "San Antonio", "Architect", "grace@example.com");
dgv1.Rows.Add ("Henry Moore", "48", "San Diego", "Manager", "henry@example.com");
dgv1.Rows.Add ("Ivy Taylor", "31", "Dallas", "Analyst", "ivy@example.com");
dgv1.Rows.Add ("Jack Anderson", "55", "San Jose", "Director", "jack@example.com");
dgv1.Rows.Add ("Karen Thomas", "42", "Austin", "Consultant", "karen@example.com");
dgv1.Rows.Add ("Leo Jackson", "27", "Jacksonville", "Developer", "leo@example.com");
dgv1.Rows.Add ("Mia White", "34", "Fort Worth", "Scientist", "mia@example.com");
dgv1.Rows.Add ("Noah Harris", "60", "Columbus", "Professor", "noah@example.com");
dgv1.Rows.Add ("Olivia Martin", "25", "Charlotte", "Intern", "olivia@example.com");

dgv1.SelectedRowIndex = 2;
dgv1.SelectedColumnIndex = 0;

Controls.Add (dgv1);

Controls.Add (new Label { Text = "DataGridView - Full Row Selection + Data Binding (column resizing disabled)", Left = 10, Top = 300, Width = 500 });

var dgv3 = new DataGridView {
Left = 10,
Top = 320,
Width = 500,
Height = 200,
SelectionMode = DataGridViewSelectionMode.FullRowSelect,
AllowUserToResizeColumns = false
};

var products = new List<Product> {
new Product { Name = "Widget", Price = 9.99, Quantity = 100, Category = "Hardware" },
new Product { Name = "Gadget", Price = 24.95, Quantity = 50, Category = "Electronics" },
new Product { Name = "Doohickey", Price = 4.50, Quantity = 200, Category = "Hardware" },
new Product { Name = "Thingamajig", Price = 15.00, Quantity = 75, Category = "Electronics" },
new Product { Name = "Whatchamacallit", Price = 7.25, Quantity = 150, Category = "Misc" },
new Product { Name = "Contraption", Price = 49.99, Quantity = 10, Category = "Electronics" },
new Product { Name = "Gizmo", Price = 12.50, Quantity = 80, Category = "Hardware" },
new Product { Name = "Doodad", Price = 3.75, Quantity = 300, Category = "Misc" }
};

dgv3.DataSource = products;

Controls.Add (dgv3);
}

private sealed class Product
{
public string Name { get; set; } = string.Empty;
public double Price { get; set; }
public int Quantity { get; set; }
public string Category { get; set; } = string.Empty;
}
}
}
9 changes: 9 additions & 0 deletions src/Modern.Forms/Control.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class Control
private static readonly object s_doubleClickEvent = new object ();
private static readonly object s_enabledChangedEvent = new object ();
private static readonly object s_gotFocusEvent = new object ();
private static readonly object s_lostFocusEvent = new object ();
private static readonly object s_invalidatedEvent = new object ();
private static readonly object s_keyDownEvent = new object ();
private static readonly object s_keyPressEvent = new object ();
Expand Down Expand Up @@ -130,6 +131,14 @@ public event EventHandler<EventArgs<Rectangle>>? Invalidated {
remove => Events.RemoveHandler (s_invalidatedEvent, value);
}

/// <summary>
/// Raised when the control loses focus.
/// </summary>
public event EventHandler? LostFocus {
add => Events.AddHandler (s_lostFocusEvent, value);
remove => Events.RemoveHandler (s_lostFocusEvent, value);
}

/// <summary>
/// Raised when the user presses down a key.
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion src/Modern.Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,10 @@ protected virtual void OnCreateControl ()
/// <summary>
/// Called when the control is deselected.
/// </summary>
protected virtual void OnDeselected (EventArgs e) { }
protected virtual void OnDeselected (EventArgs e)
{
OnLostFocus (e);
}

/// <summary>
/// Raises the DoubleClick event.
Expand Down Expand Up @@ -1023,6 +1026,11 @@ protected virtual void OnEnabledChanged (EventArgs e)
/// </summary>
protected virtual void OnInvalidated (EventArgs<Rectangle> e) => (Events[s_invalidatedEvent] as EventHandler<EventArgs<Rectangle>>)?.Invoke (this, e);

/// <summary>
/// Raises the LostFocus event.
/// </summary>
protected virtual void OnLostFocus (EventArgs e) => (Events[s_lostFocusEvent] as EventHandler)?.Invoke (this, e);

/// <summary>
/// Raises the KeyDown event.
/// </summary>
Expand Down
Loading
Loading