Can´t insert text into schedule cell

Can´t insert text into schedule cell

Anonymous
Not applicable
541 Views
1 Reply
Message 1 of 2

Can´t insert text into schedule cell

Anonymous
Not applicable

Hi I want set text to a schedule.

Here is the code I got so far:

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {


            Document doc = commandData.Application.ActiveUIDocument.Document;
            View activeView = commandData.View;

            if (activeView is ViewSchedule)
            {
                ViewSchedule CellsToAdd = activeView as ViewSchedule;
                TableData tableData = CellsToAdd.GetTableData();
                TableSectionData tsd = tableData.GetSectionData(SectionType.Header);
                using (Transaction t = new Transaction(doc, "myTrans"))
                {
                    t.Start();
                    tsd.SetCellText(tsd.LastColumnNumber-1, tsd.LastColumnNumber-1, "new Text");
                    t.Commit();
                }
            }
     }

But whenever I run the programm I get a "ArgumentException" which tells me: The given row number nRow is invalid.

How can I fix that?

0 Likes
542 Views
1 Reply
Reply (1)
Message 2 of 2

RPTHOMAS108
Mentor
Mentor

You've used 'tsd.LastColumnNumber' twice and have not used '.LastRowNumber' (if this was your intent).

 

I'm not sure if the indexing is zero based or one based therefore try without the -1 part.