none
Get table cell number before window_double_click event in Word VSTO C# RRS feed

  • Question

  • I'm working in word 2010 ribbon(Application level add-in).

    I'm using "Application_WindowBeforeDoubleClick" event to perform some functionality, now I need to get table cell number on which user has performed double click operation.

    Example if user click(double click) on table cell(2, 2), I need that cell number i.e. 2,2. 

    Thanks,

    Saurabh

    Tuesday, July 8, 2014 10:36 AM

Answers

  • Hi Saurabh

    I believe you're looking for:

    Selection.Cells(1).RowIndex / .ColumnIndex

    If you use this in an event, I'd structure it to first make sure Sel is actually IN a table before you query the above information. You should be able to do that using Sel.Tables.Count > 0 but you need to be careful because in newer versions of Word, when the cursor is just after the table .Count will return 1 rather than 0.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 8, 2014 6:59 PM
    Moderator

All replies

  • I'm working in word 2010 ribbon(Application level add-in).

    I'm using "Application_WindowBeforeDoubleClick" event to perform some functionality, now I need to get table cell number on which user has performed double click operation.

    Example if user click(double click) on table cell(2, 2), I need that cell number i.e. 2,2. 

    Thanks,

    Saurabh

    Tuesday, July 8, 2014 7:25 AM
  • Hello Saurabh,

    You can use the ActiveCell property of the Application or Window class. MSDN provides the following description:

    Returns a Range object that represents the active cell in the active window (the window on top) or in the specified window. If the window isn't displaying a worksheet, this property fails. 

    Then you can get the Row and Column property values.  

    Tuesday, July 8, 2014 7:37 AM
  • Hi Eugene,

    I don't able to use ActiveCell property in Word VSTO. I think this property is available for Excel, not for Word.

    Any equivalent of ActiveCell property for Word document??

    Tuesday, July 8, 2014 8:17 AM
  • Try using the Selection property of the Window or Application class in Word.
    Tuesday, July 8, 2014 9:39 AM
  • I'm able to get the table from the selection property but don't know how to get the cell number on which user double click.
    Tuesday, July 8, 2014 10:09 AM
  • For additional information.

    I'm able to get the table from the selection property but don't know how to get the cell number on which user double click.

    Tuesday, July 8, 2014 10:44 AM
  • Saurabh,

    Did you have a chance to check out the Selection.Tables property?

    Tuesday, July 8, 2014 10:55 AM
  • Saurabh,

    Did you have a chance to check out the Selection.Tables property?

    Please don't publish duplicate forum threads on the forums. I think Word for Developers is the right place for such questions. The question is not related to  VSTO at all. 

    Tuesday, July 8, 2014 10:56 AM
  • Yes, I'm using the below code:

    Table tbl=this.Application.Selection.Tables[1];

    Is there any property by which I can get the table cell number(like row and column number).

    I'm explaining my question again:

    There is a table in word document and I'm double clicking on 2nd row and 2nd column means cell(2,2) in the table, can be get this particular cell info(row no.=2 and column no.=2) from the selection property or not?

    Tuesday, July 8, 2014 11:22 AM
  • Hi Saurabh

    I believe you're looking for:

    Selection.Cells(1).RowIndex / .ColumnIndex

    If you use this in an event, I'd structure it to first make sure Sel is actually IN a table before you query the above information. You should be able to do that using Sel.Tables.Count > 0 but you need to be careful because in newer versions of Word, when the cursor is just after the table .Count will return 1 rather than 0.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, July 8, 2014 6:59 PM
    Moderator
  • Thank you very much Cindy

    This solves my problem.

    Thursday, July 10, 2014 5:51 AM