.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

How do I make a DataGrid fire an event when a cell is changed?

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

I tried to figure this out a while ago but gave up - now I'm in a situation where I need to try again.

I have a DataGrid (using .NET 4) and I'm trying to fire an event when a cell is changed.  However, I cannot generate any events until a different row is selected.  So, for example, I have a datagrid with a checkbox column and I want an event to occur when the user changes one of the checkboxes.  As it is right now, I can't generate an event until the user selects another row after changing the checkbox.

I've tried every type of event I can find - RowEditEnding, CellEditEnding, CurrentCellChanged, MouseLeftButtonUp, MouseLeftButtonDown, etc.  None is ever fired when the checkbox is changed - they don't fire until another row is selected.

So, I can click away on a checkbox hundreds of times and no events will be generated.  As soon as I change rows, though, the events occur.

Any help with this one?  This is such an elementary problem I'm sure there's something basic I'm missing.  Suffice it to say, I don't use WPF very often :)  I've seen the same question asked elsewhere and there are supposed answers but they are extremely complicated and I can't get them to work.

Thanks in advance,


View Complete Post

More Related Resource Links

Cell value changed event(?) in DataGrid


What would be a good way to capture a change in a cell value and act on it (e.g. flash the background)?

The only thing that I could come up with was using Binding.TargetUpdated.  It works fine with the exception that when you scroll a virtualized grid TargetUpdated is obviously also fired. There has to be a better way to do something simple like this ...

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

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




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

jquery click event doesn't fire after postback anymore

