I have a simple windows form with a gridgridview. I am trying to attach a datasource to it. My datasource is a dictionary. When I debug I can see that the values reach the binding source but they are not showing up in the datagrid. I was wondering if anyone could kindly give me an idea as to what is going on.
Here is the code:
public partial class DatagridView1GUI : Form
{
Dictionary<string, object> _d;
public DatagridView1GUI (Dictionary<string, object> dictionary)
{
const int ROW_HEIGHT = 22;
InitializeComponent();
_d = dictionary;
Height += ROW_HEIGHT * (_d.Count);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
开发者_Python百科}
private void OKButton_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void DatagridView1GUI_Load(object sender, EventArgs e)
{
Dictionary<string, string> _guiDataSource = new Dictionary<string, string>();
ArrayList dataSourceKeys = new ArrayList(_d.Keys);
foreach (string key in dataSourceKeys)
{
_guiDataSource.Add(key, _d[key].State.ToString());
}
BindingSource _bindingSource = new BindingSource();
_bindingSource.DataSource = _guiDataSource;
DatagridView1GUI.DataSource = _bindingSource.DataSource;
}
}
You are setting the bindingsource to DatagridView1GUI.DataSource. I see that this is your current forms name and not the datagridview to which you want to bind the data. I believe that your datagridview is dataGridView1.
精彩评论