This question is locked. New answers and comments are not allowed.
What is the proper way to select a cell from code-behind with the RadDataGrid set up using
SelectionMode="Single" SelectionUnit="Cell"
to allow only single-cell selection?
I tried creating a new instance of DataGridCellInfo with the selected item and its DataGridColumn as the parameter and calling radDataGrid.SelectCell(), but that doesn’t seem to actually select the cell in the UI; the reason probably is that this new instance of DataGridCellInfo cannot be matched to any instance already in the grid.
I couldn’t find any way to query the grid’s cells using some kind of LINQ statement, and the documentation on this subject is too scarce.
Please advise.
SelectionMode="Single" SelectionUnit="Cell"
to allow only single-cell selection?
I tried creating a new instance of DataGridCellInfo with the selected item and its DataGridColumn as the parameter and calling radDataGrid.SelectCell(), but that doesn’t seem to actually select the cell in the UI; the reason probably is that this new instance of DataGridCellInfo cannot be matched to any instance already in the grid.
I couldn’t find any way to query the grid’s cells using some kind of LINQ statement, and the documentation on this subject is too scarce.
Please advise.
7 Answers, 1 is accepted
0
Hello Yuri,
Thank you for your question.
You can select a cell with the approach that you have described. I have prepared an example that works as expected in our local tests. Could you check if this is working properly on your side too?
Also, any feedback is highly appreciated and we will consider to make an example in the Selection article of our online documentation.
I am looking forward to your reply.
Ivaylo Gergov
Telerik
Thank you for your question.
You can select a cell with the approach that you have described. I have prepared an example that works as expected in our local tests. Could you check if this is working properly on your side too?
Also, any feedback is highly appreciated and we will consider to make an example in the Selection article of our online documentation.
I am looking forward to your reply.
Regards,
Ivaylo Gergov
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Yuri
Top achievements
Rank 1
answered on 04 Jul 2013, 02:08 PM
This whole paradigm goes against everything the MVVM pattern stands for.
As a developer, I should be able to have the underlying data completely agnostic of its View (in our case, the RadDataGrid).
What I’d like to see is the implementation that allows me to simply define a two-way binding of RadDataGrid’s SelectedItem property to its DataContext’s SelectedItem property. The latter, of course, needs to be of a proprietary business logic type, not a DataGridCellInfo.
As far as I can tell, this would work for SelectionUnit=”Row”, but is simply impossible at the moment with the SelectionUnit set to “Cell”.
I definitely don’t want to make my ViewModel’s SelectedItem typed as DataGridCellInfo, because this would bring the View into the ViewModel - a huge “no-no”.
As a side note, creating a converter won’t help either because there’s no way for it to get hold of the RadDataGrid instance and/or its columns in order to populate the second parameter of the DataGridCellInfo constructor.
Hence, the only way to select a cell programmatically is from code-behind, which looks more like a hack than like a production-level programming.
Please advise.
As a developer, I should be able to have the underlying data completely agnostic of its View (in our case, the RadDataGrid).
What I’d like to see is the implementation that allows me to simply define a two-way binding of RadDataGrid’s SelectedItem property to its DataContext’s SelectedItem property. The latter, of course, needs to be of a proprietary business logic type, not a DataGridCellInfo.
As far as I can tell, this would work for SelectionUnit=”Row”, but is simply impossible at the moment with the SelectionUnit set to “Cell”.
I definitely don’t want to make my ViewModel’s SelectedItem typed as DataGridCellInfo, because this would bring the View into the ViewModel - a huge “no-no”.
As a side note, creating a converter won’t help either because there’s no way for it to get hold of the RadDataGrid instance and/or its columns in order to populate the second parameter of the DataGridCellInfo constructor.
Hence, the only way to select a cell programmatically is from code-behind, which looks more like a hack than like a production-level programming.
Please advise.
0
Hi Yuri,
Thank you for getting back to us.
As the RadDataGrid represents 2-dimensional (2D) data and a cell is defined by the intersection of a row(business object) and a column, in order to execute a cell selection, it will be necessary to pass not only a business object, but also a column. Could you please elaborate a bit more on your specific scenario and how exactly would you expect to make a cell selection(what is the information that you expect to be translated into a cell)?
I am looking forward to your reply.
Ivaylo Gergov
Telerik
Thank you for getting back to us.
As the RadDataGrid represents 2-dimensional (2D) data and a cell is defined by the intersection of a row(business object) and a column, in order to execute a cell selection, it will be necessary to pass not only a business object, but also a column. Could you please elaborate a bit more on your specific scenario and how exactly would you expect to make a cell selection(what is the information that you expect to be translated into a cell)?
I am looking forward to your reply.
Regards,
Ivaylo Gergov
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Yuri
Top achievements
Rank 1
answered on 11 Jul 2013, 01:19 PM
Hi Ivaylo,
I'm afraid I will have to respectfully disagree with your assertion that only the rows are mapped to the business objects while the cells aren't.
The data that is eventually displayed in the grid is there, all in the business object. After all, when setting RadDataGrid's ItemsSource via binding I don't necessarily have to specify anything beyond the actual data (e.g. an ObservableCollection). I may (in case there is some complex logic involved in rendering the columns), but I don't *have* to (such as in case automatic generation of columns from the data is allowed).
In my specific scenario, I have the data that is represented by an ObservableCollection of aggregated results; each aggregated result is a series of data objects, one for each date. Hence, the different result types constitute the rows and the dates - the columns, with their intersection making a single cell. Each such cell is mapped to a unique instance of a data object. What I would like to see is a two-way binding of the SelectedItem property with SelectionUnit="Cell" and SelectionMode="Single" (or the same for SelectedItems if multiple cells selection is allowed).
Conceptually, I am looking at 2D data, tabular by its nature, which is mapped to the grid. Essentially, I want to have the grid "mapped back" to its underlying data. From my perspective, not only a row, but also a column and especially a cell are all business objects.
Does this clarify my question?
I'm afraid I will have to respectfully disagree with your assertion that only the rows are mapped to the business objects while the cells aren't.
The data that is eventually displayed in the grid is there, all in the business object. After all, when setting RadDataGrid's ItemsSource via binding I don't necessarily have to specify anything beyond the actual data (e.g. an ObservableCollection). I may (in case there is some complex logic involved in rendering the columns), but I don't *have* to (such as in case automatic generation of columns from the data is allowed).
In my specific scenario, I have the data that is represented by an ObservableCollection of aggregated results; each aggregated result is a series of data objects, one for each date. Hence, the different result types constitute the rows and the dates - the columns, with their intersection making a single cell. Each such cell is mapped to a unique instance of a data object. What I would like to see is a two-way binding of the SelectedItem property with SelectionUnit="Cell" and SelectionMode="Single" (or the same for SelectedItems if multiple cells selection is allowed).
Conceptually, I am looking at 2D data, tabular by its nature, which is mapped to the grid. Essentially, I want to have the grid "mapped back" to its underlying data. From my perspective, not only a row, but also a column and especially a cell are all business objects.
Does this clarify my question?
0
Hello Yuri,
Thank you for elaborating on this.
RadDataGrid does not work in this way -- in our view it is conceptually closer to an ItemsControl that visualizes a list of business objects (here the row visualization is a bit more advanced as it renders multiple columns but at its core it is the same basic principle of the ItemsControl). That is why the column, and the cell cannot be business objects in the same sense a row is as only the row is a valid representation of the data items passed as ItemsSource to the control. Note that there are other types of controls like spreadsheet or pivot grid that might operate under different assumptions about the cell / column / row entities but they cover different scenarios that are out of the scope of RadDataGrid.
We are sorry that this concept does not correspond to your opinion about how the control should operate in this scenario but at this point we cannot add anything else besides the suggestions Ivaylo mentioned in his previous replies.
Giuseppe
Telerik
Thank you for elaborating on this.
RadDataGrid does not work in this way -- in our view it is conceptually closer to an ItemsControl that visualizes a list of business objects (here the row visualization is a bit more advanced as it renders multiple columns but at its core it is the same basic principle of the ItemsControl). That is why the column, and the cell cannot be business objects in the same sense a row is as only the row is a valid representation of the data items passed as ItemsSource to the control. Note that there are other types of controls like spreadsheet or pivot grid that might operate under different assumptions about the cell / column / row entities but they cover different scenarios that are out of the scope of RadDataGrid.
We are sorry that this concept does not correspond to your opinion about how the control should operate in this scenario but at this point we cannot add anything else besides the suggestions Ivaylo mentioned in his previous replies.
Regards,
Giuseppe
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Yuri
Top achievements
Rank 1
answered on 16 Jul 2013, 02:59 PM
Hi Giuseppe,
Thank you for the explanation, now I understand the root cause of these limitations, and that only the rows are the actual items.
Still, even within the confines of this implementation, I think there should be a way to get/set the column for the selected item (row) to access the cell at their intersection, and this way should not involve visual objects, operating on logical abstractions instead.
Even an integer column index would be better than having to create a DataGridColumn object.
What do you think - will this be possible to implement?
Thank you for the explanation, now I understand the root cause of these limitations, and that only the rows are the actual items.
Still, even within the confines of this implementation, I think there should be a way to get/set the column for the selected item (row) to access the cell at their intersection, and this way should not involve visual objects, operating on logical abstractions instead.
Even an integer column index would be better than having to create a DataGridColumn object.
What do you think - will this be possible to implement?
0
Hi Yuri,
Indeed, the ability to create a DataGridCellInfo object without specifying the actual DataGridColumn instance makes sense and would be useful. However, we believe that referencing a DataGridColumn through its DataGridColumn.Name property is more appropriate than accessing it through its integer index because the index is not a permanent value (for example in case of column reordering). Our development team will try to implement this feature for our Q3 2013 official release.
If you have any other questions or suggestions do not hesitate to contact us again. Also, I have updated your Telerik points as a token of gratitude for your valuable feedback.
Ivaylo Gergov
Telerik
Indeed, the ability to create a DataGridCellInfo object without specifying the actual DataGridColumn instance makes sense and would be useful. However, we believe that referencing a DataGridColumn through its DataGridColumn.Name property is more appropriate than accessing it through its integer index because the index is not a permanent value (for example in case of column reordering). Our development team will try to implement this feature for our Q3 2013 official release.
If you have any other questions or suggestions do not hesitate to contact us again. Also, I have updated your Telerik points as a token of gratitude for your valuable feedback.
Regards,
Ivaylo Gergov
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.