Ejemplo n.º 1
0
        private void listViewSearchResults_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (listViewSearchResults.SelectedItems.Count > 0)
                {
                    Excel.Worksheet activeSheet = Addin.Application.ActiveSheet as Excel.Worksheet;
                    Excel.Range     activeCell  = Addin.Application.ActiveCell;
                    if (null != activeCell)
                    {
                        int rowIndex    = activeCell.Row;
                        int columnIndex = activeCell.Column;

                        string targetRangeAddress = CalculateRangeArea(rowIndex, columnIndex, 7);

                        Customer selectedCustomer = listViewSearchResults.SelectedItems[0].Tag as Customer;

                        Excel.Range targetRange = activeSheet.Range(targetRangeAddress);
                        targetRange.Value2 = ToStringArray(selectedCustomer);
                        targetRange.HorizontalAlignment = XlHAlign.xlHAlignLeft;
                        activeSheet.Columns[targetRange.Column].AutoFit();

                        activeCell.Dispose();
                        activeSheet.Dispose();
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(this, exception.Message, "An error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }