DataGrid editing

Page 1 of 1

1 Replies - 2017 Views - Last Post: 29 June 2011 - 11:21 AM Rate Topic: -----

#1 blank_program   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 292
  • Joined: 22-July 09

DataGrid editing

Posted 26 April 2011 - 01:35 PM

I notice there is a RowEditEnding event on the DataGrid which I wanted to use to add items to a database but my first issue is with a test project I didn't get any editable rows for my DataGrid when I added two DataGridTextColumns. Is there something else special I need to do since I also set CanUserAddRows=True. I could have sworn that a previous project there was a row atutomatically added. Does the ItemSource or DataContext need set for this to happen or am I missing something? Since I will have my database but initially it will be empty.

Thanks ahead of time I feel this is something silly that I am missing. Though I also am unsure how to get the newest row the user edits with the event as well but I am sure I can just look that up later.

Is This A Good Question/Topic? 0
  • +

Replies To: DataGrid editing

#2 sssmartie   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 03-June 08

Re: DataGrid editing

Posted 29 June 2011 - 11:21 AM

If I'm getting it properly you're trying to add editable rows to your wpf datagrid.
You can do this by defining each one of your datagrid columns as DataGridTemplateColumns.

<dg:DataGridTemplateColumn Header="First Name">



      <TextBox Text="{Binding Path=FirstName}" />






      <TextBox Text="{Binding Path=FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />




As seen above ,you have the CellTemplate and CellEditingTemplate properties.
CellTemplate is the non-editing state of the column and CellEditingTemplate is the editing state of the column.
In the non-editing state,the column shows a TextBox and it's bound to the FirstName property of my data source.
In the editing state a TextBox is again created as the UIElement to be displayed which can edit the bounded data.

This post has been edited by sssmartie: 29 June 2011 - 11:44 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1