Lin Kejian

hi

The code blow is sample form MSDN, But it doesn't work ,Help me

DataTable table = new DataTable("Employees");

private void Sheet1_Startup(object sender, System.EventArgs e)
{
table.Columns.Add("FirstName", typeof(string));
table.Columns.Add("LastName", typeof(string));
table.Columns.Add("Title", typeof(string));

table.Rows.Add("Nancy", "Anderson", "Sales Representative");
table.Rows.Add("Robert", "Brown", "Sales Representative");

Microsoft.Office.Tools.Excel.ListObject List1 =
this.Controls.AddListObject(this.Range["A1", "B3"], "List1");

List1.AutoSetDataBoundColumnHeaders = true;
List1.SetDataBinding(table, "Title", "LastName", "FirstName");
List1.Disconnect();


}

the red code throw an Exception




Re: Visual Studio Tools for Office Error with fill data into listobject

Cindy Meister

Are you using the full VSTO 2005, or are you working with an Add-in or a WinForm project

Assuming you're using the full VSTO, what error message are you getting, and which line of code is triggering it

also, please give us the link to the sample code.






Re: Visual Studio Tools for Office Error with fill data into listobject

Linkejian

Hi Cindy Meister

I am sure using the full vsto 2005 ,and working with an Document based application

when I use code as

Code Snippet
List1.SetDataBinding(table, "Title", "LastName", "FirstName");

It raise an error

but if I use code as

Code Snippet
List1.SetDataBinding(table)

It's OK , so the problem become how to set filed in ListObject






Re: Visual Studio Tools for Office Error with fill data into listobject

Cindy Meister

and what is the error, please




Re: Visual Studio Tools for Office Error with fill data into listobject

Duy Le - MSFT

Is this the document you looked at

http://msdn2.microsoft.com/en-us/library/ms268997(vs.80).aspx

The code should be:

List1.SetDataBinding(table, "", "Title", "LastName", "FirstName");

If you got the code from a different URL, let me know, so I can have it updated with the correct code.

Thanks.





Re: Visual Studio Tools for Office Error with fill data into listobject

Linkejian

Hi Duy

The url is correct, but I am a user from china ,so the MSDN Chinese editon also have the same problem ,

The Chinese edition Url is http://msdn2.microsoft.com/zh-cn/library/ms268997(VS.80).aspx






Re: Visual Studio Tools for Office Error with fill data into listobject

Duy Le-MSFT

Thanks for the information. We hope to have the documents refreshed soon.