سؤال

I have been playing around with the WPF GridView control (DesktopUI not Silverlight) and I need to be able to select a specific row and only have the data for that row returned for viewing within a new control such as a list box.

In addition, once the data from a row has been selected the ability to select or add additional data to my listbox needs to be disabled. The use case here is that a user may only select one row/record to export or publish.

In looking through some of the telerik samples I have seen a few similar examples but nothing that fully supported this use case.

Has anyone had expereince with these controls and to know if this can this be accomplished within a WPF gridView. I haven't had much luck with their documentation and I have tried to use some of the inherit features like the GridViewSelectColumn property (which generates a checkbox in a column but I haven't had any luck invoking commands when a checkbox is selected/checked). Instead of the checkbox should I look to use a button and add that as a stand alone column that the user can click such as:

If anyone can provide a code sample of how to invoke the selection of one row of data as well as how to disable the seletion of additional rows once a single row has been selected I would appreciate it. For the disabling I assume that the CanUserSelect property needs to be set to false once an item has been selected but I have yet to successfully been able to invoke anything using the GridViewSelectColumn.

Any samples or points of reference would be appreciated.

Thank you

هل كانت مفيدة؟

المحلول

I realize this is an old post . But I wanted to address this in the hopse it will help others. For this project I wanted to have the ability to select records for a spcecific row within a grid view. The Telerik GridView returned 5 columns but the collection (returned from a WCF service) actually contained up to 30 columns.

I'm not going to address the binding of data here only how the selection was setup. Also this sampel does not follow a pattern (such as MVVM) so for quick explination the code was placed in the xaml code-behind.

First, I needed to register CollectionChangedEvent Handlers. What this did was everytime I selected a row wihtin the Grid view it generated an in-memory collection of all the items based upon the selected row.

this.myGridView.Loaded += (o, e) =>
      {
          this.myGridView.SelectedItems.CollectionChanged += new NotifyCollectionChangedEventHandler(SelectedItem_CollectionChanged);
      };

And for the SelectedItem_Collection Changed Event

        void Item_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.Action == NotifyCollectionChangedAction.Add)
        {
            var index = e.NewItems[0] as myWCFService.Index;
            currentItem = index.Item;
        }
    }

Basically what happens here is when a record selection is detected the items from the selected row(including all items not shown in grid) This is done by seting index = to the e.NewItems[0] from my webservice which is then added to new collection (currentItem) in-memory.

Note: currentItem was declared in the main class as:

 public myWCFService.Item currentItem;

Once this was done I had the ability to pass the data from the selected row (stored in the currentItem collection) to other collections/controls

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top