This is a migrated thread and some comments may be shown as answers.

HELP... All sorts of issues

1 Answer 66 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 01 Feb 2013, 07:33 PM
I am no expert in WPF.  I have only been using it for a year or so and I probably don't use all the proper techniques.  However I have come across a few things I just can NOT get resolved with the gridview.

Scenario:
Grid A contains documents
Grid B is a hierarchical grid that contains transactions and documents that are associated to the transactions.

1) I want to be able to do drag and drop between two grids.  I found a few sample that seemed to work to do this but nothing like what I need.  All the samples seemed to revolve around reordering or something of that nature.  What I need to do is drag a row from my document grid and associate it to a transaction in Grid B.  I can't seem to find any examples that show the capture of the row that the source is being dropped on.  This is required in order for me to be able to know which transaction to associate the document to.  Can someone please provide an example of this?

2) In Grid B, I need to be able to select a row in the child grid and remove it.  I have created a context menu on the child grid, but I had a devil of a time trying to figure out which row(s) were selected in the child grid.  I ended up listening for the contextmenuOpen and contextmenuClose events for the child grid and setting a member variable to the selectedItems in the open and back to null on the close.  Is there a better way to do this?

public static RoutedCommand RemoveRemitDocCommand = new RoutedCommand();
private ObservableCollection<object> selectedItems = null;
private void gvwChildDocs_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
    selectedItems = ((RadGridView)sender).SelectedItems;
}
  
private void gvwChildDocs_ContextMenuClosing(object sender, ContextMenuEventArgs e)
{
    selectedItems = null;
  
}
  
private void RemoveRemitDoc_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
    e.CanExecute = (selectedItems != null);
    e.Handled = true;
}
  
private void RemoveRemitDoc_Executed(object sender, ExecutedRoutedEventArgs e)
{
   //Do Something
}

3) I need to be able to set a converter on my GridB for the background of the row.  At first I wanted to just set the color if there were documents associated to the transaction.  I did this by binding the collection on the transaction to the converter value and in the converter I checked the count > 0 and returned a color accordingly.  This worked fine.  But of course you know how managers are.  Now they want to check the amounts from the documents vs the amount of the transaction.  So I bound the RelativeSource =self to the converter and changed my logic accordingly.  However, now the converter is called and works perfectly the first time, but if you sort the grid or filter it, then the converter is not called for the new order of rows and the colors are all wrong.  here is my code:
Xaml:
<telerik:RadGridView.RowStyle>
                    <Style TargetType="telerik:GridViewRow">
                        <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self},Converter={StaticResource DocColorConverter}}"></Setter>
                    </Style>
                </telerik:RadGridView.RowStyle>
Converter:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bankTransaction bt = ((GridViewRow)value).Item as bankTransaction;
            if (bt.transactionDocuments.Count > 0)
            {
                decimal tot = bt.transactionDocuments.Select(i => i.amtOwed).Sum();
 
                if (tot == bt.amount)
                    return new SolidColorBrush(Colors.LightGreen);
                else if (tot < bt.amount)
                    return new SolidColorBrush(Colors.Yellow);
                else
                    return new SolidColorBrush(Colors.Red);
            }
            else
                return new SolidColorBrush(Colors.Transparent);
        }

Those are my three problems and I need any and all help available.  Examples work best for me or corrections to my code above.  Either way is great.

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 06 Feb 2013, 11:54 AM
Hi Lee,

Let me get to your problems one by one.

1) The DragDropExamples with the GridViews that we have demonstrate the usage of the DragDropManager in various scenarios, including Drag and Drop between GridViews and/or other controls. 
You can see some of the scenarious in our examples:
http://demos.telerik.com/silverlight/#GridView/RowReorder
http://demos.telerik.com/silverlight/#DragAndDrop/TreeToGrid

You can see how you can determine the Target row there, which I believe, will help you in your efforts. 

2) The approach you have taken is correct, so you should be ok. 

3) Usually, we recommend the usage of Conditional style selectors when there is a need of differently colored rows. 

You can see an example of that here:
http://demos.telerik.com/silverlight/#GridView/Selectors/StyleSelectors/RowStyleSelector

Note that all the provided examples are available in your local copy of our WPF samples. 

Hope this helps! 

Greetings,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Lee
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or