Click here to Skip to main content
15,895,799 members

WPF DataGridTextColumn or DataGridTemplateColumn - Text Entered In Row/Cell

Manish V Mahajan asked:

Open original thread
Hi,

I am about 1month new to C# and WPF. Would appreciate some help with the following:

I have a DataGridTextColumn and DataGridTemplateColumn.
I have prepopulated the table row/column with some sample data.
When a user enters some text in the KEY column row, I would like to:

1. Determine the text that the user has entered - event drivien.
2. Based on (1), populate the row with additional data pertaining to the specific KEY row/column data.

I have the following in my DataGridTextColumn:

<DataGridTextColumn.EditingElementStyle>
  <Style TargetType="{x:Type TextBox}">
    <eventsetter event="TextInput" handler="TEXT_ENTERED" />
  </Style>


In my C# code,

private void TEXT_ENTERED(object sender, RoutedEventArgs e)
{
  TextBox t = (TextBox)sender;
  string name = t.Text;
  Debug.WriteLine(name);
}


The TEXT_ENTERED function does not work when the Event="TextInput". When I set the Event to "TextChanged", then I get an event for each character entered in the DataGridTextColumn.

I want to capture the whole text entered - either by entered in "ABC" followed by a carriage return, a mouse click elsewhere....etc.

Any help would be appreciated.

Another funny thing is that the above works for "TextInput" in Visual Studio 2010, but not in 2008.

Thanks,

Manish
Tags: C#, WPF, User Controls, DataGrid

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900