BUG: You Cannot Delete an Excel List Row from the CommandButton Click Event (823988)
The information in this article applies to:
- Microsoft Office Excel 2003
- Microsoft Visual Studio Tools for the Microsoft Office System version 2003
SYMPTOMSYou have built a managed code extension for Office Excel 2003. Your solution uses the Click event of an MSForms CommandButton control to remove rows from a List object that is located on a worksheet. When you click the button to remove the List row, the row is not removed, and you may receive a run-time error.STATUS
Microsoft has confirmed that this is a bug in Office Excel 2003.
RESOLUTIONTo resolve this problem, make sure that CommandButton does not have the focus when you delete the list row. Use one of the following methods: - Set the TakeFocusOnClick property of CommandButton to false.
-or- - Re-select the current worksheet selection to take the focus away from CommandButton.
WORKAROUNDTo work around this problem, use one of the following methods: - Set the TakeFocusOnClick property for the CommandButton control to false:
protected void ThisWorkbook_Open()
{
//Get a reference to the first worksheet.
ws = (Excel.Worksheet)(ThisWorkbook.Worksheets[1]);
//Set up the Click event handler for CommandButton1.
cb = (MSForms.CommandButton)(this.FindControl("CommandButton1"));
cb.Click+= new MSForms.CommandButtonEvents_ClickEventHandler(cbClick);
cb.TakeFocusOnClick = false;
}
-or- - Call the Select method for the current worksheet Selection to remove focus from the CommandButton:
private void cbClick()
{
ThisApplication.Selection.GetType().InvokeMember("Select",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.InvokeMethod |
System.Reflection.BindingFlags.Instance,
null,
ThisApplication.Selection,
null);
ws.ListObjects[1].ListRows[1].Delete();
}
Modification Type: | Minor | Last Reviewed: | 2/3/2006 |
---|
Keywords: | kbBug kbAutomation kbnofix KB823988 kbAudDeveloper |
---|
|