.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

WPF Datagrid, raising "RowEditEnded" event

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

I know that WPF datagrid has "RowEditEnding" event , but I need to fire the event on after the Row has comitted to check if the newly added row is duplicated and merge the duplicated row. My datagrid has "CanUserAddRow" property set to True.

I am using EntityObservableCollection that extends ObservableCollection to synchronize my entity with the collection. So, i considered OnCollectionChanged event, but the "InsertItem" event is raise once user click on the new item place holder row, which means the object is still empty and I cant check for duplicate. I also considered CollectionView CurrentItemChanged event, but it does not provide the behavior I wished.



//my Model class

public class InventoryIngredient : EntityObject, IDataInfoError{

# region properties

public Guid InventoryIngredientID;
public Guid IngredientID;
public Guid UnitID;
public string

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

DataGrid Button + event in Footer, event not getting fire!

hi.First Time i am trying this...I have one Datagrid with Footer. Footer Row Contains Input fields with one Button to add New Values. I have button click event but not getting fires. my code follows:protected void dgPrice_ItemCreated(object sender, DataGridItemEventArgs e)    {            Button btnAdd = new Button();            btnAdd.Text = "Add";            btnAdd.Width = 80;            btnAdd.ID = "btnAdd";           // btnAdd.Attributes.Add("onClick", "return validateRates()");            btnAdd.CommandName = "add";            btnAdd.CommandArgument = e.Item.ItemIndex.ToString();            btnAdd.Command +=new CommandEventHandler (PriceNew);            e.Item.Cells[6].Controls.Add(btnAdd);}protected void PriceNew(object sender, EventArgs e)    {}btnAdd.command/ btnAdd.click event not getting fired I also tried to

Accessing master page from content page? Raising Event?

Here is my situation:I have a user control that has a menu in it.  This user control sits on my master page.  It is my main navigation menu for my application.I am having an issue where, on one of my pages, users seem to be leaving the page before committing all changes to the database, which results in a loss of data.So what I want to accomplish is - if the user is leaving this page and the data has not been saved yet, I want to prompt the user and say something like "The information is not yet saved, are you sure you want to leave this page" in a modal popup.So my approach is this:In my menu user control, create an event handler called MenuClicked that is raised when the menu web control's (in the user control) MenuItemClicked is raised, I raise my custom MenuClicked event.Then on my master page, I can catch this event in NavMenu_MenuClicked.My problem is - I need to catch this event in my content page, not the master?Am I approaching this correctly?Thanks in advancesb

How to stop Datagrid SelectionChange from SelectionChanged Event



I have a DataGrid which is binded with a List. Consider I have 10 Items in the List, so in the combobox also.

Currently 2nd Item is selected in the DataGrid.

Now I am selecting the 3rd item in the DataGrid.

In the DataGrid SelectionChanged event, I am doing some validation and validation fails so I don want my Selection is changed from 2nd item to 3rd item or the selection should remain in 2nd item.

Please let me know how to do this?

In the DataGrid SelectionChanged event, I tried to set DataGrid.SelectedItem = 2ndItem.

But this didn't work properly.

Hope, my requirement is clear. If you have any doubt then please feel free to ask me.



WPF Datagrid SelectionChanged event is triggering Multiple times while loading the rows.



When i use DataGridComboBoxColumn in my WPF DataGrid, the DataGrid SelectionChanged event is triggering multiple times based on the number of rows while loading the rows in the WPF DataGrid.

How can i stop this? Because of this I am facing Performance issue.



Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This will help other members to find the solution easily.

DataGrid ItemDataBound Event Calls


how many times itemDataBound event calls exactly, if my datatable have 2 records it is calling 4 times , first time in item index 0 , second time it is 1 and third time again it contains index 0 and forth time it is 1. 

so, could anyone please help me how the itemdatabound event actually works,

highly appreciate for any comment.

DataGrid control properties not updating on resize event


I have a DataGrid control on a form and I'm binding it to an ArrayList that is populated dynamically as the user scrolls.  The array list is pre-populated with blank records equal in number to the number of records in the DB.  As the user scrolls, if they stop in a place where there are blank records I populate that data from the DB.  I'm using the VisibleRowCount and VertScrollBar.Value properties to determine where I am in the DataGrid.  


The problem is that if I scroll to the bottom of the control then maximize the control it's resize event fires, the VertScrollBar is redrawn proportionally to the number of records, but the Value and VisibleRowCount remain unchanged.  If I then grab and scroll the scroll bar up then back down to the bottom, the Value and VisibleRowCount update correctly.  Is there a way for me to get these values some other way or to force the scroll bar to refresh/update manually?

Avoid raising an event


Hello everyone.

Here's my question, I have an event that's being raised on datagrid once the collection has changed, I use that to store position of columns in config file, like this:


void dgvRezultati_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
      int i = 0;
      string configFile = xmlPostavke.ConfigFile;
      XmlDocument doc = new XmlDocument();

        foreach (SortableGridViewColumn column in dgvRezultati.Columns)
          column.ColumnIndex = i;
          xmlPostavke.SpremiRasporedStupaca(column.ColumnName, column.ColumnIndex, doc);
      catch (Exception) 


But  now I have a method that removes columns, like this:

private voi

Datagrid + Mouse right click event


I have a datagrid and it contains the list of files from the folder. I want to display the default window files right click options in right click on the filename.

That is when ever i right click the filename in the datagrid, a default windows right click pop up should appear.


Can anyone help me to sort this out. The project is in C#.

Thank you.

Saugat K.C.

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");




Raising an Event in another thread from a Thread



I have a Polling thread which runs an infinite loop . and I have another thread(business) which is invoked by the UI thread based on user actions.

I need to raise an event in the polling thread from the business thread so that at the begining of the business thread (which is created  by

the UI thread bcause of a user action - say Button click - ) the event is raised and the event needs to be raised inside the Polling thread which is executing some complex logic inside a loop  and need to stop all of its operation temperorly so that the business thread can continue its work and after it completes the polling thread can resume its work , I have done the synchronization using the lock state ment but since the logic inside the loop of the polling thread is complex and takes time to complete each iteration , I need to stop the polling threads exection at the exact moment the business thread starts its execution - two threads share some  common hardware devices .


Is there any way to do this in .Net




Raising an event in .Net 3.5


I know in .Net 1.1, I used the following code when raising an event.

if (SetTaskDescription != null)
                    SetTaskDescription(this, new TaskDescriptionEventArgs("Current Row : FILTERING Row. Total Rows : " +
 this.MasterGridViewTemplate.Rows.Count)); }

But in .Net 3.5, do I have to check if SetTaskDescription != null ? I mean, I will ignore the if and just use the following code:

SetTaskDescription(this, new TaskDescriptionEventArgs("Current Row : FILTERING Row. Total Rows : " +

INotifyPropertyChanged isn't raising event


Hi, I'm trying not to create new thread about this topic. When I googled this, I found many links over this topic. I'm so desperate trying to find a solution, so I make a question here. I made a simple CAL / Prism project implementing INotifyPropertyChanged. Here is the link to my project TestProject.zip


<UserControl x:Class="PrismTestProject.Modules.Test.Views.TestView"
	d:DesignHeight="300" d:DesignWidth="300">
		<TextBlock Text="{Binding Path=MyText}" FontSize="20" HorizontalAlignment="Center" TextAlignment="Center" />


View Model

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

WPF DataGrid Add Row Event



I want to add an event to WPF that fires whenevr the user moves to another row or adds a new row in the DataGrid.

How do I do that?

Update datagrid and Event-Based Async calls


I’m using a datagrid (actually Infragistics XamGrid) which is bound to a custom list of business objects.  In the old WPF days, when completing the edit of a grid row, the business object’s EndEdit() method would be called via databinding.  The EndEdit() method would then save the data to the db via a web service call.  The retuning result of the web service call would tell the business object (in the EndEdit() method) of the call succeeded or failed.  If it failed, it would roll back the changes and raise an event to alert the UI.

In the world of Silverlight and Event-Based Async calls, it’s not possible to do all of this from in the EndEdit() method.

Also, I’m generating my web services using the SLsvcUtil.exe tool.  Since MS is forcing us to use Async calls, then what is the standard way to update data from a gird row and then roll it back and alert the UI when the call fails?

I found a nice article http://blog.jayway.com/2010/06/10/silverlight-prefer-synchronous-web-service-calls/ about making synchronous web service calls in SL, but the catch is that can’t be on the UI thread which – updating a gird row will be on.

Please relay any advice and resources you can offer!


TargetException while raising COM event for interop


Hi experts,

I've one DLL loaded in two Internet Explorer Windows. While loading the first one, a singleton is created. This singleton raises COM events, which are received by JavaScript in the Internet Explorer windows. This works fine and both IE windows are getting the events. The whole scenario works on my development machine. After deploying everything to a production machine, I get a TargetException (the object does not match the target type) when raising the COM event, but only when a function in the singleton is called from the second IE window. When I call a function from singleton instance from the first IE window everything works fine and I receive the events. I am completely lost because it works on my dev machine.

My event is defined in an interface, however the delegate is created within the singleton class.

The event definition:

[ComVisible(true )]
public interface IOcsExposedEvents
void CallStatusEvent(string message);

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