N
NA_AB
hey friends, now that am able to create as many number of buttons and catch
their events accordingly on any cell location in the excel sheet, i am facing
a problem when am trying to delete these buttons.
in my code, i have these statements:
1) a 'search' button to search data and show it.
2) a 'delete' button to delete
(i) the data,
(ii) the search button and
(iii) the delete button itself finally...
and the statements to add buttons are:
Shape btn1 = sht.Shapes.AddOLEObject("Forms.CommandButton.1",
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
sht.get_Range(act, act).Left,
sht.get_Range(act, act).Top,
sht.get_Range(act, act).Width,
((double)sht.get_Range(act, act).
Height) * 2);
OLEObject o1 = (OLEObject)(sht.OLEObjects("CommandButton" + k));
MSForms.CommandButton mbtn_1 = (MSForms.CommandButton)(o1.Object);
mbtn_1.Caption = "search";
mbtn_1.Click += new
MSForms.CommandButtonEvents_ClickEventHandler(searchButton_Click);
and so on...
and to delete these, am saying:
o1.Delete(); //to delete 'search' button
o2.Delete(); //to delete 'delete' button
In the code, "k" is a static int which keeps incrementing with every button
added.
Now, when am trying to delete, it is deleting properly but again if am
trying to add a button, it is resulting in a weird behavour, the controls of
one button are going to another button, the reason for which i assume is the
statement:
OLEObject o1 = (OLEObject)(sht.OLEObjects("CommandButton" + k));
If am trying to change "CommandButton"+k to any other name, my button
doesn't even respond to anything.
What do I do about this? How will i be able to delete and add button as and
when required?
Thanks, in advance
Regards,
NA_AB
their events accordingly on any cell location in the excel sheet, i am facing
a problem when am trying to delete these buttons.
in my code, i have these statements:
1) a 'search' button to search data and show it.
2) a 'delete' button to delete
(i) the data,
(ii) the search button and
(iii) the delete button itself finally...
and the statements to add buttons are:
Shape btn1 = sht.Shapes.AddOLEObject("Forms.CommandButton.1",
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
sht.get_Range(act, act).Left,
sht.get_Range(act, act).Top,
sht.get_Range(act, act).Width,
((double)sht.get_Range(act, act).
Height) * 2);
OLEObject o1 = (OLEObject)(sht.OLEObjects("CommandButton" + k));
MSForms.CommandButton mbtn_1 = (MSForms.CommandButton)(o1.Object);
mbtn_1.Caption = "search";
mbtn_1.Click += new
MSForms.CommandButtonEvents_ClickEventHandler(searchButton_Click);
and so on...
and to delete these, am saying:
o1.Delete(); //to delete 'search' button
o2.Delete(); //to delete 'delete' button
In the code, "k" is a static int which keeps incrementing with every button
added.
Now, when am trying to delete, it is deleting properly but again if am
trying to add a button, it is resulting in a weird behavour, the controls of
one button are going to another button, the reason for which i assume is the
statement:
OLEObject o1 = (OLEObject)(sht.OLEObjects("CommandButton" + k));
If am trying to change "CommandButton"+k to any other name, my button
doesn't even respond to anything.
What do I do about this? How will i be able to delete and add button as and
when required?
Thanks, in advance
Regards,
NA_AB