mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using Terminal.Gui;
|
|
using NStack;
|
|
|
|
namespace UICatalog.Scenarios {
|
|
[ScenarioMetadata (Name: "ListView & ComboBox", Description: "Demonstrates a ListView populating a ComboBox that acts as a filter.")]
|
|
[ScenarioCategory ("Controls")]
|
|
class ListsAndCombos : Scenario {
|
|
|
|
public override void Setup ()
|
|
{
|
|
List<string> items = new List<string> ();
|
|
foreach (var dir in new [] { "/etc", @"\windows\System32" }) {
|
|
if (Directory.Exists (dir)) {
|
|
items = Directory.GetFiles (dir).Union(Directory.GetDirectories(dir))
|
|
.Select (Path.GetFileName)
|
|
.Where (x => char.IsLetterOrDigit (x [0]))
|
|
.OrderBy (x => x).ToList ();
|
|
}
|
|
}
|
|
|
|
// ListView
|
|
var lbListView = new Label ("Listview") {
|
|
ColorScheme = Colors.TopLevel,
|
|
X = 0,
|
|
Width = 30
|
|
};
|
|
|
|
var listview = new ListView (items) {
|
|
X = 0,
|
|
Y = Pos.Bottom (lbListView) + 1,
|
|
Width = 30
|
|
};
|
|
listview.OpenSelectedItem += (object sender, ListViewItemEventArgs e) => lbListView.Text = items [listview.SelectedItem];
|
|
Win.Add (lbListView, listview);
|
|
|
|
// ComboBox
|
|
var lbComboBox = new Label ("ComboBox") {
|
|
ColorScheme = Colors.TopLevel,
|
|
X = Pos.Right (lbListView) + 1,
|
|
Width = 30
|
|
};
|
|
|
|
var comboBox = new ComboBox() {
|
|
X = Pos.Right(listview) + 1 ,
|
|
Y = Pos.Bottom (lbListView) +1,
|
|
Height = 10,
|
|
Width = 30
|
|
};
|
|
comboBox.SetSource (items);
|
|
|
|
comboBox.Changed += (object sender, ustring text) => lbComboBox.Text = text;
|
|
Win.Add (lbComboBox, comboBox);
|
|
}
|
|
}
|
|
}
|