KeepWith 抛出未设置到对象实例的对象引用

发布于 2024-11-26 06:00:06 字数 425 浏览 1 评论 0原文

希望那里的人可能遇到与此相同的问题并找到解决方案。

我试图将表中的某些行设置为分组,以便如果一行落入下一页,其他行也将进入下一页。

我正在使用 PdfSharp 和 Migradoc 将行 KeepWith 属性设置为行的索引 我想继续执着。

IE:

var row = myTable.AddRow();
var rowIndex = row.Index;

foreach (var term in terms)
{
  row = myTable.AddRow();

  if (term.name == "group")
  {
    row.KeepWith = rowIndex;
  }
}

当我尝试加载 pdf 时,我收到“对象引用未设置为对象的实例” 抛出错误并且无法找出原因。任何帮助都会很棒。

Hoping someone out there might have had the same issue as this and have found a resolution.

I'm trying to set certain rows within a table to be grouped so that if a row falls into the next page the other rows will also go across to that next page.

I'm using PdfSharp and Migradoc setting the rows KeepWith property to the index of the row
i want to keep attached to.

IE:

var row = myTable.AddRow();
var rowIndex = row.Index;

foreach (var term in terms)
{
  row = myTable.AddRow();

  if (term.name == "group")
  {
    row.KeepWith = rowIndex;
  }
}

When i try and load the pdf I get an 'Object reference not set to an instance of an object'
error thrown and cannot figure out why. Any help would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生寂 2024-12-03 06:00:06

将 KeepWith 设置为要与当前行一起保留的后续行的计数。要将三行保留在一起,正确的值为 2(设置在组的第一行)。

Set KeepWith to the count of following rows you want to keep with the current row. To keep three rows together, the correct value is 2 (set at the first row of the group).

人疚 2024-12-03 06:00:06

我犯了一个错误,将 KeepWith 放在行的末尾以保持在一起。正如 Vive la déraison 所说,将 KeepWith 放在各行的第一行以保持在一起。

此外,为 KeepWith 值提供的 int 不包括设置它的行。因此,要将行 rowA、rowB 和 rowC 保持在一起,您可以设置:

rowA.KeepWith = 2;

如果您为表的最后几行设置 KeepWith,并意外设置值 +1(包括您设置它的行),则您将得到相同的“对象未设置...”错误,因为您将 KeepWith 扩展得比表行长。

一定会喜欢那些差一的错误。

I was making the mistake of putting the KeepWith at the end of the rows to keep together. As Vive la déraison said, place the KeepWith on the first row of the rows to keep together.

Additionally, the int provided for the KeepWith value does NOT include the row it is set on. So to keep rows rowA, rowB, and rowC together, you would set:

rowA.KeepWith = 2;

If you're setting a KeepWith for the last rows of your table, and accidentally set the value +1 (Inclusive of the row you set it on), you will get the same "Object Not Set..." error, as you are extending the KeepWith longer than the table rows.

Gotta love those Off-By-One errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文