WPF中的C1Datagrid中未进行更新 [英] Update is not taking place in C1Datagrid in WPF
问题描述
using C1.WPF.DataGrid;
public static OleDbConnection connection;
public static OleDbDataAdapter da;
public static DataSet ds = new DataSet();
public static DataTable dt;
OleDbCommandBuilder cmd;
public static string connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Project/A&T.accdb";
public static string cmdstring;
private void button1_Click(object sender, RoutedEventArgs e)
{
cmdstring = "SELECT*FROM DP";
connection = new OleDbConnection(connectionstring);
connection.Open();
da = new OleDbDataAdapter(cmdstring, connection);
dt = new DataTable();
da.Fill(dt);
c1DataGrid1.DataContext = dt;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
cmd = new OleDbCommandBuilder(da);
dt.GetChanges();
if (dt.GetChanges() != null)
{
da.Update(dt);
}
dt.AcceptChanges();
}
在此代码中,我使用了第三方产品组件Datagrid.问题是单击Button2时,更改应更新回数据库.如果我用WPF的Datagrid替换c1DataGrid1,一切正常,我该怎么办.任何帮助将不胜感激
仅当单击任何其他行中的单元格时,才进行更新.否则不会发生,我想避免这种情况
问候
Iqbal
in this code i use a third party product Component one Datagrid.the problem is while clicking Button2 the change should be updated back to the database. this is not happening.if I replace the c1DataGrid1 with Datagrid of WPF everything working fine what should i do. any sort of help will be appreciated
update is happening only when a cell in any other row is clicked . otherwise it is not happening I want to avoid this situation
Regards
Iqbal
推荐答案
Have n't并未使用此控件,因此不确定是否要使用ItemsSource
.所以:
Haven''t used this control so not sure about this but should you useItemsSource
. So:
c1DataGrid1.ItemsSource= dt;
另外,许多网格组件都有一个单独的方法,可以将网格中的更改反映到基础数据源,因此请检查是否没有应调用的内容.
Also many grid components have a separate method that reflects the changes in the grid to the underlying data source, so check that there isn''t anything like that which should be called.
这篇关于WPF中的C1Datagrid中未进行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!