SheetBeforeDoubleClick and merged cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear Reader

I succesfully implemented SheetBeforeDoubleClick (Excell application level)
using VSTO end VS 2005 (professional)
It works as long as cells ain't merged together.
when I double-click on single cells everything works as expected, however any
merged cell seems to destroy the event hookup, since after this even clicking
a single cell does not work anymore.
Thus presents I reckon a serious drawback in the layout-possibility of a
spreadsheet
with C#-implemented add-inns.

I'm currently at a loss to this issue, any idea's I welcome!
 
It could be that you code is not dealing with merged cells correctly and is
producing errors.

NickHK
 
.....
app.SheetBeforeDoubleClick += new
Microsoft.Office.Interop.Excel.AppEvents_SheetBeforeDoubleClickEventHandler(app_SheetBeforeDoubleClick);
.....
void app_SheetBeforeDoubleClick(object Sh,
Microsoft.Office.Interop.Excel.Range Target, ref bool Cancel)
{
MessageBox.Show("Hello")
}

Changed to the above to test your assumption!
and indeed you seem to be right since both single cell and merged cell yield
"hello"
so there must be something inside my eventhandler that disables it to
function!

Thanks, I'll need to study further. It is just that I see nothing in my code
that makes
use of the fact that cells aren't merged. So the deactivation is unexpected.
Will take some time to figure out what exactly deactivates the event

Thanks
 
You could record a macro i Excel of the actions on the merged cells to see
the required VBA. Then translate to C#.

NickHK
 
for some reason my responses before hasn't shown up so my final solution to
the incomprehensable Redmond-logic is:

object TargetValue(Microsoft.Office.Interop.Excel.Range Target)
{
bool merged = (bool) Target.MergeCells;

if (!merged)
return Target.get_Value(Excel.XlRangeValueDataType.xlRangeValueDefault);
else
try
{
object[,] arr =
(object[,])Target.get_Value(Excel.XlRangeValueDataType.xlRangeValueDefault);
// new object[Target.Rows.Count, Target.Columns.Count];
return arr[1,1]; // VSTO logic C# should be arr[0,0] !!!
}
catch (Exception ex)
{
MessageBox.Show("TargetValue HUMBUG \r\n" + ex.ToString());
}
return null;
}
 
Back
Top