From: Mr. Arnold on
Anthony wrote:
>> It's in the link.
>>
>> http://blogs.techrepublic.com.com/programming-and-development/?p=594
>
> I still have a problem.
> I've a windows form application and DataGridView does not contain a
> definition for 'DataBind' and no extension method 'DataBind'.


XDocument xmlDoc = XDocument.Load(@"c:sites.xml");
var q = from c in xmlDoc.Descendants("site")
where c.Attribute("technical").Value == "true"
select new {
name = c.Element("name").Value,
url = c.Element("url").Value
};

All you have to do here is this.
dataGridView1.DataSource = q;

I think it will bind to the List<T> 'q'. 'q' is a collection of objects

You may look into BindingSource control still using BS.Datasource = q;
From: Anthony on
[ . . ]

> dataGridView1.DataSource = q;

This does not work

> You may look into BindingSource control still using BS.Datasource = q;

Tried this:
bindingSource1.DataSource = q;
and set the DataGrid's datasource to bindingSource1

This does not work either.

Anthony


From: Martin Honnen on
Anthony wrote:
> [ . . ]
>
>> dataGridView1.DataSource = q;
>
> This does not work

Try
dataGridView1.DataSource = q.ToList();



--

Martin Honnen --- MVP Data Platform Development
http://msmvps.com/blogs/martin_honnen/
From: Anthony on
> Try
> dataGridView1.DataSource = q.ToList();

That's the trick :-))))

Thank you very much !

Anthony


From: Mr. Arnold on
Anthony wrote:
> [ . . ]
>
>> dataGridView1.DataSource = q;
>
> This does not work
>
>> You may look into BindingSource control still using BS.Datasource = q;
>
> Tried this:
> bindingSource1.DataSource = q;
> and set the DataGrid's datasource to bindingSource1
>
> This does not work either.
>
> Anthony
>
>

I copied the xml for sites to a file on the HD from the link I provided
you.

I ran this code and it showed the data in the dataGridView.

private void Form1_Load(object sender, EventArgs e)
{

XDocument xmlDoc = XDocument.Load(@"d:\\duane1\\sites.xml");

var q = from c in xmlDoc.Descendants("site")
where c.Attribute("technical").Value == "true"
select new
{
Name = c.Element("name").Value,
URL = c.Element("url").Value
};

var bs = new BindingSource {DataSource = q};

dataGridView1.AutoGenerateColumns = true;
dataGridView1.AutoSize = true;

dataGridView1.DataSource = bs;
}
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: WPF-style code
Next: Uploading file to UNIX host