LINQ to SQL Winforms Databinding Question
-
2012年3月8日 15:29I have a Winforms application which uses LINQ to SQL for back end data processing. I currently have a form where I start with a complex object graph from the database. In this instance, the primary starting point is a list of projects. Each project has an associated list of jobs. Each job can have a list of change orders. The project has a 1:1 relationship with a contract entry and each job in the project also has a 1:1 relationship to a contract entry. I have no problem getting the binding sources setup on the form so that the master-detail items flow properly (change to a new project and I get the list of jobs for that project, change jobs and get only the lost of change orders for that job). My issue comes in with the 1:1 relationships to contract items. The revised contract amount for a project is the original amount plus the sum of all the change orders for all the associated jobs. I can easily compute this value with a LINQ query. I am having issues hooking to the necessary change events to cause the new value to be calculated and displayed. I have tried hooking onto the CurrentItemChanged event of the PCN binding source but it does not reflect the update until I navigate away from the row in the grid and come back to it. I am obviously missing some small item here. Does anyone have any idea what I am missing here?
すべての返信
-
2012年3月9日 3:20モデレータ
I think the EndEdit() method will help you: http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.endedit.aspx
[When the EndEdit method is called, all pending changes are applied to the underlying data source.]
Best wishes,Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
- 回答の候補に設定 Mike Dos ZhangMicrosoft Contingent Staff, Moderator 2012年3月13日 10:06
- 回答の候補の設定解除 AutomationTool_Brad 2012年3月13日 13:08
-
2012年3月13日 10:06モデレータ
I am writing to check the status of the issue on your side.
What about this problem now?
Would you mind letting us know the result of the suggestions?
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
-
2012年3月13日 13:46
After further review it made more sense for me to move the items that had a 1:1 relationship up to the parent object. I added the two calculated contract values to the project and job object and then added a calculation method that I called when values that affected the contract value were changed.
On the original design though, I really needed to be looking at the grid events to know when an amount had been edited and then update the calculated values. However I was trying to find a way to hook onto the Property Changed event for the contract item to know when to perform the calculations. While that might be possible it was certainly not easy or obvious.
To your original suggestion, I would most likely have had to call the EndEdit method on the binding source to make sure that all the data was properly updated to ensure my calculations were working properly. The EndEdit method would not help me to know when to perform the calculations since I would need to know when to call EndEdit which was also the time I needed to perform the calculations.
-
2012年3月14日 9:44モデレータ
[a calculation method that I called when values that affected the contract value were changed.]
Then which event or method call will change the value?
And maybe the INotifyPropertyChanged interface can help you: http://msdn.microsoft.com/en-us/library/System.ComponentModel.INotifyPropertyChanged.aspx, I think.
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
-
2012年3月16日 5:54モデレータ
I am writing to check the status of the issue on your side.
What about this problem now?
Would you mind letting us know the result of the suggestions?
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
-
2012年3月16日 14:06
The property changed event was what I initially wanted to use but since I needed this event from a detail in a master-detail binding scenario I could never figure out how to wire up the event to the detail item when the master changed. Since I am using a pair of DevExpress XtraGrid controls I ended up using the GridCellChanged event of the detail grid and testing to see if it was the cell I needed to recalculate on that changed.
What is the best practice way to handle this scenario?
-
2012年3月19日 8:35モデレータ
I will try to capture the cell text changed event like this:
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if(tb != null) { tb.TextChanged -= tb_TextChanged; tb = null; } } TextBox tb; private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { tb = (TextBox)e.Control; tb.TextChanged += new EventHandler(tb_TextChanged); } void tb_TextChanged(object sender, EventArgs e) { if (tb != null) Console.WriteLine(tb.Text); }But you're using the third party products, so, please use their support.
Best wishes,
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
- 回答としてマーク Mike Dos ZhangMicrosoft Contingent Staff, Moderator 2012年3月23日 7:39
-
2012年3月21日 10:06モデレータ
I am writing to check the status of the issue on your side.
What about this problem now?
Would you mind letting us know the result of the suggestions?
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us

