How to Add Row of a WPF Listview when Press “Enter” Key in Listview Column

I saw many application software provides this kind of facilities.But WPF is new for everybody.So i think for doing this in c# WPF.In this post i will discuss about this solution.
My ListView contain one column which is binding by a object.At first i make a Listview which Column field contain textbox.Here is the XAML Code.

<ListView Height="101" Margin="289,318,0,0" Name="lvItem" VerticalAlignment="Top" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Left" Width="215">
            <GridViewColumn Header="Item Name"  Width="80">
                <GridViewColumn.CellTemplate >
                        <TextBox Name="txtForAddRow"  Text="{Binding Path=ItemName}" 
                                 Margin="-6,0,-6,0" KeyDown="txtForAddRow_KeyDown" />

The entity class definition is here

public class EItemCategory
public string ItemName { get; set; }

Now the cs Code for add row in Listview

private void txtForAddRow_KeyDown(object sender, KeyEventArgs e)
EItemCategory obj = new EItemCategory();

If you have any query about this topic please leave a comment.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: