.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

edit DataGrid cell contents

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :WPF

I'm attempting to create a DataGrid where the user can edit the cells directly in the grid and have these changes updated in the underlying data source and reflected in the data grid.  Unfortunately I'm having trouble achieving this.

The xaml specification of my data grid is as follows:

      ItemsSource="{Binding Path=Parameters, Mode=TwoWay}"

View Complete Post

More Related Resource Links

How to get the combobox value inside Datagrid on Edit button click event

Hi     I have Datagrid template column like<DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>DataGridTemplateColumn Header="Edit" x:Name="Edit" ><DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>SelectionChanged="cmbDGTeam_SelectionChanged" IsTabStop="True" /></DataTemplate><ComboBox Height="22" IsEditable="True" IsReadOnly="True" ItemsSource="{Binding}" DisplayMemberPath="Title" SelectedValuePath="TeamID" x:Name="cmbDGTeam"  SelectedValue="{Binding Path=TeamID,Mode=TwoWay}"<DataGridTemplateColumn.CellEditingTemplate><DataTemplate><DataTemplate><TextBlock Text="{Binding Title}"/></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn Header="Team" Width="75"><DataGridTemplateColumn.CellTemplate> and Edit button Template column <DataGridTemplateColumn Header="Edit" x:Name="Edit" > </DataGridTemplateColumn.CellTemplate></DataTemplate><Button Content="Edit" IsEnabled="False" x:Name="btnEdit" Click="btnEdit_Click" ></Button>&l

Get Cell Value of DataGridComboBox Column for WPF DataGrid

hello Friends I am using WPF Datagrid (WPFToolKit Control) in my appliction I Have a DataGridComboBox Column which is filled with some records.  <WpfToolkit:DataGridComboBoxColumn ScrollViewer.CanContentScroll="True" CellStyle="{StaticResource LeftAlignedCellStyle}" Header="Item Code" x:Name="CmbItems" Width="250" SelectedValueBinding="{Binding ITEMCODE}" DisplayMemberPath="ITEMDESC" SelectedValuePath="ITEMCODE"  > </WpfToolkit:DataGridComboBoxColumn> Now how to get selectedText of that combobox for current row. my current focus on other cell  Please Help Me regards Vipul

WPF DataGrid TemplateColumn does not go into edit mode when tabbed to.

I am using a TemplateColumn with the WPFToolKit DataGrid.  When I tab thru the other columns when in edit mode the cells go right into edit mode, but when I hit the cell with the TemplateColumn I have to click the tab twice to get into edit mode.




Changing Datagrid Cell foreground colour depending on previous value



I have a datagrid bound to a observable collection and a background thread is regularly updating the collection when an event is fired.( subscribed to a market data service) . I need to change the foreground of the cell value if (Previousvalue > NewValue) . I guess I need a conveter but how can I get access to the previous value ? Or is there a smarter way to do this. Performace is a concern as well.

Thanks v much.


WPF DataGrid TemplateColumn does not go into edit mode when tabbed to first time.

I am using a TemplateColumn with the .Net4.0 DataGrid.  When I tab thru the other columns when in edit mode the cells go right into edit mode, but when I hit the cell with the TemplateColumn I have to click the tab twice to get into edit mode.




Any Workarounds. I came across a work around http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/93d66047-1469-4bed-8fc8-fa5f9bdd2166/ but I cannot use that because of the bug http://social.msdn.microsoft.com

How to change the datagrid cell background color linear to the value



I have a WPF 4.0 Datagrid displaying order values and I need to colour the backgroud of the high value orders so the user will notice high value orders easily. Is it possible to set the colour from white to red but increasing in steps say every 10,000 and increase the colour intensity according to the value.

Many Thanks.


Datagidview Cell Edit Cancel/Commit


How can I trap Commit/Cancel of a cell/row in datagridview?

I have a datagridview with a column order which contains numeric order value 1,2,3,4,5 etc. It actually displays the position of the row. I am using DefaultValuesNeeded to automatically populate the new row with the new order value. So if the last value was 5 next would be 6. The gridview is bound to a dataview. There are two radio buttons (off course out side the grid view), which are used to filter the data in gridview (applying rowfilter on dataview). When the second radio button is clicked the rows that are displayed have higher order values than the rows that are displayed when the first radio button is clicked, meaning continuation of order values.

Now situation is there are total 11 rows in the dataview and grid view. When first radio button is selected 6 rows are displayed. Therefore the order value for sixth row is 6. When the second radio button is selected 5 rows are displayed and and order value for the starting row in this case is 7 and for the last row is 11. Now I realize that I have to enter one more row for first radio button. So I select first radio button and the six rows are displayed. I go to 7th row and it prepopulates the order value with 7. Here I have two options:

1. To commit  the changes by pressing Enter.

2. Cancel changes by

How to wrap the Cell in DataGrid? PLS HELP ME


Dear all,

Are Anyone know how to wrap the cells in the Datagrid (in WPF) to show long texts wrapped? I tried all the way, but due to lack of experience and knowledge in WPF, I am not able to make it run

