SelectedItem in the MouseDoubleClick event

0

I have the following situation. A UserControl where I can choose a company to work on, when I choose it, I send it to the application title.

My problem is that I can only choose the company with just one click, but I would like to select it with a double click.

Inside my GridControl:

<dxg:GridControl x:Name="grid" AutoGenerateColumns="None" EnableSmartColumnsGeneration="True" dxlc:LayoutControl.AllowVerticalSizing="True"
                     ItemsSource="{Binding Empresas, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}}"
                     SelectedItem="{Binding EmpresaSelecionada, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}}" PreviewMouseDoubleClick="grid_PreviewMouseDoubleClick" PreviewKeyDown="grid_PreviewKeyDown"
                             >
                <dxg:GridControl.View>
                    <dxg:TableView x:Name="view" AutoWidth="True" AllowPerPixelScrolling="True" ShowGroupPanel="False" AllowEditing="False"/>
                </dxg:GridControl.View>
                <dxg:GridControl.Columns>

                    <dxg:GridColumn FieldName="Id" Width="30"/>
                    <dxg:GridColumn FieldName="Cnpj" Header="CNPJ / CPF"/>
                    <dxg:GridColumn FieldName="RazaoSocial"/>
                    <dxg:GridColumn FieldName="Municipio" Header="Cidade"/>
                    <dxg:GridColumn FieldName="Logradouro" Header="Endereço"/>
                    <dxg:GridColumn FieldName="Situacao" />

                </dxg:GridControl.Columns>
            </dxg:GridControl>

Code:

public partial class U_EscolherEmpresa : UserControl
{
    List<DC_System.Model.Empresa> str = new List<DC_System.Model.Empresa>();

    public static readonly DependencyProperty EmpresaSelecionadaProperty =
                           DependencyProperty.Register("EmpresaSelecionada", typeof(DC_System.Model.Empresa), typeof(U_EscolherEmpresa), new PropertyMetadata(null));

    public DC_System.Model.Empresa EmpresaSelecionada
    {
        get { return this.GetValue(EmpresaSelecionadaProperty) as DC_System.Model.Empresa; }
        set { this.SetValue(EmpresaSelecionadaProperty, value); }
    }

    private void AddToList()
    {
        using (EmpresaController controller = new EmpresaController())
        {
            foreach (DataRow row in controller.ListarEscolherEmpresa(2).Rows)
            {
                var obj = new DC_System.Model.Empresa()
                {
                    Id = (int)row.ItemArray[0],
                    Cnpj = (string)row.ItemArray[1],
                    RazaoSocial = (string)row.ItemArray[2],
                    Municipio = (string)row.ItemArray[3],
                    Logradouro = (string)row.ItemArray[4],
                    Situacao = (bool)row.ItemArray[5],
                };

                str.Add(obj);
            }
        }

        grid.ItemsSource = str;
    }

    public List<DC_System.Model.Empresa> Empresas
    {
        get
        {
            return str;
        }
    }

    public U_EscolherEmpresa()
    {
        InitializeComponent();

        AddToList();
    }

    private void grid_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        //O QUE COLOCAR AQUI? OU SE É AQUI...
    }

I tried to add a MouseDoubleClick event but I do not know how to do that. Can someone help me?

Thank you!

    
asked by anonymous 20.10.2015 / 14:56

0 answers