麻烦使用绑定源 [英] Trouble using binding source
本文介绍了麻烦使用绑定源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是开始学习C#以及如何将它与SQL配对,所以这些更复杂的内置函数中的一些对我来说仍然是新的。
I am only starting to learn C# and how to pair it with SQL, so some of these more complicated built in functions are still new to me.
My数据表显示一行和四列,这是正确的,但是当我将它绑定到数据视图时,我得到0行和列。为什么我的数据视图网格没有填充数据表中的信息?如何让它顺利进行?
My data table shows one row and 4 columns, which is correct, but when I bind it to a data view, I get 0 rows and columns. Why is my dataview grid not populating with the information from the datatable and how can I get it to go smoothly?
推荐答案
你确定没有将您的datagridview设置为false?
Are you sure you have not set something of your datagridview to false?
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable dtW = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
dtW.Columns.Add("1");
dtW.Columns.Add("2");
dtW.Columns.Add("3");
dtW.Columns.Add("4");
dtW.Rows.Add(new object[] { "A", "B", "C", "D" });
BindingSource bsW = new BindingSource();
bsW.DataSource = dtW;
dgvWells.DataSource = bsW;
try
{
MessageBox.Show(dtW.Rows.Count.ToString()); //Shows 1 Row
MessageBox.Show(dtW.Columns.Count.ToString()); //Shows 4 columns
MessageBox.Show(dgvWells.Rows.Count.ToString()); //Shows 2 rows
MessageBox.Show(dgvWells.Columns.Count.ToString()); //Shows 4 Columns
}
catch (Exception x)
{
MessageBox.Show("Exception: " + x.Message + "\r\n" + x.StackTrace);
}
}
}
}
这篇关于麻烦使用绑定源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文