-1

I have a ListView with with a Gridview and for a number of the columns I need to have two rows of data. the top lone has the items amount and the bottom with that amount multiplied by the quantity. I can get the top amount to show up just fine, but the bottom amount does not show. I have place breaks in the back end parts to make sure that the correct amount is being pulled and it is returning the right number, but it does not show up when I run the program.

<Window x:Class="Listviewissue.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525"
    xmlns:local="clr-namespace:Listviewissue">
<Window.Resources>
    <local:AmountQuantityConverter x:Key="AmtQConverter"/>

</Window.Resources>
<Grid >
    <ListView Name="lstBids" Margin="3" Grid.ColumnSpan="4" Grid.Row="1" MinHeight="200">
        <ListView.View>
            <GridView>
                <GridViewColumn Header ="Q">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Margin="1"  Text="{Binding Path=Quantity}"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header ="Sub Name" Width="100">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Margin="1"  Text="{Binding Path=SubContractorName}"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header ="Sub Amt">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Margin="1"  Text="{Binding Path=SubContractorAmount, StringFormat={}{0:C}}"/>
                                <TextBlock Margin="1">
                                    <TextBlock.Text>
                                        <MultiBinding Converter="{StaticResource AmtQConverter}" StringFormat="{}{0:C}}">
                                            <Binding Path="Quantity" />
                                            <Binding Path="SubContractorAmount"/>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>

Here are the back cs File

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace Listviewissue
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        LoadBox();
    }

    private void LoadBox()
    {
        BidSheet bs = new BidSheet();
        bs.ReadFromDatabase("Test");
       lstBids.ItemsSource = bs.BidSheetLineItems;
    }
}

public class AmountQuantityConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        // Return the total value of all the items in stock.
        decimal quantity = decimal.Parse(values[0].ToString());
        decimal amt = decimal.Parse(values[1].ToString());
        decimal result = (quantity * amt);
        return result;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}



public class BidSheet
{
    public BidSheet()
    {
        BidSheetLineItems = new BidSheetLineItems();
    }
    public BidSheetLineItems BidSheetLineItems { get; set; }

    public void ReadFromDatabase(string file)
    {
        BidSheet bidSheet = new BidSheet();
        System.Xml.Serialization.XmlSerializer reader =
        new System.Xml.Serialization.XmlSerializer(typeof(BidSheet));
        System.IO.StreamReader xmlFile = new System.IO.StreamReader(
            file + ".xml", true);
        bidSheet = (BidSheet)reader.Deserialize(xmlFile);

        BidSheetLineItems = bidSheet.BidSheetLineItems;

        xmlFile.Close();
    }
    }


public class BidSheetLineItems : List<BidSheetLineItem>
{


}

public class BidSheetLineItem
{
    public BidSheetLineItem()
    {
        Quantity = 0;
        SubContractorName = "";
        SubContractorAmount = 0;
    }
    public double Quantity { get; set; }
    public string SubContractorName { get; set; }
    public decimal SubContractorAmount { get; set; }
}

}

And here is a xml file with some data

<?xml version="1.0" encoding="utf-8"?>
<BidSheet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<BidSheetLineItems>
    <BidSheetLineItem>
      <Quantity>1</Quantity>
      <SubContractorName>Harry</SubContractorName>
  <SubContractorAmount>50</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>5</Quantity>
  <SubContractorName>Arther</SubContractorName>
  <SubContractorAmount>248120</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>2</Quantity>
  <SubContractorName>Bill</SubContractorName>
  <SubContractorAmount>340000</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>3</Quantity>
  <SubContractorName>Fred</SubContractorName>
  <SubContractorAmount>248120</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>5</Quantity>
  <SubContractorName>Ron</SubContractorName>
  <SubContractorAmount>248120</SubContractorAmount>
</BidSheetLineItem>
<BidSheetLineItem>
  <Quantity>1</Quantity>
  <SubContractorName>Goerge</SubContractorName>
  <SubContractorAmount>60</SubContractorAmount>
</BidSheetLineItem>
  </BidSheetLineItems>
</BidSheet>

Thanks in advance and let me know if you need any more info to help me out.

SSJTDK
  • 3
  • 5
  • 1
    This is not a good code example. Please provide a good [mcve] that reliably reproduces the problem, and a precise description of what the code does and what you want it to do instead. Reduce your code down to the bare minimum of what's needed to reproduce the problem (e.g. no more columns and properties than the minimum to show the problem), and provide a _complete_ code example that can be compiled and run without any additional effort by the reader. – Peter Duniho Apr 30 '16 at 00:02
  • I agree with Peter. Please provide a good code example so that others could easily understand your issue. Please don't post the entire code here which may confuse others. – ViVi Apr 30 '16 at 03:41
  • Okay, @PeterDuniho, I reduced the columns down to just one with the issue (sub Amt), the quantity(Q), and an identifier (Sub Name) . The problem is that sub amount only show the top amount and the bottom is just blank. It is supposed to be the amount multiplied by the quantity. – SSJTDK May 02 '16 at 13:56

1 Answers1

0

Okay, I figured it out. I had

<MultiBinding Converter="{StaticResource AmtQConverter}" StringFormat="{}{0:C}}">

and it needed to be

<MultiBinding Converter="{StaticResource AmtQConverter}"  StringFormat="{}{0:C}">
SSJTDK
  • 3
  • 5