|
Are you thinking out loud?
|
|
|
|
|
You're half right. 
|
|
|
|
|
Hey,
Im trying to insert cross reference into a word document, the document itself is consists of 2 headings:
1.1.1 SUBJECT1
1.1.2 SUBJECT2
while trying to iterate through all the subjects with GetCrossReferenceItems(ref oRefType); function I do get both of the subjects, however, when I use the InsertCrossReference function, it always inserts the last subject into the document (meaning, I get duplicate SUBJECT2 cross references)
See below simplified example:
object file = @"c:\somefile.docx";
object oRefHyperlink = true;
object oRefType = WdReferenceType.wdRefTypeHeading;
object arr_r = doc.GetCrossReferenceItems(ref oRefType);
Array arr = ((Array)(arr_r));
Microsoft.Office.Interop.Word.Application document = new Microsoft.Office.Interop.Word.Application();
Document doc = document.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
object oRefItem = arr.GetValue(arr.Length);
doc.Application.Selection.InsertCrossReference(ref oRefType, WdReferenceKind.wdContentText, ref oRefItem, ref oRefHyperlink, ref InsertPosition, ref SeperateNumbers, ref nullobj);
oRefItem = arr.GetValue(1);
doc.Application.Selection.InsertCrossReference(ref oRefType, WdReferenceKind.wdContentText, ref oRefItem, ref oRefHyperlink, ref InsertPosition, ref SeperateNumbers, ref nullobj);
has anyone came crossed into this problem?
Thank you for your response.
|
|
|
|
|
Before when I used the vb.net I faced the similar problem. Then I remember instead of using the Cross Reference, I used the Paragraphs.And then I found a solution to my problem...
In richTextBox you can append the text easily, and save as document file....

