これは何のためにあるのでしょうか。
これはここからでもTreeNodeの名前を変更できるようにするためにあります。そのための機能を追加しましょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public partial class Form1 : Form { public Form1() { InitializeComponent(); textBox1.TextChanged += TextBox1_TextChanged; textBox2.TextChanged += TextBox2_TextChanged; group = new SyncGroup(imageList1); group.SetTreeView(syncTreeViewEx1); group.SetTreeView(syncTreeViewEx2); } } |
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 |
public partial class Form1 : Form { private void TextBox1_TextChanged(object sender, EventArgs e) { TreeNodeEx nodeEx = syncTreeViewEx1.SelectedNode; nodeEx.Text = textBox1.Text; } private void TextBox2_TextChanged(object sender, EventArgs e) { TreeNodeEx nodeEx = syncTreeViewEx2.SelectedNode; nodeEx.Text = textBox2.Text; } private void syncTreeViewEx1_AfterSelect(SyncTreeView sender, AfterSelectArgs e) { if (ignoreSelectedNodeChange) return; var node = syncTreeViewEx1.SelectedNode; if (node == null) return; textBox1.Text = node.Text; if(syncTreeViewEx1.SelectedNode == syncTreeViewEx2.SelectedNode) textBox2.Text = node.Text; // 以下省略 } private void syncTreeViewEx2_AfterSelect(SyncTreeView sender, AfterSelectArgs e) { if (ignoreSelectedNodeChange) return; var node = syncTreeViewEx2.SelectedNode; if (node == null) return; textBox2.Text = node.Text; if(syncTreeViewEx1.SelectedNode == syncTreeViewEx2.SelectedNode) textBox1.Text = node.Text; // 以下省略 } } |
これで完成♪ と言いたいところですが、そうではありません。TreeNodeのラベルをクリックして名前を変更したとき、TextBoxに反映されていません。TreeNodeのラベルが変更されたときのイベントを使えばなんとかなりそうです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public partial class Form1 : Form { public Form1() { InitializeComponent(); textBox1.TextChanged += TextBox1_TextChanged; textBox2.TextChanged += TextBox2_TextChanged; syncTreeViewEx1.AfterLabelEdit += SyncTreeViewEx1_AfterLabelEdit; syncTreeViewEx2.AfterLabelEdit += SyncTreeViewEx2_AfterLabelEdit; group = new SyncGroup(imageList1); group.SetTreeView(syncTreeViewEx1); group.SetTreeView(syncTreeViewEx2); } } |
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 |
public partial class Form1 : Form { private void SyncTreeViewEx1_AfterLabelEdit(SyncTreeView sender, NodeLabelEditEventArgs e) { if (e.Label == null) { e.CancelEdit = true; return; } textBox1.Text = e.Label; if(syncTreeViewEx1.SelectedNode == syncTreeViewEx2.SelectedNode) textBox2.Text = e.Label; } private void SyncTreeViewEx2_AfterLabelEdit(SyncTreeView sender, NodeLabelEditEventArgs e) { if (e.Label == null) { e.CancelEdit = true; return; } textBox2.Text = e.Label; if (syncTreeViewEx1.SelectedNode == syncTreeViewEx2.SelectedNode) textBox1.Text = e.Label; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public partial class Form1 : Form { private void TextBox1_TextChanged(object sender, EventArgs e) { TreeNodeEx nodeEx = syncTreeViewEx1.SelectedNode; nodeEx.Text = textBox1.Text; if (syncTreeViewEx1.SelectedNode == syncTreeViewEx2.SelectedNode) textBox2.Text = textBox1.Text; } private void TextBox2_TextChanged(object sender, EventArgs e) { TreeNodeEx nodeEx = syncTreeViewEx2.SelectedNode; nodeEx.Text = textBox2.Text; if (syncTreeViewEx1.SelectedNode == syncTreeViewEx2.SelectedNode) textBox1.Text = textBox2.Text; } } |
これで完成♪