Hello, I have a WinForm in Visual Studio C# that contains a TreeView and also a DataGridView.
I am testing with a file directory path as data and populating each with the DirectoryInfo Class, which allows me to get all directors and all files within a directory.
I am able to populate both accurately, each representing the content of the file path that I've indicated ( i.e. string path = "E:\\"; ), which is a USB drive containing Folders and Files.
My question is as follows.... I would like to be able to select (to click on) a TreeNode node and that would automatically select a Row in the DataGridView corresponding to that file in the path. I would also be great if I could do that in reverse. That being, select a Row in the DataGridView and have the TreeView highlight its corresponding node (or file).
In essence, what I am trying to do is LINK the two data container structures together.
Is there a way to do that...?
Would I have needed to first create an Array and dump the entire file path of "E:\" into that Array, and then populate each of my containers, those being the TreeView and the DataGridView?
Is there a practical way to do what I'm trying to do and if so, how should I approach this task? It would seem that there has to be a way, but I'm just not clear on how to approach this.
Thank you in advance for your help.
1). I had to move your the OnLoad event to the Form_Load event for the TreeView and DataGridView to populate. I was able to get that working, so that is not an issue any longer (I think).
2). The clicking (selecting) part did not work as it does for you. I would click on either the TreeView or the DataGridView and nothing changed. However, I then changed the _SelectionChanged event (for the DataGridView and the _NodeMouseClicked events (for the TreeView) and it worked perfectly.
I'm using Visual Studio 2019 C# WinForms, so it may be the version of VS that we're using. That said, you did a MASTERFUL job. THANK YOU!!!
Excellent work and very, very elegantly coded.