[Solved] How to add right click menu on nodes in treeview?

Hi, 
I have read this article https://www.syncfusion.com/winforms-ui-controls/treeview, I have 3 questions as follows:
1. How to add right click menu on nodes?
2. When I enabletheme, the options button  cannot be changed color. Can i do that?
3. I want to replace minusplus by the triangle as in the image in that post but I don't know where to set it up?
thank you!

15 Replies

TG The GridLock April 24, 2020 11:14 AM UTC

I want to ask 2 more questions:
1. Can I uncheck all the check options after the form loads?
2. I use the aftercheck event to get the name of the node after checking a certain node, however I get 2 times including the previous node notification. I only need the node I chose (e.node.text) what should I do to disable the node earlier. Is there any event that meets this or not>
thank you!


TG The GridLock April 24, 2020 01:32 PM UTC

question 6:
After adding the databinding sqlserver database to treeviewadv, but now the database has some more tables, I want to refresh to update the database, I want to use the code instead of manually updating the database! what should I do?


TG The GridLock April 24, 2020 01:51 PM UTC

question 7:



I have a dataset after databinding (AuexpressdbDataset)
How do i get datatable from it? I got the correct table name, but it only shows the header from the table without any data


DV Duraimurugan Vedagiri Syncfusion Team April 24, 2020 03:41 PM UTC

Hi khanh,

Thanks for using syncfusion products.

Query  
Response 
How to add right click menu on nodes? 
You can achieve by using TreeViewAdv.ContextMenu property. Please refer the below code snippet and attached sample for you reference. 

this.treeViewAdv2.ContextMenu=this.contextMenu1;
 
When I Enable theme, the options button cannot be changed color. Can i do that? 
We have analyzed, but we are unable to reproduced. Please refer the below attached sample which works as expected. 
I want to replace minus plus by the triangle as in the image in that post, but I don't know where to set it up? 
The expander icon is varying to themes. If you want expander as Triangle, please apply the Office2016 theme and refer the below attached sample.  
Can I uncheck all the check options after the form loads? 
Yes, you can uncheck the checked TreeView item. Please refer the below code snippet. 
private void Form1_Load(object sender, EventArgs e) 
{ 
    for (int i = 0; i < this.treeViewAdv2.SelectedNodes.Count; i++) 
    { 
        //To uncheck the selected checkbox 
         this.treeViewAdv2.CheckedNodes.Remove(this.treeViewAdv2.SelectedNodes[i]); 
 
        this.treeViewAdv2.SelectedNodes.Remove(this.treeViewAdv2.SelectedNodes[i]); 
    } 
} 
what should I do to disable the node earlier? 
You can achieve to restrict the item checking by using e.Cancel = True in TreeViewAdv.BeforeCheck event handler.

 
private void TreeViewAdv2_BeforeCheck(object sender, TreeNodeAdvBeforeCheckEventArgs e) 
        { 
            String Text = e.Node.Text; 
            e.Cancel = true; 
        } 

Sample : https://www.syncfusion.com/downloads/support/directtrac/153598/ze/GettingStarted-547778981.zip

If we misunderstood your requirement, could you please brief your requirement, it would be helpful for us to provide the solution at earliest.

Regards,
Durai


DV Duraimurugan Vedagiri Syncfusion Team April 24, 2020 03:45 PM UTC

Hi khanh,

Please refer the sample from the following link for your reference.

Sample: https://www.syncfusion.com/downloads/support/forum/153598/ze/GettingStarted391285556.zip

Regards,
Durai


TG The GridLock April 24, 2020 06:20 PM UTC

Hi Durai!
Thanks for the sample file. Surely it will help me.


TG The GridLock April 25, 2020 06:51 AM UTC

Hi Durai, with question 1, 
I could not find contextmenu in the toolbox, I saw contextmenustrip, I had to add code manually based on the code you provided,
Is there any easier way by dragging and dropping context control into the form?


TG The GridLock April 25, 2020 09:15 AM UTC

Hi Durai, can you check for me the code for question 4:
it always check the first node!




DV Duraimurugan Vedagiri Syncfusion Team April 27, 2020 12:32 PM UTC

Hi khanh,

Thanks for your update.

Query  
Response 
Is there any easier way by dragging and dropping context control into the form? 
You can use syncfusion contextmenustrip control which has the same behavior of contextmenu control, and it has the support to adding through the designer. Please refer the below documentation for your reference.
https://help.syncfusion.com/windowsforms/contextmenustrip/getting-started 
It always checks the first node! 
You can restrict this by using TreeNodeAdv.EnsureDefaultOptionedChild bool property.
https://help.syncfusion.com/windowsforms/treeview/treenode-features

treeNodeAdv1.EnsureDefaultOptionedChild = false;
 
I want to refresh to update the database, I want to use the code instead of manually updating the database! what should I do? 
We have prepared the simple sample based on your requirement. Please refer the below location.

https://www.syncfusion.com/downloads/support/forum/153598/ze/SelectionModeDemo184886304.zip
 

Regards,
Durai


TG The GridLock April 27, 2020 12:41 PM UTC

Hi, 
Good news! I will try it.


DV Duraimurugan Vedagiri Syncfusion Team April 28, 2020 06:51 AM UTC

Hi khanh,

Thanks for your update. 

Query : I have a dataset after databinding (AuexpressdbDataset). How do i get datatable from it? I got the correct table name, but it only shows the header from the table without any data

Response :

If you enabled the database connection properly, you can get the Data for SfDataGrid Columns. Please refer the below document for this.

1. https://help.syncfusion.com/windowsforms/datagrid/databinding#loading-data-from-adonet  
2. https://help.syncfusion.com/windowsforms/datagrid/databinding#binding-to-xml-data  
3. https://help.syncfusion.com/windowsforms/datagrid/databinding#binding-data-from-microsoft-access  
4. https://help.syncfusion.com/windowsforms/datagrid/databinding#binding-to-ienumerable  

Please let us know if you need further assistance.

Regards,
Durai


TG The GridLock April 28, 2020 07:33 AM UTC

Hi Durai, 
after setting up the dataset, I have the .xsd file which will contain the names of the tables and the corresponding adapters, then I use this code. 
Dim ta As DataSetTableAdapters.table1TableAdapter = New DataSetTableAdapters.table1TableAdapter() 
ta.GetData () 
DataGrid1.DataSource = ta.GetData
This time it returns to the original problem, if there are some tables added I will need to update the dataset, so the problem is solved.


DV Duraimurugan Vedagiri Syncfusion Team April 29, 2020 07:55 AM UTC

Hi khanh,

Thanks for your update.

Please let us know which grid (GridGroupingControl, SfDataGrid, etc..) control you are using?

Based on that we will proceed further.

Regards,
Durai



TG The GridLock April 29, 2020 11:51 AM UTC

Hi Durai,
It is Treeviewadv, sfdatagrid.


SS Susmitha Sundar Syncfusion Team April 30, 2020 10:40 AM UTC

Hi GridLock, 
 
Thanks for the update. 
 
Please let us know if you need further assistance on this. We are happy to help you. 
 
Regards, 
Susmitha S 
 


Loader.
Up arrow icon