错误一个DataGridView绑定到BindingNavigator
问题描述:
时,我有以下的小孩子形式:错误一个DataGridView绑定到BindingNavigator
到控件链接到我的数据库表我到目前为止已经得到了下面。
我试图以类似的方式将datagridview链接到导航器,我将文本框链接到导航器 - 什么是加入这些控件的正确语法?
public SqlCeConnection conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["WindFormAppRevisionHelper.Properties.Settings.DefinitionsDBConnectionString"].ConnectionString);
BindingSource rawtableBindingSource = new BindingSource();
public uxFormDatabase()
{
InitializeComponent();
fillTheDGVusingAdapter();
}
public void fillTheDGVusingAdapter()
{
SqlCeDataAdapter da = new SqlCeDataAdapter(new SqlCeCommand("Select * From tb_Definitions", conn));
DataSet ds = new DataSet("DGVdata");
ds.Tables.Add("rawTable");
da.Fill(ds.Tables["rawTable"]);
uxDGVtable.DataSource = ds.Tables["rawTable"];
rawtableBindingSource.DataSource = ds.Tables["rawTable"];
uxrawdataBindingNavigator.BindingSource = this.rawtableBindingSource;
//PROBLEM WITH THE FOLLOWING LINE
uxDGVtable.DataSource = DataBindings.Add(new Binding("Text", uxrawdataBindingNavigator, "Item_Id", true));
}
答
这是有点不清楚你在做什么,因为3行,你已经设置了uxDGVtable控件的数据源。
尽量只使用导航器使用相同的BindingSource:
// uxDGVtable.DataSource = ds.Tables["rawTable"];
uxDGVtable.DataSource = this.rawtableBindingSource;
确定 - 将在随后意味着,在导航和datagridview的任何按钮都将高达数据库表链接即通过这些所做的任何更改控件将被保存到数据库中? – whytheq 2012-07-15 13:13:48
@whytheq是的,使用相同的网格绑定源和导航器将它们连接在一起。它不会自动保存数据,但您仍然需要通过适当的更新呼叫来完成自己的操作。 – LarsTech 2012-07-15 13:28:26
大声笑...只是在阅读您的评论和碰到更多问题之前试验保存! (我有这个winForm的第一次迭代工作正常,但我试图编写这个新版本,而不使用向导来创建数据集和绑定为我...像我这样的新手这是相当痛苦,但希望值得)。我将发布保存问题作为一个新问题 – whytheq 2012-07-15 13:38:36