|
@@ -70,6 +70,7 @@ namespace UICatalog.Scenarios {
|
|
miAlternatingColors = new MenuItem ("Alternating Colors", "", () => ToggleAlternatingColors()){CheckType = MenuItemCheckStyle.Checked},
|
|
miAlternatingColors = new MenuItem ("Alternating Colors", "", () => ToggleAlternatingColors()){CheckType = MenuItemCheckStyle.Checked},
|
|
miCursor = new MenuItem ("Invert Selected Cell First Character", "", () => ToggleInvertSelectedCellFirstCharacter()){Checked = tableView.Style.InvertSelectedCellFirstCharacter,CheckType = MenuItemCheckStyle.Checked},
|
|
miCursor = new MenuItem ("Invert Selected Cell First Character", "", () => ToggleInvertSelectedCellFirstCharacter()){Checked = tableView.Style.InvertSelectedCellFirstCharacter,CheckType = MenuItemCheckStyle.Checked},
|
|
new MenuItem ("_ClearColumnStyles", "", () => ClearColumnStyles()),
|
|
new MenuItem ("_ClearColumnStyles", "", () => ClearColumnStyles()),
|
|
|
|
+ new MenuItem ("Sho_w All Columns", "", ()=>ShowAllColumns())
|
|
}),
|
|
}),
|
|
new MenuBarItem ("_Column", new MenuItem [] {
|
|
new MenuBarItem ("_Column", new MenuItem [] {
|
|
new MenuItem ("_Set Max Width", "", SetMaxWidth),
|
|
new MenuItem ("_Set Max Width", "", SetMaxWidth),
|
|
@@ -137,45 +138,80 @@ namespace UICatalog.Scenarios {
|
|
tableView.ScreenToCell (e.MouseEvent.X, e.MouseEvent.Y, out DataColumn clickedCol);
|
|
tableView.ScreenToCell (e.MouseEvent.X, e.MouseEvent.Y, out DataColumn clickedCol);
|
|
|
|
|
|
if (clickedCol != null) {
|
|
if (clickedCol != null) {
|
|
|
|
+ if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) {
|
|
|
|
+
|
|
|
|
+ // left click in a header
|
|
|
|
+ SortColumn (clickedCol);
|
|
|
|
+ } else if (e.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked)) {
|
|
|
|
|
|
- // work out new sort order
|
|
|
|
- var sort = tableView.Table.DefaultView.Sort;
|
|
|
|
- bool isAsc;
|
|
|
|
-
|
|
|
|
- if(sort?.EndsWith("ASC") ?? false) {
|
|
|
|
- sort = $"{clickedCol.ColumnName} DESC";
|
|
|
|
- isAsc = false;
|
|
|
|
- } else {
|
|
|
|
- sort = $"{clickedCol.ColumnName} ASC";
|
|
|
|
- isAsc = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // set a sort order
|
|
|
|
- tableView.Table.DefaultView.Sort = sort;
|
|
|
|
-
|
|
|
|
- // copy the rows from the view
|
|
|
|
- var sortedCopy = tableView.Table.DefaultView.ToTable ();
|
|
|
|
- tableView.Table.Rows.Clear ();
|
|
|
|
- foreach(DataRow r in sortedCopy.Rows) {
|
|
|
|
- tableView.Table.ImportRow (r);
|
|
|
|
|
|
+ // right click in a header
|
|
|
|
+ ShowHeaderContextMenu (clickedCol, e);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void ShowAllColumns ()
|
|
|
|
+ {
|
|
|
|
+ foreach(var colStyle in tableView.Style.ColumnStyles) {
|
|
|
|
+ colStyle.Value.Visible = true;
|
|
|
|
+ }
|
|
|
|
+ tableView.Update ();
|
|
|
|
+ }
|
|
|
|
|
|
- foreach(DataColumn col in tableView.Table.Columns) {
|
|
|
|
|
|
+ private void SortColumn (DataColumn clickedCol)
|
|
|
|
+ {
|
|
|
|
+ // work out new sort order
|
|
|
|
+ var sort = tableView.Table.DefaultView.Sort;
|
|
|
|
+ bool isAsc;
|
|
|
|
|
|
- // remove any lingering sort indicator
|
|
|
|
- col.ColumnName = col.ColumnName.TrimEnd ('▼', '▲');
|
|
|
|
|
|
+ if (sort?.EndsWith ("ASC") ?? false) {
|
|
|
|
+ sort = $"{clickedCol.ColumnName} DESC";
|
|
|
|
+ isAsc = false;
|
|
|
|
+ } else {
|
|
|
|
+ sort = $"{clickedCol.ColumnName} ASC";
|
|
|
|
+ isAsc = true;
|
|
|
|
+ }
|
|
|
|
|
|
- // add a new one if this the one that is being sorted
|
|
|
|
- if (col == clickedCol) {
|
|
|
|
- col.ColumnName += isAsc ? '▲': '▼';
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // set a sort order
|
|
|
|
+ tableView.Table.DefaultView.Sort = sort;
|
|
|
|
|
|
- tableView.Update ();
|
|
|
|
|
|
+ // copy the rows from the view
|
|
|
|
+ var sortedCopy = tableView.Table.DefaultView.ToTable ();
|
|
|
|
+ tableView.Table.Rows.Clear ();
|
|
|
|
+ foreach (DataRow r in sortedCopy.Rows) {
|
|
|
|
+ tableView.Table.ImportRow (r);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach (DataColumn col in tableView.Table.Columns) {
|
|
|
|
+
|
|
|
|
+ // remove any lingering sort indicator
|
|
|
|
+ col.ColumnName = col.ColumnName.TrimEnd ('▼', '▲');
|
|
|
|
+
|
|
|
|
+ // add a new one if this the one that is being sorted
|
|
|
|
+ if (col == clickedCol) {
|
|
|
|
+ col.ColumnName += isAsc ? '▲' : '▼';
|
|
}
|
|
}
|
|
- };
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tableView.Update ();
|
|
|
|
+ }
|
|
|
|
+ private void ShowHeaderContextMenu (DataColumn clickedCol, View.MouseEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ var contextMenu = new ContextMenu (e.MouseEvent.X + 1, e.MouseEvent.Y + 1,
|
|
|
|
+ new MenuBarItem (new MenuItem [] {
|
|
|
|
+ new MenuItem ($"Hide '{clickedCol.ColumnName}'", "", () => HideColumn(clickedCol)),
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+ contextMenu.Show ();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void HideColumn (DataColumn clickedCol)
|
|
|
|
+ {
|
|
|
|
+ var style = tableView.Style.GetOrCreateColumnStyle (clickedCol);
|
|
|
|
+ style.Visible = false;
|
|
|
|
+ tableView.Update ();
|
|
|
|
+ }
|
|
|
|
|
|
private DataColumn GetColumn ()
|
|
private DataColumn GetColumn ()
|
|
{
|
|
{
|