Hello there,I have a small website where I want to display a confirmation dialog after clicking on a button.When you click the confirmButton the dialog appears. Then you can choose between Yes or No to either continue with the PostBack or to return.Problem: The first time you get into the site all works fine. But after you click Yes to continue with the PostBack, no click event will be triggered anymore.Here is some code.<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script type="text/javascript"> function loadConfirmDialog() { //Dialog configurieren jQuery('#confirmDialog').dialog({ autoOpen: false, width: 400, modal: true, resizable: false }); //Dialog öffnen jQuery('#confirmButton').bind('click', function () { jQuery('#confirmDialog').dialog('open'); return false; }); //Postback ausführen jQuery('#continueButton').bind('click', function () { jQuery('#confrimDialog').dialog('destroy'); __doPostBack('confirmButton', ''); }); //Postback abbrechen jQuery('#cancel

Custom event does not fire

Hello,I have a base server control class for all my user controls. Inside this class I have the following declaration:#region Event Handling Management public event EventHandler ItemSaved; public event EventHandler ItemCancelled; protected virtual void OnItemSaved(EventArgs e) { if (this.ItemSaved != null) { this.ItemSaved(this, e); } } protected virtual void OnItemCancelled(EventArgs e) { if (this.ItemCancelled != null) { this.ItemCancelled(this, e); } } #endregion Concrete user controls used in the application are used always inside a ModalPopupExtender object and the popup it is always handled with server-side code. This means that there are no controls binded to the OkControlID and CancelControlID properties of the ModalPopupExtender.The responsibility to show the Modal Popup is then given to the aspx that has code like thisin the ASPX file...<gsl:PhoneNumberUC ID="ucPhoneDetail" runat="server" />in code behind...protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Bind to the event handler ucPhoneDetail.ItemSaved += new EventHandler(ucPhoneDetail_ItemSaved); ucPhoneDetail.ItemCancelled += new EventHandler(ucPhoneDetail_ItemCancelled); } } protected void btnNewPhone_Click(object sender, EventArgs e) { //Show the Modal Popup this.mpePopupPhone.Show(

get url from server and fire event

i want to open new window ,but i dont want to provide url link in script because i want to hide this link from user.so is there any method to get URL from server and fire event to open new window after cliking button which has some server logic on that basis serever return URL. 

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

Infopath Changed Event code triggering in preview but not in web filler.

Hi there, I've written some code for a changed event hookup on a field in infopath 2010. The form is for submission to a sharepoint 2010 forms library. What the code does is fill in a specific value into a field depending on the selected value from a combo-box elsewhere on the form. When i preview this in Infopath 2010 it works perfectly but when i fill out the form through the web interface it simply does nothing. I've got another piece of code which executes on load and this works perfectly in both the preview and the web filler. What it does is just set the value of a field when the form loads. Here is the code, could someone tell me what i'm doing wrong? public void InternalStartup() { EventManager.XmlEvents["/my:myFields/my:service_level"].Changed += new XmlChangedEventHandler(service_level_Changed); EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading); } public void service_level_Changed(object sender, XmlEventArgs e) { // Write your code here to change the main data source. XPathNavigator xroot = MainDataSource.CreateNavigator(); XPathNavigator serviceLevel = xroot.SelectSingleNode("/my:myFields/my:service_level",NamespaceManager); XPathNavigator xest = xroot.SelectSingleNode("/my:myFields/my:est_cost", NamespaceManager); switch (serviceLevel.Value)

Cannot get Asyncfileupload to fire UploadComplete event... :(

hey everyone!I cannot get the asyncfileupload to fire the uploadcomplete event at all. I did a test:    Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AsyncFileUpload1.UploadedComplete         Dim currentUser As MembershipUser = Membership.GetUser()         Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)         errorLabel.Text = "Test"     End Sub    Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AsyncFileUpload1.UploadedComplete       errorLabel.Text = "Test"    End Suband... nothing. The background turns green, my throbber activates successfully.. but then, I get nothing. It doesnt even make it to the uploadedComplete event. I also did the same test in the error event.. and still nothing. Any ideas??

Handle MaxLength changed event for TextBox

Hi, Is it it possible to handle the event when MaxLength property is changed on a TextBox? Thanks, cp

How to make a DataGridView Cell/Column not enterable / selecatble

Hi, I am trying to make a Column in a DataGridView non-entaerable (the user should not be able to set focus to the cell neither using the mouse nor the keyboard). I already tried to change the CurrentCell property in the CellStateChanged. But in this event-handler the CurrenCell is the "old" one; setting it to any value doesn't help, because the value is set after calling this procedure. In Delphi there is an event-handler for entering a cell, where you can tell whether the user is allowed to enter a cell. Is there anything comparable in C#? Any other suggestions?

How to make a connection between a word in the cell (href)? and a rule of the same or another table

 HelloHow to make a connection between a word in the cell (href)? and a rule of the same or another table with sql. Is there also finished editors?

Raise OnPropertyChanged event when Text Box Text has changed

Hi there I have a Wrapped Text Box that is bound to a Public String Property. I have a related OK Button that should be Enabled when the text changes to indicate there are 'items' in the Text Box. The problem is that the set accessor of the property (and thus OnPropertyChanged) is not being called until focus is lost from the text box - and I would like the Ok Button to be enabled before then. What is the the best way to raise the set when the Text Box text has changed? (A List Box is not an option) Thanks very much Joe

OnItemCommand event won't fire

My formview OnItemCommand event . What do I need to do to capture this event?  <asp:FormView ID="fvMemberDetail" runat="server" DataKeyNames="Ident" EnableViewState="False" OnItemUpdating="fvMemberDetail_OnUpdating" OnItemCommand="fvMemberDetail_ItemCommand" OnItemInserting="fvMemberDetail_OnInserting" >  protected void fvMemberDetail_ItemCommand(object source, FormViewCommandEventArgs e) { if (e.CommandName.ToString() == "Insert") { MemberInfoInserting(); DlMembers.Visible = true; fvMemberDetail.Visible = false; } if (e.CommandName.ToString() == "Update") { MemberInfoUpdating1(); DlMembers.Visible = true; fvMemberDetail.Visible = false; } } Thanks for your suggestions. EJM

Checkbox checked changed event inside gridview

Hi All, In my gridview there are 8 checkboxex in each row : 'Sunday' to 'Saturday' and one for 'All'. If 'All' is checked in a particular row, all other checkboxes in that row should be checked instantly, and viserversa. Can i do this in checkbox checked_changed event, if so how do i access the current row of the gridview in the checked changed event? Thanks in advance

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
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