|
|
|
|
|
Unfortunately there are alot of actions I need to do over the document , in fact, the entire application is based on word document so I can't do these actions over the rich text box
can you please expand alittle about the Paragraphs thingy ? how did you do it ?
|
|
|
|
|
Shine..actually its vb.net2008 code..I don't have time to convert to c#..so you need to convert it.
Dim OPara1 As Microsoft.Office.Interop.Word.Paragraph
Dim Rng As Microsoft.Office.Interop.Word.Range = WrdDcmt.Paragraphs(1).Range
OPara1 = WrdDcmt.Paragraphs.Add
OPara1.Format.SpaceBefore = 50
OPara1.Range.Text = "REFERENCE No. : AMC/" + Dprt + "/" + DvPoint + "/MPR-" + TextBox1.Text + vbCrLf
OPara1.Range.Text = "DATE : " + QtRqt
OPara1.Format.SpaceAfter = 6
OPara1.Range.InsertParagraphAfter()
For RichTextBox
RichTextBox4.AppendText("DATE : " + QtRqt)
RichTextBox4.AppendText(" " + vbCrLf)
RichTextBox4.AppendText("To" + vbCrLf)
RichTextBox4.AppendText("Some of Your Text" + vbCrLf)
// Simply you can copy the rtb Text and can Paste to your Range and can add to your document..
RichTextBox4.SelectAll()
RichTextBox4.Copy()
Rng.Paste()
I hope this can helps a bit for your search 
|
|
|
|
|
First of all thank alot for your help
As far as i can see you enter the Cross Reference programmatically, am I right ?
can you please help me understand this line ?
OPara1.Range.Text = "REFERENCE No. : AMC/" + Dprt + "/" + DvPoint + "/MPR-" + TextBox1.Text + vbCrLf
thank you
|
|
|
|
|
Those are strings - DPRT & DvPoint
|
|
|
|
|
So I still don't understand how the Cross reference is being made :[]
you don't use the InsertCrossReference Function over here
|
|
|
|
|
you don't actually seem to be inserting the value at position 0. Taking a look at your assignments to oRefItem , you actually start at the length of the array (which would be after the end of the array). Surely you want to assign it here as arr.GetValue(0);
|
|
|
|
|
Hey Pete,
The array holds values from index 1 to n, index 0 throws out of range exception
|
|
|
|
|
How on earth has this been created? Standard indexing in C# is zero-based.
|
|
|
|
|
The
object arr_r = doc.GetCrossReferenceItems(ref oRefType); return non-zero indexed array (string[*]) which forces the programmer to cast a non-zero array.
|
|
|
|
|
OK, try this:
object file = @"c:\somefile.docx";
object oRefHyperlink = true;
object oRefType = WdReferenceType.wdRefTypeHeading;
object arr_r = doc.GetCrossReferenceItems(ref oRefType);
Array arr = ((Array)(arr_r));
Microsoft.Office.Interop.Word.Application document = new Microsoft.Office.Interop.Word.Application();
Document doc = document.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
int i = arr.Length;
while (i > 0)
{
object oRefItem = arr.GetValue(i--);
doc.Application.Selection.InsertCrossReference(ref oRefType, WdReferenceKind.wdContentText, ref oRefItem, ref oRefHyperlink, ref InsertPosition, ref SeperateNumbers, ref nullobj);
}
|
|
|
|
|
Thanks for your message,
unfortunately it didn't help, the problem isn't with getting the problem value from
oRefItem I think there is a certain bug in
InsertCrossReference function...
E.G: when I have 2 subjects over the document (1.1.1 SUBJECT1, 1.1.2 SUBJECT2) and I try to get ONLY the last subject, I keep getting the cross reference for the first subject.
|
|
|
|
|
What do you see in the values when you step over them in the debugger?
|
|
|
|
|
the array holds the correct values.
arr.GetValue(1)- Subject1
arr.GetValue(2) - Subject2
|
|
|
|
|
Hi,
Iam using C# 2010. I would like to know, is it possible to select a column name of listview?
I mean, once the user click on second column, then I want to get the second column value...also, once the user click on third column then the reslutant has to be thisd column value...
Is it possible?
Iam using the following codes...for listview...
for (int F12 = 0; F12 <= MyDataTable.Length - 1; F12++)
{
ListViewItem GItem = new ListViewItem(MyDataTable[F12]["invoic_no"].ToString());
GItem.SubItems.Add(MyDataTable[F12]["invoice_date"].ToString());
GItem.SubItems.Add(MyDataTable[F12]["Supplier_name"].ToString());
GItem.SubItems.Add(MyDataTable[F12]["itm_description"].ToString());
GItem.SubItems.Add(MyDataTable[F12]["unit_measure"].ToString());
GItem.SubItems.Add(MyDataTable[F12]["Invoice_Quantity"].ToString());
listView1.Items.Add(GItem);
}
listView1.Visible = true;
listView1.Focus();
Note: ListView1.SelectedItems[0].text or
ListView1.SelectedItems[0].SubItems[1].text all will give the value by assigned column.
But My clarification is is it possible to get the unkwon clicked column name...
Thanks
|
|
|
|
|
Using the ListView.HitTest[^] method; you give it the coordinates where the user clicked, and it'll return which subitem the user clicked on.
Bastard Programmer from Hell
|
|
|
|
|
Thanks Eddy. I Get Clear. 
|
|
|
|
|
You're welcome 
|
|
|
|
|
Please clarify:
Are you speaking here of an end-user clicking on a Column Header (i.e., the text in the column label area at the top), or are you speaking of an end-user clicking on an item in a Column, and from the item selected/clicked deducing the Column Header text ?
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Thank you Bill.
Yes. Iam looking for the selected item value & its header text...The user will click on the item only...
And hence I need to find that value and its header text..
I found the answer with HitTest as Eddy has posted.
Thanks
modified 19-Jan-12 1:54am.
|
|
|
|
|
Hello,
I have many c# projects. I want know to create a Team Foundation project. I can't understand what it mean the Team Foundation Server. is it my IP @??
I want u help
regards
|
|
|
|
|
A few points:
1. This has nothing to do with C#
2. Googling would reveal a plethora of hits
3. Please try to avoid text speak. It only serves to annoy people. There are so many amazing letters in the English language, like the letter y. It's a shame to ignore them.
|
|
|
|