C
Chris Dunaway
The following code is placed a new Windows Forms App and a
DataGridView and BindingSource are dragged onto the form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ThrowAwayCS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = bindingSource1;
var procs = from process in
System.Diagnostics.Process.GetProcesses()
select process.ProcessName;
bindingSource1.DataSource = procs;
}
}
}
When run, the grid does not show a ProcessName column with the names
of the processes as expected, it has a Length column with the lengths
of the names.
However, change the LINQ to the following and the correct values are
shown:
var procs = from process in
System.Diagnostics.Process.GetProcesses()
select new {process.ProcessName};
Can anyone shed some light on this? I am sure I am missing something
obvious.
Thanks,
Chris
DataGridView and BindingSource are dragged onto the form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ThrowAwayCS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = bindingSource1;
var procs = from process in
System.Diagnostics.Process.GetProcesses()
select process.ProcessName;
bindingSource1.DataSource = procs;
}
}
}
When run, the grid does not show a ProcessName column with the names
of the processes as expected, it has a Length column with the lengths
of the names.
However, change the LINQ to the following and the correct values are
shown:
var procs = from process in
System.Diagnostics.Process.GetProcesses()
select new {process.ProcessName};
Can anyone shed some light on this? I am sure I am missing something
obvious.
Thanks,
Chris