BizApps
BizApps

Reputation: 6130

How to Find toolstripButton inside toolstrip in a UserControl

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

enter image description here

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

Answers (3)

BizApps
BizApps

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

Tanveer-Ibn- Haresh
Tanveer-Ibn- Haresh

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

Micah Armantrout
Micah Armantrout

Reputation: 6971

Try a 0 instead of 1 your array is zero based

Upvotes: 0

Related Questions