{"id":8386,"date":"2024-04-02T12:47:17","date_gmt":"2024-04-02T11:47:17","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=8386"},"modified":"2024-04-02T12:47:19","modified_gmt":"2024-04-02T11:47:19","slug":"devexpress-xaf-get-selected-items-in-listview","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/devexpress-xaf-get-selected-items-in-listview\/","title":{"rendered":"DevExpress XAF get selected items in Listview"},"content":{"rendered":"\n<p>In List View data access modes InstantFeedback, InstantFeedbackView, or ServerView the selected rows\/objects are of the type ObjectRecord. In other modes the real type is available. Below a helper function to use one method for all modes.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"csharp\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">using DevExpress.ExpressApp;\r\n\r\npublic static List&lt;T> GetSelectedObjects&lt;T>(IEnumerable selectedObjects, IObjectSpace os)\r\n{\r\n    var selectedItemList = selectedObjects.OfType&lt;ObjectRecord>()\r\n        .Where(x => x.ObjectType == typeof(T))\r\n        .Select(x => os.GetObjectByKey&lt;T>(x.ObjectKeyValue))\r\n        .OfType&lt;T>();\r\n    return selectedItemList.Concat(selectedObjects.OfType&lt;T>()).ToList();\r\n}\r\n\r\nprivate void MyAction_Execute(object sender, SimpleActionExecuteEventArgs e)\r\n{\r\n    var productList = GetSelectedObjects&lt;Product>(ListView.SelectedObjects, ObjectSpace);\r\n    foreach (var product in productList)\r\n    {\r\n        \/\/ do something\r\n    }\r\n    ObjectSpace.Refresh();\r\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In List View data access modes InstantFeedback, InstantFeedbackView, or ServerView the selected rows\/objects are of the type ObjectRecord. In other modes the real type is available. Below a helper function to use one method for all modes.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8386","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/8386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=8386"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/8386\/revisions"}],"predecessor-version":[{"id":8387,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/8386\/revisions\/8387"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=8386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=8386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=8386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}