Advertisement

05.09.2008 at 06:38AM PDT, ID: 23389224
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.1

C# code only brings back multiple rows on one record

Asked by MindenMan in C# Programming Language

Tags:

Hi;
I've been following the procedure on "Binding Data to Controls on a Word Actions Pane" found at http://msdn.microsoft.com/en-us/library/ms178783.aspx.

I've built my project using VS2008 and the document works as mentioned but the table only shows one record but inserts it multiple times.  Thus were I am expecting three rows of different records I'm getting two rows of the same record.  My code for the project is below.

As you can guess I am (still) a newbie at this and could do with some help on rectifying the issue.

Many thanks in advance
MMStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
ActionsPaneControl1.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Office = Microsoft.Office.Core;
using System.Data;
 
namespace TestXpath
{
    partial class ActionsPaneControl1 : UserControl
    {
        public ActionsPaneControl1()
        {
            InitializeComponent();
            this.Load += new EventHandler(ActionsPaneControl1_Load);
        }
        private void ActionsPaneControl1_Load(object sender, EventArgs e)
        {
            this.cONTRACT_ITEM_VIEWTableAdapter.Fill(this.baseline_Consultancy_MSCRMDataSet.CONTRACT_ITEM_VIEW);
            this.Insert.Click += new EventHandler(Insert_Click);
        }
        static void SetHeadings(Microsoft.Office.Interop.Word.Cell tblCell, string text)
        {
            tblCell.Range.Text = text;
            tblCell.Range.Font.Bold = 1;
            tblCell.Range.ParagraphFormat.Alignment =
                Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
        }
 
        private void AddData(DataRow row, string companyName)
        {
            object missing = System.Type.Missing;
 
            // Create a table if it doesn't already exist.
            if (Globals.ThisDocument.Tables.Count == 0)
            {
                try
                {
                    // Create a table.
                    Microsoft.Office.Interop.Word.Table tbl = Globals.ThisDocument.Tables.Add
                        (Globals.ThisDocument.Application.Selection.Range, 1, 4, ref missing, ref missing);
 
                    // Insert headings.
 
                    SetHeadings(tbl.Cell(1, 1), "Contract No");
                    SetHeadings(tbl.Cell(1, 2), "Tag No");
                    SetHeadings(tbl.Cell(1, 3), "Item Description");
                    SetHeadings(tbl.Cell(1, 4), "Serial No");
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Problem creating Contracts table: " + ex.Message,
                        "Actions Pane", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
 
            // Add data from data row to the table.
            Microsoft.Office.Interop.Word.Selection selection = Globals.ThisDocument.Application.Selection;
 
            if (selection.Tables.Count > 0)
            {
                Microsoft.Office.Interop.Word.Row newRow = Globals.ThisDocument.Tables[1].Rows.Add(ref missing);
 
                newRow.Range.Font.Bold = 0;
 
                newRow.Range.ParagraphFormat.Alignment =
                    Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
 
                newRow.Cells[4].Range.ParagraphFormat.Alignment =
                    Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
 
                
                newRow.Cells[1].Range.Text = row["ContractNo"].ToString();
                newRow.Cells[2].Range.Text = row["TagNo"].ToString();
                newRow.Cells[3].Range.Text = row["ItemDescription"].ToString();
                newRow.Cells[4].Range.Text = row["SerialNo"].ToString();
            }
            else
            {
                MessageBox.Show("Cursor must be within a table.",
                    "Actions Pane", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 
        private void Insert_Click(object sender, System.EventArgs e)
        {
            DataTable tbl = baseline_Consultancy_MSCRMDataSet.CONTRACT_ITEM_VIEW;
            DataRow[] rows;
 
            // Check if a Customer is selected.
            if (this.customerComboBox.SelectedIndex >= 0)
            {
                DataRowView customerRow = (System.Data.DataRowView)this.customerComboBox.SelectedItem;
 
 
                string customer = this.customerComboBox.Text;
                // Return the data row from the selected Customer.
                rows = tbl.Select("Customer = '" + customer.Replace("'", "''") + "'");
                this.AddData(rows[0], customer);
            }
            else
            {
                MessageBox.Show("Please select a product.", "Actions Pane", MessageBoxButtons.OK);
            }
        }
 
        private void customerComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
 
        }
 
        
 
 
 
    }
    
}
 
 
ThisDocument.cs
 
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Office = Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;
 
 
namespace TestXpath
{
    public partial class ThisDocument
    {
 
        private ActionsPaneControl1 actions = new ActionsPaneControl1();
    
 
        private void ThisDocument_Startup(object sender, System.EventArgs e)
        {
 
         
            this.ActionsPane.Controls.Add(actions);
        }
 
        private void ThisDocument_Shutdown(object sender, System.EventArgs e)
        {
        }
 
        #region VSTO Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Shutdown += new System.EventHandler(this.ThisDocument_Shutdown);
            this.Startup += new System.EventHandler(this.ThisDocument_Startup);
 
        }
 
        #endregion
 
       
    }
}
 
 
[+][-]05.09.2008 at 12:46PM PDT, ID: 21535903

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 05:27AM PDT, ID: 21546226

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 11:57AM PDT, ID: 21549582

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 02:56AM PDT, ID: 21553485

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.19.2008 at 02:53AM PDT, ID: 21596291

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 05:20PM PDT, ID: 21636932

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Tags: C#
Sign Up Now!
Solution Provided By: rlively
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.30.2008 at 09:25AM PDT, ID: 21679235

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:45AM PDT, ID: 21875351

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-39 / EE_QW_2_20070628