Event handlers for TextChanged and other events for individual cells
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)?
SIGN IN To post a reply.
5 Replies
CB
Clay Burch
Syncfusion Team
September 2, 2009 10:58 PM UTC
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
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
AS
Andre Slenko
September 3, 2009 05:19 PM UTC
Thank you for the samples!
How can I attach a ContentMenu to a textbox (default cell style)?
How can I attach a ContentMenu to a textbox (default cell style)?
AS
Andre Slenko
September 3, 2009 05:30 PM UTC
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").
I am trying to create a text cell (TextBox) that accepts only certain predefined values ("Yes", "No", "Maybe").
AS
Andre Slenko
September 3, 2009 05:30 PM UTC
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").
I am trying to create a text cell (TextBox) that accepts only certain predefined values ("Yes", "No", "Maybe").
CB
Clay Burch
Syncfusion Team
September 3, 2009 07:56 PM UTC
Here is the code from one of the samples posted here yesterday.
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_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;
}
}
}
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
AS Andre Slenko
- Sep 2, 2009 07:50 PM UTC
- Sep 3, 2009 07:56 PM UTC