I declared following style in the Resources as like below

 <Style x:Key="myGridCellStyle" TargetType="DataGridcell">
 <Setter Property="ContentTemplate">


changing Asp.net Gridview's cell from Label to edit mode in code behined file


 Hi all,

In my asp.net application i'm using gridview to which i'm binding data dynamically by writing a select query in code behined file (all column's are autogenerated) now i want to change gridview cell to edit mode from label to textbox or dropdown on clicking of gridview's cell.How can i achive this in code behined file.

thanks in advance

Create controls inside the datagrid cell based on the datatype uisng WPF


I have a requirement that I need to develop a component which should display variable types of data inside a datagrid. The datagrid will have two coulmns. Fisrt column will display the list Captions (like: FirstName, DateOfBirth, IsMarried, Age) and the second column will display the list of data based on their data type, like:

> As FirstName is in string format it should display the value inside a TextBox control on right side of FirstName caption

> As DateOfBirth is in Date format it should display the Date value inside a DatePicker control on right side of DateOfBirth caption

> As IsMarried is in Boolean format it should display the CheckBox control with check state on right side of IsMarried caption

> As Age is in integer format it should display the integr value inside a TextBox Control on right side of Age caption.

If any body has any idea please guide me the way to develop. I request you to kindly help on this for creating this control



KeyUp event on DataGrid cell or column




I've a DataGrid in my wpf, and I'm creating my columns dynamically via code,

i want to handle the key event on the dataGrid column.

how can i handle event on dataGrid column (something like dataGridView has in winforms).

here is an example:

col = new DataGridTextColumn();
            col.Header = "sum";
            col.Width = new DataGridLength(15, DataGridLengthUnitType.Star);
            col.Binding = new Binding("sum");




Entering edit mode with RichTextBox in a DataGrid column


Hi guys,

I have a DataGrid TemplateColumn with a readonly RichTextBox in its CellTemplate and a (editable) RichTextBox in its CellEditingTemplate. The problem is that when I double click the RichTextBox, it selects its text instead of bringing the DataGrid to Edit mode.

As a workaround, I hooked PreviewDoubleClick on the RichTextBox and called DataGrid.BeginEdit(). Although this does bring the editable RichTextBox but the Caret is always at the beginning of the text instead of the location where I double clicked.

Any Ideas how to handle this?


Syed Mehroz Alam
My Blog | My Articles

Table locked? Can't click into cell and edit data...


 My previous version of sql management studio did not lock me out from a table. Why does this R2 version, after I say open all rows in a table, not allow me to then click on any cell I want to edit data?

It appears just the top 200 rows will allow this. How do I change this setting? What is the purpose of locking like this anyways? 

how to get a cell control in DataGrid


Dear everyone

i have tried to get a cell control in datagrid, but i can't get it.



        void SimPle_Loaded(object sender, RoutedEventArgs e)

        Microsoft.Windows.Controls.DataGridCell cell = GetCell(1, 1);
            TextBlock tb = cell.Content as TextBlock;   // i can't get the textblock, the cell.content have a binding object, not control
            if (tb != null)


          //<Output:OutputIO x:Name="WriteOutput" BorderThickness="6" Height="38" Width="150" IO="{Binding Mode=OneTime, Path=IOHandle}"  />

         // because i want to get my usercontro

Is it Possible to Edit page number text in Datagrid(which clicked)


Hi,I have a datagrid.

I am editing the page links text  1 2 3 4 5 ...  as  1-10 11-20 21-30 31-40 ...succesfully.

But here the problem is when am clicking 21-30 link it changes to 3.

How to display the 3 as 21-30.

Setting focus on cell in datagrid after CollectionChanged event.




Having trouble setting the focus on a cell after the collection recieves a new row. This is my code:

 sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
			DataGridRowObjects<My_DataGridRow> oc = (DataGridRowObjects<My_DataGridRow>)sender;
 (e.Action == NotifyCollectionChangedAction.Add)
				//set focus to column 2 of the new row

				DataGridCell cell = my_datagrid.GetCell(e.NewStartingIndex, 2);
 (cell != null
				 DataGridCellInfo info = new
				 my_datagrid.CurrentCell = info;

Is there any event that fires after the CollectionChanged? My DataGridRow doesn't have a CellPresenter att this stage and GetCell fails. If I do the same with a button event instead, it works fine.

I just tried to add a dispatcher message instead but that did nothing:

Dispatcher.BeginInvoke(new Action(delegate()
  //set focus to column 2 of the new row
  DataGridCell c

How to assign a value to wpf datagrid cell


Let say I have a wpf datagrid with 2 columns (ProductID and Description).  ProductID column is a combobox and the Description is a Textbox.  On the SelectionChanged event of the ProductID, I want to assign a value to the Description column.  I need to know how to assign the value to the Description textbox for the row of the combobox that fired the SelectionChanged event.  Can someone please provide a sample code?  Thanks

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend