INTRODUCTION AND RELEVANT INFORMATION:
Before I start, it is important to introduce example SQL table that will be used in this question to illustrate the problems I face:
Table < #ID autonumber, Planet varchar(20) >
SQL table populated with some records looks like below:
ID | Planet
1 | Mercury
2 | Venus
3 | Earth
Treeview is populated with following pattern:
- Parent node = column name
- Parent's children = distinct column values
For our example SQL table, treeview would look like
this[
^].
My goal is to use treeview to create dynamic SQL `SELECT` query.
For example:
- if user checks Mercury, my query would be something like
SELECT ID from Table where Planet = 'Mercury';
- if user checks multiple nodes, for example Mercury and Earth then my query would become
SELECT ID from Table where Planet IN ( 'Mercury', 'Earth' );
.
PROBLEM:
At first, I thought to simply traverse the tree when user presses "search" button, for example. Then I could determine which nodes are checked and include them in the query.
However, tree in the image above is simplified example. In my case, treeview might be much more complex.
Therefore I must create proper query
when node changes state (when it becomes checked or unchecked).
MY EFFORTS TO SOLVE THIS:
First, I have decided to substitute
SELECT ID from Table where Planet = 'Mercury';
with
SELECT ID from Table where Planet IN ('Mercury');
. This way I do not need to check whether only one node is clicked or multiple ones.
I have found
NM_TVSTATEIMAGECHANGING[
^] notification that might be very useful for my task ( I am willing to drop XP support if this message will solve problem in this question ).
Reading carefully its documentation, I have found important info in
Community Additions section that led me to examine
TVN_ITEMCHANGING[
^] notification code. This also seems useful, and again, I am willing to drop XP support if this solves my problem.
At the moment of writing this question I am experimenting with various approaches but they lead me nowhere. Therefore I will not include them in this post.
I have tried Googling for solution but have found nothing ( since this is quite creative solution for implementing search query, I did not know how to form proper Google search query, to be honest ).
QUESTION:
How can I form proper SQL query, in response to node changing its checked state?
If further explanations or info is required, leave a comment. I apologize if anything is unclear, English is not my native, and I am not that experienced with WinAPI either, so please take that into consideration when reading the question.