open a property window on gridrow click

2 Answers 112 Views
Miscellaneous
Sudeshna
Top achievements
Rank 1
Sudeshna asked on 22 Jan 2023, 07:54 PM
I need to open a new property window with no/specific data if no row is selected and if any row is selected open property window with that gridrow data. How can i do that.
Dess | Tech Support Engineer, Principal
Telerik team
commented on 23 Jan 2023, 08:11 AM

Hello, Sudeshna,

According to the provided information, it is not clear what is the exact Telerik product that you are currently using. Could you please specify this? Thus, we can move the question to the respective product forum. Thank you.

Sudeshna
Top achievements
Rank 1
commented on 26 Jan 2023, 04:15 AM

Hello Dess,

using Telerik.UI.for.Wpf.NetCore.Xaml , 

This is my Grid(item.xaml)

<telerik:RadGridView
                    Name="ItemGrid"
                    CanUserSearch="True"
                    Visibility="Visible"
                    ItemsSource="{Binding Templates, Mode=OneWay}"
                    MaxHeight="650" Margin="10,70,10,50" MinHeight="320">
            <telerik:RadGridView.Columns>
                <telerik:GridViewColumn Header="" >
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadButton Content="Edit"  
                                               Visibility="Hidden"
                         Command="{Binding Path=ItemOpenCommand}"
                         CommandParameter="{Binding Path=Item}" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
                <telerik:GridViewDataColumn Name ="ItemNumber" DataMemberBinding="{Binding Path=ItemNumber}" Header="Item Number"  />
                <telerik:GridViewDataColumn Name ="Diameter" DataMemberBinding="{Binding Path=Diameter}" Header="Item Diameter,in"  />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

 

Now I need to open a rad propertywindow on clicking any row with the existing data. for that i have added a button on the grid (edit). 

this is my item.xaml.cs file

  public vmItem viewModel { get; set; }
        public vwItem()
        {
            viewModel = new vmItem();
            this.DataContext = viewModel;

            InitializeComponent();
        }
        private RelayCommand<DataRow> _itemOpenCommand;
        public RelayCommand<DataRow> ItemOpenCommand
        {
            get
            {
                return this._itemOpenCommand ?? (_itemOpenCommand = new RelayCommand<DataRow>((dataRow) =>
                {
                    Pulley pulley = this.viewModel.GetSingleItemFromDataRow(dataRow);
                   ////here need to write the code to open the property window
                }));
            }
        }
    }

ViewModel:

 public Item GetSingleItemFromDataRow(DataRow dataRow)
        {
            return this.Model.GetSingleItem((int)dataRow[0]);

        }

but while running I am getting error:

ItemOpenCommand RadButton.Command ICommand ItemOpenCommand property not found on object of type DataRow.

instead of button if it's easier to do on row click ,that will also work. 

Name of the propertywindow vwItemPropertyWindow.

Actually Item is on navigation menu.

What i am missing.

2 Answers, 1 is accepted

Sort by
0
Sudeshna
Top achievements
Rank 1
answered on 25 Jan 2023, 08:52 PM | edited on 26 Jan 2023, 04:16 AM

Hello Dess,

Please see my comment 

0
Dilyan Traykov
Telerik team
answered on 30 Jan 2023, 01:57 PM

Hello Sudeshna,

Thank you for the provided code snippets.

Based on them, I set up a small sample project to demonstrate how you can pass the command correctly.

The reason for the error you described is that the DataContext of each individual row (and respectively cell) is the underlying data item. So as the error suggests, the binding is looking for an ItemOpenCommand on the DataRow object which simply isn't present.

Instead, you can set up a RelativeSource binding and point it to the object that holds the command - the vwItem class in this case.

As for handling this when the row is selected, you can handle the SelectionChanged event of the control. For the purpose, however, you'd need to set up an additional command as accessing the selected item in this case needs to be performed via the SelectionChangeEventArgs of the event. Please note that I've used the EventToCommandBehavior helper class to bind the event to the new custom command.

Please have a look at the attached project and let me know if a similar approach would work in your original application. I will be awaiting your reply.

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Miscellaneous
Asked by
Sudeshna
Top achievements
Rank 1
Answers by
Sudeshna
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or