问题
I have a button that creates checkedlistbox inside a table in word. the problem is that I can access the checkedlistbox only inside the function and if I am doing this inside the scope, I can only access the last checkedlistbox
the code:
{
Microsoft.Office.Tools.Word.Controls.CheckedListBox listBox1;
Document extendedDocument = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
extendedDocument.Paragraphs[1].Range.InsertParagraphBefore();
listBox1 = extendedDocument.Controls.AddCheckedListBox(newTable.Cell(i , 2).Range, 90, 66.75F, "checkedListBox1" + i);
//listBox1.Name = xlDDLRange.Cells[j, i].Value2.ToString();
// MessageBox.Show(listBox1.Name);
//CheckedListBox.CheckedItemCollection;
listBox1.IntegralHeight = true;
int j = 1;
int range = ColumnRange(i );
while (true)
{
//MessageBox.Show(xlDDLRange.Cells[j, i].Value2.ToString());
if (j == range) break;
// Add items that are wide to the ListBox.
listBox1.Items.Add(xlDDLRange.Cells[j+1 , i ].Value2.ToString());
j++;
}
}
and the code to check if check is mark:
foreach (Microsoft.Office.Tools.Word.Controls.CheckedListBox listBox1 in listBox)
{
MessageBox.Show(listBox1.Name);
foreach (int indexChecked in listBox1.CheckedIndices)
{
MessageBox.Show(indexChecked.ToString());
// The indexChecked variable contains the index of the item.
MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" +
listBox1.GetItemCheckState(indexChecked).ToString() + ".");
}
}
please help :(
来源:https://stackoverflow.com/questions/59523729/access-word-checkboxlist-and-check-if-check-mark-in-checkbox