How to detect which row is selected?

  • Thread starter Thread starter JsJ_Slim
  • Start date Start date
J

JsJ_Slim

Hi,

I'm trying to detect if a user selected a cell within a powerpoint table
shape, as well as find out which row and column the cell belongs to.
Basically, I'm trying to do the equivalent of the following Word code:

***Code Snippet***

Cell selectedCell = Application.Selection.Cells[1];
int rowIndex = selectedCell.Row.Index;
int colIndex = selectedCell.Column.Index;

******

Please help.

Thanks.

Josh

p.s.

sorry for the trail of posts in the forums and newsgroup. apparently,
"Powerpoint" and "Project" looks the same to me, especially early in the
morning.
 
By the way,

I'm coding for Powerpoint 2007. And I believe I read somewhere in the
newsgroup that TextRange.Parent.Parent will not work (and I can confirm this
too) because the Object Model for 2007 keeps returning null.

Please help.

Thanks
 
Tables in 2007 are pretty much broken from the object model perspective. You
can check if a cell is selected, that works. However extracting text from
the selected cell is another matter.
?ActiveWindow.Selection.ShapeRange.Table.Cell(1,1).Selected

Regards,
Shyam Pillai

Image Importer Wizard
http://skp.mvps.org/iiw.htm


JsJ_Slim said:
By the way,

I'm coding for Powerpoint 2007. And I believe I read somewhere in the
newsgroup that TextRange.Parent.Parent will not work (and I can confirm
this
too) because the Object Model for 2007 keeps returning null.

Please help.

Thanks

JsJ_Slim said:
Hi,

I'm trying to detect if a user selected a cell within a powerpoint table
shape, as well as find out which row and column the cell belongs to.
Basically, I'm trying to do the equivalent of the following Word code:

***Code Snippet***

Cell selectedCell = Application.Selection.Cells[1];
int rowIndex = selectedCell.Row.Index;
int colIndex = selectedCell.Column.Index;

******

Please help.

Thanks.

Josh

p.s.

sorry for the trail of posts in the forums and newsgroup. apparently,
"Powerpoint" and "Project" looks the same to me, especially early in the
morning.
 
Thanks!

Got it working now. Thanks!!

int selectedRow = -1;
int selectedCol = -1;
Row selection = null;

if (shape.HasTable == MsoTriState.msoTrue)
{
Table table = shape.Table;
int rowIndex = 0; // Keep track of current row

foreach (Row row in table.Rows)
{
int colIndex = 0; // Keep track of current column
foreach (Cell cell in row.Cells)
{
if (cell.Selected) // checks if the current cell is selected
{
selectedRow = rowIndex; // record cell row
selectedCol = colIndex; // record cell column
selection = row; // as well as the actual row itself
break;
}
colIndex++;
}
if (selection != null) break;
rowIndex++;
}
}

Josh

Shyam Pillai said:
Tables in 2007 are pretty much broken from the object model perspective. You
can check if a cell is selected, that works. However extracting text from
the selected cell is another matter.
?ActiveWindow.Selection.ShapeRange.Table.Cell(1,1).Selected

Regards,
Shyam Pillai

Image Importer Wizard
http://skp.mvps.org/iiw.htm


JsJ_Slim said:
By the way,

I'm coding for Powerpoint 2007. And I believe I read somewhere in the
newsgroup that TextRange.Parent.Parent will not work (and I can confirm
this
too) because the Object Model for 2007 keeps returning null.

Please help.

Thanks

JsJ_Slim said:
Hi,

I'm trying to detect if a user selected a cell within a powerpoint table
shape, as well as find out which row and column the cell belongs to.
Basically, I'm trying to do the equivalent of the following Word code:

***Code Snippet***

Cell selectedCell = Application.Selection.Cells[1];
int rowIndex = selectedCell.Row.Index;
int colIndex = selectedCell.Column.Index;

******

Please help.

Thanks.

Josh

p.s.

sorry for the trail of posts in the forums and newsgroup. apparently,
"Powerpoint" and "Project" looks the same to me, especially early in the
morning.
 
Back
Top