Listview with an empty and editable column

Asked

Viewed 379 times

0

inserir a descrição da imagem aquiPeople wanted to have empty and editable cells in a column of a Listview that pulls from the SQL Server Database information to my project. To pull the information I use LINQ and I can list all the data I want. The idea is: when loaded this list the user could edit the cells of a new column (Quantity), the information that will be inserted in these cells (whole numbers) will serve for other calculations in the project.

In XMAL code I am not able to leave the values empty... This way is returning the class path.

Anyone who can help I’d be most grateful!!

I attached an image to make it easier to doubt... It is in the Amount column that cells need is empty and editable for the user. It is not part of the SQL database, I display only for the user to enter the data.

  • XMAL code:

     <ListView x:Name="listView_tabMaqPrda_ApontaPrd" Margin="99,117,915,583" 
               ItemsSource="{Binding}" ScrollViewer.CanContentScroll="True" 
               SelectionMode="Single">                              
    
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Código" Width="Auto" DisplayMemberBinding="{Binding CodigoParada}"/>
                <GridViewColumn Header="Descrição da Parada" Width="Auto" DisplayMemberBinding="{Binding DescricaoParada}"/>
                <GridViewColumn Header="Tempo(min)" Width="Auto" DisplayMemberBinding="{Binding TempoParada}"/>
                <GridViewColumn Header="Tipo de Parada" Width="Auto" DisplayMemberBinding="{Binding TipoParada}"/>
                <GridViewColumn Header="Quantidade" Width="Auto" />
            </GridView>
        </ListView.View>
    </ListView>
    

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;

        }

    }
}

Lostfocus event from a Combox, when loading the list:

private void CarregarParadas_ApontaPrd(object sender, RoutedEventArgs e)
    {
        try
        {
            listView_tabMaqPrda_ApontaPrd.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);
        }

    }

2 answers

2

Got it that way personally...

XMAL:

<GridViewColumn Header="Quantidade" Width="Auto">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Path=Quantidade}" Width="30" MaxLength="2" 
                     HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="12" 
                     FontFamily="Calibri" HorizontalContentAlignment="Center"/>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

Source: Populating Combobox Inside Listview in WPF

1

In the same way as you declared the coded propertyPath, descricationPath and timePath in its classPath, add one more "quality" property, but no values and add Binding in the code of the quality column to make the class name disappear, thus:

  • Good night, buddy. Like this?

  • <Gridviewcolumn Header="Quantity" Width="Auto" Displaymemberbinding="{Binding Quantity}"/>

  • That’s how it worked... That is, it returns empty. Post now I need to know how to make the cells in this column editable.

  • 1

    Exactly like that. Now, regarding making the column editable, I suggest you use a Datagrid, because Listview was developed only for the purpose of presenting data, not editing, that is the goal of Datagrid (Visualisar and manipulate data)or create a Textbox with Binding setting the Listview property you want to change.

  • Thank you... I switched to Datagrid... But when I type the values in the cells that I want to edit after leaving it, some of the ones that were typed... How do I make the data being edited visible?

  • 1

    I have no idea what’s going on with you, but I think you’ll find other questions that might answer your question. Any other questions just ask. Don’t forget to mark the question as answered. ;)

  • Friend... If you can help...http://answall.com/questions/130745/datagrid-editando-dates-apenas-n%C3%Bameros-e-calculando-seu-valores-wpf-c-co

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.