Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 ..

C#
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();
            
        }
Posted
Updated 29-Oct-12 14:17pm
v2

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
 
Share this answer
 
try this..
dataGrid1.BeginEdit();
///////////add your code here/////////////
dataGrid1.CommitEdit();//or use only this
then refresh datagrid
 
Share this answer
 
Comments
konah 2-Nov-12 6:39am    
Not working, i refresh datas in another window and datagrid in ana\other window

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900