We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Event handlers for TextChanged and other events for individual cells

Thread ID:

Created:

Updated:

Platform:

Replies:

89695 Sep 2,2009 03:50 PM Sep 3,2009 03:56 PM WPF 5
loading
Tags: GridControl
Andre Slenko
Asked On September 2, 2009 03:50 PM

How do you attach an event handler to catch TextChanged event for default cells (TextBox) or SelectedIndexChanged event for ComboBoxes? If you use a cell template, where do you specify an event handler for a particular control in that template, so that when you catch it, you can get a reference to a cell object itself (GridStyleInfo)?



Clay Burch [Syncfusion]
Replied On September 2, 2009 06:58 PM

Here is a zip file that has two samples.

One shows how to use the TextChanged event for TextBoxes and Comboboxes and get at the underlying style information.

The second one is a hyperlink sample that shows how you can use the CurrentCellMoved event to get at the information in a DataTemplate cell.



TwoSamples_8c2a7c9b.zip

Andre Slenko
Replied On September 3, 2009 01:19 PM

Thank you for the samples!
How can I attach a ContentMenu to a textbox (default cell style)?

Andre Slenko
Replied On September 3, 2009 01:30 PM

Another question: in the CurrentCellChanging event handler, how can I get the entered cell value. If I type "A", the event fires but style.CellValue is always "" and CurrentCell.Renderer.ControlValue is also "". How can I cancel the user input if user types an invalid value into a textbox?
I am trying to create a text cell (TextBox) that accepts only certain predefined values ("Yes", "No", "Maybe").

Andre Slenko
Replied On September 3, 2009 01:30 PM

Another question: in the CurrentCellChanging event handler, how can I get the entered cell value. If I type "A", the event fires but style.CellValue is always "" and CurrentCell.Renderer.ControlValue is also "". How can I cancel the user input if user types an invalid value into a textbox?
I am trying to create a text cell (TextBox) that accepts only certain predefined values ("Yes", "No", "Maybe").

Clay Burch [Syncfusion]
Replied On September 3, 2009 03:56 PM

Here is the code from one of the samples posted here yesterday.

void grid_CurrentCellChanged(object sender, Syncfusion.Windows.ComponentModel.SyncfusionRoutedEventArgs args)
{
GridControl g = sender as GridControl;
if (g != null)
{
GridCurrentCell cc = g.CurrentCell;
GridStyleInfo style = g.Model[cc.RowIndex, cc.ColumnIndex];
switch (style.CellType)
{
case "TextBox":
this.Title = string.Format("Text Changed[{0},{1}] newValue={2}", cc.RowIndex, cc.ColumnIndex, cc.Renderer.ControlValue);
break;
case "ComboBox":
this.Title = string.Format("Combo Changed[{0},{1}] newValue={2}", cc.RowIndex, cc.ColumnIndex, cc.Renderer.ControlValue);
break;
case "DropDownList":
this.Title = string.Format("DropDownList Changed[{0},{1}] newValue={2}", cc.RowIndex, cc.ColumnIndex, cc.Renderer.ControlValue);
break;
default:
break;
}
}
}


The cc.Renderer.ControlValue gives the changed value.

If you want to cancel keystrokes, then you can try using the grid.PreviewKeyDown event.

void grid_PreviewKeyDown(object sender, KeyEventArgs e)
{
GridControl g = sender as GridControl;
if (g != null)
{
GridCurrentCell cc = g.CurrentCell;
string currentText = cc.Renderer.ControlText;
Key newKey = e.Key;
if (YouWantToCancel())
{
e.Handled = true;
}
}
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;