Dezzz

Hello,

I am sure this has been answered before but here goes anyway....

I have a Service which provides me with some hierarchical data which I would like to display in a DataGrid.

Fields 1 and 2 (e.g. Code , Name) are followed by a subset of 2 fields (e.g. Language and Translation) the 3rd field Language being a combo box from a predefined set of available languages (lets say 3 in this case)

thus by example

DEU Germany de-DE Deutschland

fr-FR Allemagne

en-US Germany

FRA France de-DE Frankreich

fr-FR France

en-US France

So, to be able to allow the user to update as they need I am using a DataGrid. TO reduce the code behind I wanted to use something like an Observable collection (which also seems to handle hierarchical data). Now here comes the rub - As I am not bound to the Service that provided me with the data I need to send back to the Service 3 messages - New Records, Deleted Records and Modified Records - thus when the User hits the 'Commit' button - in theory I should have 3 collections. In all the examples shown by Microsoft I havn't seen a way of Marking records (in tha way a Dataset would do) to indicate Added, Deleted Modified.

Real Question: Can I use this approach to achieve my goal or can anyone suggest a diferent methodology/approach.

Any help appreciated...

Desmond.



Re: Windows Presentation Foundation (WPF) DataGrid, DataBinding and Updates

Yi-Lun Luo - MSFT

Hello, what DataGrid are you using WPF doesn¡¯t have a build in DataGrid. Also what ¡°records¡± are you using Are they DataSets You may need to explain a little more detail.






Re: Windows Presentation Foundation (WPF) DataGrid, DataBinding and Updates

Dezzz

Ah Hello Yi-Lun....Many thanks for coming back..

Well that's the whole issue (MS don;t have one)..I have tried Xceeed and NetAdvantage and they are very verbose as far as far as adding and deleting records are concerned - I just looked at NetAdvantage yesterday and it expects my collection to be implementing the IBindingList.- a bit Over the top if you ask me.

I really have a generic problem - I will be generating about 50-100 different screens with potentially different sources on each grid thus the search for a simple solution that again just works like an MS Access screen. Frankly I am amazed...as I would have though most Corporate customers would have similare needs.

My data format e.g. DataSets , Observable collection is open to debate and at this stage will consider anything that you recommend - at the moment it is in a System.Collections.GenericList<T> - I

Cheers,

Desmond.





Re: Windows Presentation Foundation (WPF) DataGrid, DataBinding and Updates

Dezzz

Hi Yi-Lun ...any anybodey...any ideas

Cheers,

Dezzz.





Re: Windows Presentation Foundation (WPF) DataGrid, DataBinding and Updates

Benny Tops

Hi,

I would databind a ListView/GridView to a DataSet. On submitting, you can run through your DataSet and get the new, modified and deleted items.

Best regards,

Benny





Re: Windows Presentation Foundation (WPF) DataGrid, DataBinding and Updates

Dezzz

Thanks Benny for replying...I DO appreciate some feedback,

This is what I've done so far...let me run it past you and see what you thing...

In my ItemsSource collection

a. I have added 3 Boolean properties Added, Modified and Deleted

b. Made a slight modification to the INotifyPropertyChanged logic (change the Modified property if false)

public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged(string info)

{

PropertyChangedEventHandler handler = PropertyChanged;

if (handler != null)

{

handler(this, new PropertyChangedEventArgs(info));

if (this.Modified == false) { this.Modified = true; };

}

}

c. Against the Added and Deleted methods in the main code-behind area set the collection booleans (Add or Delete) appropriately.

d. Now for Delete I guess I would have to add a filter to the CollectionView not to dispay any rows with the Deleted flag set. This allows the user to rollback if need be whilst editing.

Main point is I want to potentially reduce the number of Calls to the Webservice so whne the User decides to 'Commit' then 3 cals and thats all his/her edits donw in one fell swoop.

I am really looking for assurance that I am not using a sledgehammer to crack a nut !!!

Cheers,

Dezzz.





Re: Windows Presentation Foundation (WPF) DataGrid, DataBinding and Updates

Benny Tops

Hi,

Personally, I wouldn't implement it like this. I would use ADO.NET, because it has the behavior of keeping track of changes built in. Now, you have to rebuild the maintenance yourself.

Also, I do not really understand what you are trying to build. You've added 3 booleans: Added, Modified and Deleted. Why not add just add one property, called State for example, which is an enumeration with the Added, Modified and Deleted values

Maybe I'm missing something or I don't have enough information ...

Best regards,

Benny





Re: Windows Presentation Foundation (WPF) DataGrid, DataBinding and Updates

Dezzz

Hi Benny,

I basically retieve data from a Web Service which I have to 'relocate' to an entity - be that an Observable Collection, a Generic Collection so as I can bind it to the XAML.

Now, if you are saying that I should create a DataSet and DataTable with the data I have and THEN bind that - well that is a different matter. This was my question in the first place.

I have an object named CountryDC (DataContract) returned to me from the Web Service which I have a List of in my 'mini' DAL and pass this on to the XAML code-behind to merely set the ItemsSource to that Collection.

private List<CountryDC> m_curExposeCountry = new List<CountryDC>();

public List<CountryDC> _CountryItems

{

get { return m_curExposeCountry; }

set { m_curExposeCountry = value; OnPropertyChanged("_CountryItems"); }

}

The big question is how levels of data manipulation or rather which should be the 'Choice' should I go through. I couild of course, in my mini DAL replace the code above with a DataSet as you suggested.

The main reason for keeping 3 booleans is that when a row traverses between the various 'States' the extra logic involved in only having one setting would result in spaghetti code whilst with 3 properties I can visually see what is happening. I am not saying that ONCE the business decides the functionality of what they doould like to see happen that this would not be an option but for now its more convenient whilst I am getting the whole thing to operate.

Can you understand what I am doing

Cheers,

Dezzz.