您好我在WPF C#中使用List作为数据源。有比率,重量,数量等。
我需要在更改速率或重量值时自动更新数量.....
当我更新费率,行李,重量,金额或相应数量自动更新时,我需要的所有......
我的代码......
XAML:
<DataGrid Name="dataGridItem" LoadingRow="dataGridItem_LoadingRow" Binding.XmlNamespaceManager="{Binding}" HorizontalAlignment="Left" Margin="10,100,0,0" VerticalAlignment="Top" Height="292" Width="740" AutoGenerateColumns="False" CanUserAddRows="False">
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, Path=Header}"/>
</DataTemplate>
</DataGrid.RowHeaderTemplate>
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding I_ID}" Visibility="Hidden"></DataGridTextColumn>
<DataGridTextColumn Header="Code" Binding="{Binding I_Code}"></DataGridTextColumn>
<DataGridTextColumn Header="Grade" Binding="{Binding I_Grade}"></DataGridTextColumn>
<DataGridTextColumn Header="Particulars" Binding="{Binding I_Name}"></DataGridTextColumn>
<DataGridTextColumn Header="Rate" Binding="{Binding I_Rate}"></DataGridTextColumn>
<DataGridTextColumn Header="Bags" Binding="{Binding I_BAGS}"></DataGridTextColumn>
<DataGridTextColumn Header="Weight" Binding="{Binding I_WEIGHT_BAGS}"></DataGridTextColumn>
<DataGridTextColumn Header="Quantity" Binding="{Binding I_QUANTITY}"></DataGridTextColumn>
<DataGridTextColumn Header="Amount" Binding="{Binding I_Amount}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
C#:
public class cls_INVOICE_ITEM
{
public int _I_ID;
public string _I_Code;
public string _I_Grade;
public string _I_Name;
public decimal _I_Rate;
public decimal _I_BAGS = 0;
public decimal _I_WEIGHT_BAGS = 0;
public decimal _I_QUANTITY;
public decimal _I_RATE = 0;
public decimal _I_Amount;
public int I_ID { get { return _I_ID; } set { _I_ID = value; } }
public string I_Code { get { return _I_Code; } set { _I_Code = value; } }
public string I_Grade { get { return _I_Grade; } set { _I_Grade = value; } }
public string I_Name { get { return _I_Name; } set { _I_Name = value; } }
public decimal I_Rate { get { return _I_Rate; } set { _I_Rate = value; } }
public decimal I_BAGS { get { return _I_BAGS; } set { _I_BAGS = value; } }
public decimal I_WEIGHT_BAGS { get { return _I_WEIGHT_BAGS; } set { _I_WEIGHT_BAGS = value; } }
public decimal I_QUANTITY { get { return I_BAGS * I_WEIGHT_BAGS; } set { _I_QUANTITY = I_BAGS * I_WEIGHT_BAGS; } }
public decimal I_Amount { get { return I_BAGS * I_WEIGHT_BAGS * I_Rate; } set { _I_Amount = I_BAGS * I_WEIGHT_BAGS * I_Rate; } }
}
static List<cls_INVOICE_ITEM> lstIOrder = new List<cls_INVOICE_ITEM>();
DataTable DT = BLL.Get_Item_By_ItemCode(txtItemCode.Text);
Function Which BindData :
if(DT.Rows.Count > 0)
{
lstIOrder.Add(new cls_INVOICE_ITEM() { I_ID = int.Parse((DT.Rows[0]["I_ID"].ToString())), I_Code = DT.Rows[0]["I_Code"].ToString(), I_Grade = DT.Rows[0]["I_Grade"].ToString(), I_Name = DT.Rows[0]["I_Name"].ToString() });
}
dataGridItem.ItemsSource = null;
dataGridItem.ItemsSource = lstIOrder;