I need a DataGrid column to receive users only numbers in the rows (cells) and after clicking on the button, multiplication calculations are performed between cells on the same row and different columns. The DataGrid is populated as follows to the class below through the LINQ tool ... The users column is the "No. Stops", it needs to be multiplied by the "Time (min)" column.
But the values that the user types in the cells do not stay in them , what is typed is disappearing . As soon as it leaves the cell the value is erased, why?
And as for the calculation logic, I'm only able to add the cells of a column.
Who can help thank you. Below I put the sequence of commands ...
LINQ Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TRSSystem.AcessoDados
{
public class tabMaquinaParadaAcesso
{
//Consultar pela MAQUINA no Banco pela estrutura LINQ TO SQL Server
public static List<tabMaquinaParada> Consultar_OnlyMaquina(string pMaquina, string pTipo)
{
TRSSystemDataClassesDataContext oDB = new TRSSystemDataClassesDataContext();
List<tabMaquinaParada> aMaquina = (from Selecao in oDB.tabMaquinaParadas where Selecao.Maquina == pMaquina && Selecao.Sacaria == pTipo select Selecao).ToList<tabMaquinaParada>();
return aMaquina;
}
}
}
XMAL:
<DataGrid x:Name="dataGridPrdMaquina_ApontPrd" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="4,7,0,0" VerticalAlignment="Top" Height="103" Width="577" GridLinesVisibility="Horizontal" SelectionUnit="Cell" VerticalContentAlignment="Center" AutoGenerateColumns="False" SelectionMode="Single" AlternatingRowBackground="{DynamicResource SelectedBackgroundBrush}" HorizontalGridLinesBrush="{DynamicResource MouseOverBrush}" VerticalGridLinesBrush="{DynamicResource MouseOverBrush}" HorizontalContentAlignment="Center">
<DataGrid.Columns>
<DataGridTextColumn Header="Código" Width="Auto" Binding={Binding CodigoParada}" IsReadOnly="True"/>
<DataGridTextColumn Header="Descrição da Parada" Width="Auto" Binding="{Binding DescricaoParada}" IsReadOnly="True"/>
<DataGridTextColumn Header="Tempo (min)" Width="Auto" Binding="{Binding TempoParada}" IsReadOnly="True"/>
<DataGridTextColumn Header="Tipo" Width="Auto" Binding="{Binding TipoParada}" IsReadOnly="True"/>
<DataGridTextColumn Header="Nº Paradas" Width="Auto" IsReadOnly="False" FontFamily="Calibri">
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox">
<Setter Property="MaxLength" Value="2"/>
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
LostFocus event of a Combox, when the list is loaded:
private void CarregarParadas_ApontaPrd(object sender, RoutedEventArgs e)
{
try
{
dataGridPrdMaquina_ApontPrd.ItemsSource = TRSSystem.AcessoDados.tabMaquinaParadaAcesso.Consultar_OnlyMaquina(CmBox_MaquinaApontaPrd.Text, CmBox_TipoApontaPrd.Text);
}
catch(Exception error)
{
MessageBox.Show("Erro de Compilação, contacte o Administrador do Sistema." + error, "Erro de Compilação", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
PreviewTextInput Event - Get Integer Only
private void SomenteInt_ListViewPrdPadrao_ApontaPrd(object sender, TextCompositionEventArgs e)
{
if (!char.IsDigit(e.Text, e.Text.Length - 1))
e.Handled = true;
}
Calculation Button
How do I multiply the values in the Time column by the number of Stops?
//Aqui apenas Soma os valores de uma coluna apenas:
private void CalcularTempoEfetivo_ApontPrd(object sender, RoutedEventArgs e)
{
int somarColuna = 0;
for (int i = 0; i < dataGridPrdMaquina_ApontPrd.Items.Count; i++)
{
tabMaquinaParada Dados = (tabMaquinaParada)dataGridPrdMaquina_ApontPrd.Items[i];
somarColuna = somarColuna + Dados.TempoParada;
}
txtTempoEfetivo_ApontaPrd.Text = Convert.ToString(somarColuna);
}