Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
770
How to add new row in webgrid like row adding in excel
posted

Hello,

 I want to add/insert new empty row on the top of selected row as in excel sheet.

I have alredy one record binded in webgrid. I have shown popup to and button to Add new row when click in cell. Now if click on Add new row button i want to add new row on top of selected row.

I need to add textbox in each cell to edit that values.

For already binded webgrid my code is as below

 

 

 

 

 

 

 

 

 

 

CellETemp =

 

 

new StringBuilder

();

CellETemp.Append(

 

 

"<DataTemplate "

);

CellETemp.Append(

 

 

"xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' "

);

CellETemp.Append(

 

 

"xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> "

);

CellETemp.Append(

 

 

" <Grid x:Name=\"LayoutRoot\" Background=\"Transparent\" Width=\"119\">"

);

CellETemp.Append(

 

 

" <Grid.ColumnDefinitions>"

);

CellETemp.Append(

 

 

" <ColumnDefinition x:Name=\"ColValue\" Width=\"117\"></ColumnDefinition>"

);

CellETemp.Append(

 

 

" </Grid.ColumnDefinitions>"

);

CellETemp.Append(

 

 

" <TextBox x:Name=\"txtValue\" HorizontalAlignment=\"Center\" TextAlignment=\"Right\" Text=\"{Binding " + strHeader + " ,Mode=TwoWay}\" VerticalAlignment=\"Center\" Grid.Column=\"0\" Height=\"20\" Width=\"105\" Background=\"#FFF7F8F8\"></TextBox>"

);

CellETemp.Append(

 

 

" </Grid>"

);

CellETemp.Append(

 

 

" </DataTemplate>"

);

 

 

 

So how can i do that

 

Thanks,

Nandu.

Parents
No Data
Reply
  • 5595
    posted

    Hi,

    To insert a row above the currently active cell, you could use a code similar to the following two methods:

            void GetActiveRowInfo(XamGrid grid, out RowCollection rows, out Row row)

            {

                row = null;

                rows = null;

     

                if (grid.ActiveCell == null)

                    return;

     

                row = grid.ActiveCell.Row as Row;

                rows = grid.GetRowCollection(row);

            }

      

            void InsertAboveActiveRow(XamGrid grid)

            {

                RowCollection rows = null;

                Row existingRow = null;

                Row insertRow = null;

     

                grid.GetActiveRowInfo(out rows, out existingRow);

     

                if ((rows == null) || (existingRow == null))

                    throw new InvalidOperationException("Could not find the Row to insert above.");

     

                insertRow = rows.CreateItem();

                rows.Insert(existingRow.Index, insertRow);

            }

     

     

     

     HTH,

Children
No Data