如何以编程方式设置RadGridView列的值

时间:2016-02-22 05:03:33

标签: c# silverlight telerik radgridview

我有一个RadGridView,一旦用户点击Insert按钮,我想为新生成的行设置Date列的值。如何将其值设置为System.Date.Today

RadGridview的Xaml:

<telerik:RadGridView VerticalAlignment="Top" 
                      Name="grdProductGrid"
                      AutoGenerateColumns="False"
                      RowEditEnded="OnRowEditEnded"
                      CellValidating="OnCellValidating"
                      BeginningEdit="OnBeginningEdit">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn x:Name="ID" 
                                DataMemberBinding="{Binding ProductID}" 
                                Header="ID" />

        <telerik:GridViewDataColumn x:Name="Code" 
                                DataMemberBinding="{Binding Code}" 
                                Header="Code" />

        <telerik:GridViewDataColumn x:Name="Date" 
                                DataMemberBinding="{Binding Path=Date, Mode=OneWay, StringFormat='{}{0:dd/MM/yyyy}'}" 
                                Header="Effective from" />

    </telerik:RadGridView.Columns>
</telerik:RadGridView>

Insert点击事件处理程序:

private void OnInsertClick(object sender, RoutedEventArgs e)
{
  this.grdProductGrid.BeginInsert();
}

1 个答案:

答案 0 :(得分:0)

在您的AddingNewDataItem事件中,您将e.NewObject设置为等于网格绑定的新对象类型...然后设置Date属性。

lvData.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        final Dialog dialog = new Dialog(c);
        //getting value from listview after click

        String nm = (String) ((TextView) view.findViewById(R.id.tvMenuKuNama)).getText();
        int gbr = (int) ((ImageView) view.getTag(R.id.ivMenuKuImg)).getId();
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(R.layout.detail_menu);
        //inisialisasi menu item

        ImageView detailImg = (ImageView)dialog.findViewById(R.id.detailMenuImg);
        TextView detailNamaMenu = (TextView)dialog.findViewById(R.id.detailNamaMenu);
        detailNamaMenu.setText(nm);
        imageLoader.DisplayImage(NurHelper.BASE_URL_IMAGE +gbr, detailImg);

        dialog.show();

    }
});

希望这会有所帮助。 :)