This is a migrated thread and some comments may be shown as answers.

how can i create new row on runtime

1 Answer 45 Views
GridView
This is a migrated thread and some comments may be shown as answers.
arman
Top achievements
Rank 1
arman asked on 25 Jun 2018, 07:08 AM

hi all

I convert my project from windows form to wpf

and I use this code in the windows form

 

radGridViewCostList.Rows.Clear();    

       foreach (var cost in _costList)      

     {             

  var newRow = radGridViewCostList.Rows.NewRow();         

      newRow.Cells["cost"].Value = cost.Name;       

        newRow.Cells["id"].Value = cost.ID;         

                    newRow.Cells["description"].Value = cost.Description;  

             newRow.Cells["proposedValue"].Value = cost.ProposedValue;      

 

              radGridViewCostList.Rows.Add(newRow);    

       }

 

in wpf  radgrid dose not have Row Property

I use this code bot can not find GridViewCell

 

uxRadGridView_CostTypeList.BeginInsert();

var newRow = uxRadGridView_CostTypeList.ChildrenOfType<GridViewNewRow>();   

      if (newRow == null) {     return; }  

        var cells = new.RowFirstOrDefault().ChildrenOfType<GridViewCell>();

var costCell_ID = newRow.FirstOrDefault().ChildrenOfType<GridViewCell>().Where(c => c.Name.ToString() == uxGridViewColumn_id.Name).First(); costCell_ID.Content =" cost.ID";

 

xaml code :

<telerik:RadGridView x:Name="uxRadGridView_CostTypeList" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" IsReadOnly="True" AutoGenerateColumns="False" ShowGroupPanel="False" NewRowPosition="Top">                     <telerik:RadGridView.Columns>                 <telerik:GridViewColumn x:Name="uxGridViewColumn_row" UniqueName="row" Header="ردیف" Width="45" MaxWidth="45" MinWidth="35"/>                 <telerik:GridViewColumn x:Name="uxGridViewColumn_id" UniqueName="id" Header="کد" MaxWidth="90" MinWidth="50" Width="76"/>                 <telerik:GridViewColumn x:Name="uxGridViewColumn_cost" UniqueName="cost" Header="نام هزینه" MaxWidth="300" MinWidth="150" Width="227"/>                 <telerik:GridViewColumn x:Name="uxGridViewColumn_category" UniqueName="category" Header="گروه" MaxWidth="100" Width="151"/>                 <telerik:GridViewColumn x:Name="uxGridViewColumn_proposedValue" UniqueName="proposedValue" Header="قیمت پیش فرض" MaxWidth="110" MinWidth="110" Width="110"/>                 <telerik:GridViewColumn x:Name="uxGridViewColumn_Accounting" UniqueName="Accounting" Header="سرفصل مرتبط" MinWidth="80" Width="153"/>                 <telerik:GridViewColumn x:Name="uxGridViewColumn_description" UniqueName="description" Header="توضیحات" MinWidth="150" Width="299"/>             </telerik:RadGridView.Columns>                 </telerik:RadGridView>

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 26 Jun 2018, 03:12 PM
Hi arman,

There are two options to add rows in RadGridView. The first one is to insert items in its ItemsSource collection. You can read how to data bind the gridview and set its ItemsSource in the Populating with Data section in the documentation.

The other option is to use the BeginInsert() method of RadGridView. You can read how to use this in the Adding New Entries article.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
arman
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or