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?
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:
Converter:
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.
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>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.