Reputation: 6130
I used this code below to Enable/Disable Button Control inside my usercontol on my Form which works perfect.
var btnAdd = this.userControlCommonTask1.Controls.Find("btnAdd", true);
btnAdd[0].Enabled = true;
But when i use toostrip(toolstrip1) with buttons (btnAdd,btnEdit,btndelete etch..) and use my code above
I got:
Index was outside the bounds of the array.
I tried this one but it only works in toolstrip.
var btnAdd = this.userControlCommonTask1.Controls.Find("toolstrip1", true);
btnAdd[0].Enabled = true;
Thanks in Regards
Upvotes: 1
Views: 6556
Reputation: 6130
I already Solve my Problem:
var toolstrip1 = this.userControlCommonTask1.Controls.Find("toolstrip1", true);
var toolstrip1Items = toolstrip1[0] as ToolStrip; <-- set to toolstrip control
var btnRead = toolstrip1Items.Items.Find("btnRead", true); <--get BtnRead on toolstrip Item.Find
btnRead[0].Enabled = false; <--disable/Enable btn
This can be a reference for other Developers.
Cheers!
Upvotes: 3
Reputation: 300
Toolstrip is another usercontrol. Try make a reference to it and then find it's child controls
ie. ctlTooolStrip.Controls.Find("BtnAdd",true);
Also try toolStrip.Items
Upvotes: 0