datagrid wpf 刷新数据_问题我无法在datagrid wpf中刷新数据

I have a datagrid in main form, which take datas from databse Firebird.

In another form i''am editing datas in database by wcf service,in which i describe a methods to create,update my datas.

But I cannot refresh datas in datagrid when i create a new record in second window..

Datas to datagrid i''am taking from database by using a class.

code of button edit,new and delete ..private void QueueOperations(int tag)

{

Queue q = new Queue();

MainWindow mn=new MainWindow();

ISDElectronicQueueWcfServiceLibrary.Queue queue = new ISDElectronicQueueWcfServiceLibrary.Queue();

switch (tag)

{

case 1:

{

if (ttbQueueName.Text == "")

{

MessageBox.Show("Заполните наименование очереди", this.Title);

ttbQueueName.Focus();

}

else

{

try

{

svc.CreateQueue(ttbQueueName.Text, ttbQueueDescription.Text);

ttbQueueDescription.Text = "";

ttbQueueName.Text = "";

q.dtgQueue.ItemsSource = svc.GetQueuefromClass(0, 0);

q.dtgQueue.Items.Refresh();

Close();

}

catch (Exception str)

{

MessageBox.Show("Такая очередь уже существует\n" + str.Message, this.Title);

}

}

}

break;

case 2:

{

if (ttbQueueName.Text.Length == 0)

{

MessageBox.Show("Нужно заполнить наименование", mn.Title);

ttbQueueName.Focus();

}

else

{

try

{

queue.id = queueid;

queue.name = ttbQueueName.Text;

queue.description = ttbQueueDescription.Text;

svc.SetQueue(queue);

ttbQueueName.Text = "";

ttbQueueDescription.Text = "";

q.dtgQueue.ItemsSource = svc.GetQueuefromClass(0, 0);

q.dtgQueue.Items.Refresh();

Close();

}

catch (Exception e)

{

MessageBox.Show(e.Message, mn.Title);

}

}

}

break;

case 3:

{

svc.ClearQueue(queueid);

ttbQueueName.Text = "";

ttbQueueDescription.Text = "";

q.dtgQueue.ItemsSource = svc.GetQueuefromClass(0, 0);

q.dtgQueue.Items.Refresh();

Close();

}

break;

}

ttbQueueName.Focus();

}

解决方案Use an ObservableCollection for the data (http://msdn.microsoft.com/en-us/library/ms668604.aspx[^]). The ObservableCollection handles the NotifyPropertyChanged when items are added or deleted.

Since only see part of the solution, so not sure about everything. You may need to provide an adapter to convert your Queue (? guess you are using a queue) to an ObservableCollection. You could also create a control that does what you want as far as Queue operations the inherits from ObservableCollection

try this..

dataGrid1.BeginEdit();

///add your code here/

dataGrid1.CommitEdit();//or use only this

then refresh datagrid

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值