コード例 #1
0
        public void exportToExcel(System.Windows.Controls.DataGrid grid, string fileName = "Excel")
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter   = "Excel Documents (*.xls)|*.xls";
                sfd.FileName = fileName + ".xls";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // Copy DataGridView results to clipboard
                    copyAlltoClipboard(grid);

                    object misValue = System.Reflection.Missing.Value;
                    Microsoft.Office.Interop.Excel.Application xlexcel = new Microsoft.Office.Interop.Excel.Application();

                    xlexcel.DisplayAlerts = false; // Without this you will get two confirm overwrite prompts
                    Microsoft.Office.Interop.Excel.Workbook  xlWorkBook  = xlexcel.Workbooks.Add(misValue);
                    Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                    // Format column D as text before pasting results, this was required for my data
                    Microsoft.Office.Interop.Excel.Range rng = xlWorkSheet.get_Range("D:D").Cells;
                    rng.NumberFormat = "@";

                    // Paste clipboard results to worksheet range
                    Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1];
                    CR.Select();
                    xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);

                    // For some reason column A is always blank in the worksheet. ¯\_(ツ)_/¯
                    // Delete blank column A and select cell A1
                    Microsoft.Office.Interop.Excel.Range delRng = xlWorkSheet.get_Range("A:A").Cells;
                    delRng.Delete(Type.Missing);
                    xlWorkSheet.get_Range("A1").Select();

                    // Save the excel file under the captured location from the SaveFileDialog
                    xlWorkBook.SaveAs(sfd.FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                    xlexcel.DisplayAlerts = true;
                    xlWorkBook.Close(true, misValue, misValue);
                    xlexcel.Quit();

                    releaseObject(xlWorkSheet);
                    releaseObject(xlWorkBook);
                    releaseObject(xlexcel);

                    // Clear Clipboard and DataGridView selection
                    System.Windows.Clipboard.Clear();
                    // roomsGrid.ClearSelection();

                    // Open the newly saved excel file
                    if (File.Exists(sfd.FileName))
                    {
                        System.Diagnostics.Process.Start(sfd.FileName);
                    }
                }
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.ToString());
            }
        }
コード例 #2
0
ファイル: CommonMethod.cs プロジェクト: dacer250/FileCompare
        /// <summary>
        /// 将SelectedItem滚动为第一行
        /// </summary>
        /// <param name="dataGrid">目标DagaGrid</param>
        /// <param name="selectedItem">选中项</param>
        public static void SetSelectedItemFirstRow(object dataGrid, object selectedItem)
        {
            //若目标datagrid为空,抛出异常
            if (dataGrid == null)
            {
                throw new ArgumentNullException("目标无" + dataGrid + "无法转换为DataGrid");
            }
            //获取目标DataGrid,为空则抛出异常
            System.Windows.Controls.DataGrid dg = dataGrid as System.Windows.Controls.DataGrid;
            if (dg == null)
            {
                throw new ArgumentNullException("目标无" + dataGrid + "无法转换为DataGrid");
            }
            //数据源为空则返回
            if (dg.Items == null || dg.Items.Count < 1)
            {
                return;
            }

            //首先滚动为末行
            dg.SelectedItem  = dg.Items[dg.Items.Count - 1];
            dg.CurrentColumn = dg.Columns[0];
            dg.ScrollIntoView(dg.SelectedItem, dg.CurrentColumn);

            //获取焦点,滚动为目标行
            dg.Focus();
            dg.SelectedItem  = selectedItem;
            dg.CurrentColumn = dg.Columns[0];
            dg.ScrollIntoView(dg.SelectedItem, dg.CurrentColumn);
        }
コード例 #3
0
ファイル: OrderManager.cs プロジェクト: yunchiri/uma24new
        public static void UpdateNewOrderDetails2(System.Windows.Controls.DataGrid grid, System.Data.Linq.EntitySet <OrderDetail> targetList)
        {
            int selIndex  = grid.SelectedIndex;
            int diffIndex = grid.Items.Count - selIndex;

            if (diffIndex == 1)
            {
                //add item
                OrderDetail newOrderDetail = GetNewOrderDetail(true);

                //2011-4-2 새로추가
                if (newOrderDetail != null)
                {
                    targetList.Add(newOrderDetail);
                    DataManager.Submit();
                }
                grid.SelectedIndex = -1;
            }
            else if (selIndex > -1)
            {
                OrderDetail newOrderDetail = GetNewOrderDetail(false);
                if (newOrderDetail != null)
                {
                    targetList[selIndex] = newOrderDetail;
                    DataManager.Submit();
                }
                else
                {
                    targetList.RemoveAt(selIndex);
                    DataManager.Submit();
                }
            }
        }
コード例 #4
0
        /////////////////////////////////////////////////////////////

        public DataTable get_dataGridColumnNames(System.Windows.Controls.DataGrid dg)
        {
            DataTable table = new System.Data.DataTable();

            if (dg.Columns.Count == 1)
            {
                table.Columns.Add(dg.Columns[0].Header.ToString());

                return(table);
            }

            for (int i = 1; i <= dg.Columns.Count - 1; i++)
            {
                //  if (i == 1)
                try
                {
                    table.Columns.Add(dg.Columns[i].Header.ToString());
                }
                catch { }
                //if (i == 2)
                //    table.Columns.Add(dg.Columns[i].Header.ToString(), typeof(string));
                //if (i == 3)
                //    table.Columns.Add(dg.Columns[i].Header.ToString(), typeof(string));
                //if (i == 4)
                //    table.Columns.Add(dg.Columns[i].Header.ToString(), typeof(string));
            }

            return(table);
        }
コード例 #5
0
 public Form1(System.Windows.Controls.DataGrid dataGrid, int type)
 {
     InitializeComponent();
     this.dataGrid = dataGrid;
     this.type     = type;
     startAction();
 }
コード例 #6
0
ファイル: DataGrid.cs プロジェクト: lenkasetGitHub/NightSky
        /// <summary>
        /// Changes the BorderBrush property of the control.
        /// </summary>
        /// <param name="targetControl">The control instance.</param>
        /// <param name="fromValue">The color to change to before the transition begins./param>
        /// <param name="toValue">The color to change to.</param>
        /// <param name="duration">Transtition Time in Milliseconds.</param>
        public static void BorderBrush(System.Windows.Controls.DataGrid targetControl, Color fromValue, Color toValue, int duration)
        {
            ColorAnimation animation = new ColorAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(duration)));

            targetControl.BorderBrush = new SolidColorBrush(fromValue);
            targetControl.BorderBrush.BeginAnimation(SolidColorBrush.ColorProperty, animation);
        }
コード例 #7
0
ファイル: SearchClass.cs プロジェクト: JanRajnoha/DVData
        internal DataGrid LoadArt(string URL)
        {
            DataGrid Database = new DataGrid();

            Database.CanUserAddRows = false;
            var  webget = new HtmlWeb();
            var  doc    = webget.Load(URL);
            bool con    = true;
            int  div    = 1;

            while (con)
            {
                string Actors = doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[1]/div[" + div + "]/h4[1]").InnerText;
                if (Actors == "Hrají:")
                {
                    con = false;
                }
                else
                {
                    div++;
                }
            }
            for (int i = 1; ; i++)
            {
                try
                {
                    Database.Items.Add(new ArtCard()
                    {
                        IDArt = i.ToString(), NameArt = doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[1]/div[" + div + "]/span[1]/a[" + i + "]").InnerText
                    });
                }
                catch { break; }
            }
            return(Database);
        }
コード例 #8
0
        GetQueryController(
            System.Windows.Controls.DataGrid dataGrid,
            FilterData filterData, IEnumerable itemsSource)
        {
            if (dataGrid == null)
            {
                throw new ArgumentNullException(nameof(dataGrid));
            }

            var query = DataGridExtensions.GetDataGridFilterQueryController(dataGrid);

            if (query == null)
            {
                //clear the filter if exists begin
                System.ComponentModel.ICollectionView view
                    = System.Windows.Data.CollectionViewSource.GetDefaultView(dataGrid.ItemsSource);
                if (view != null)
                {
                    view.Filter = null;
                }
                //clear the filter if exists end

                query = new QueryController();
                DataGridExtensions.SetDataGridFilterQueryController(dataGrid, query);
            }

            query.ColumnFilterData        = filterData;
            query.ItemsSource             = itemsSource;
            query.CallingThreadDispatcher = dataGrid.Dispatcher;
            query.UseBackgroundWorker     = DataGridExtensions.GetUseBackgroundWorkerForFiltering(dataGrid);

            return(query);
        }
コード例 #9
0
        public void SendMails(System.Windows.Controls.DataGrid grid, double interval)
        {
            List <object> gridSource = null;
            int           idx        = 1;

            grid.ItemsSource = gridSource;

            int intervaMillilSeconds = Convert.ToInt32(interval * 60 * 1000);

            foreach (List <MailMessage> contestMails in contests)
            {
                foreach (MailMessage contestMail in contestMails)
                {
                    try
                    {
                        System.Threading.Thread.Sleep(intervaMillilSeconds);
                        mailClients[contestMail.From.ToString()].Send(contestMail);
                        gridSource.Add(new { Index = idx++, Absender = contestMail.From.ToString(), Empfaenger = contestMail.To.ToString(), Betreff = contestMail.Subject.ToString() });
                    }
                    catch (SmtpException smtpEx)
                    {
                        MessageBox.Show(smtpEx.Message, "Fehler beim Mailversand", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
コード例 #10
0
 public static System.Windows.Controls.DataGridCell GetCell(System.Windows.Controls.DataGrid dataGrid, System.Windows.Controls.DataGridRow rowContainer, int column)
 {
     if (rowContainer != null)
     {
         System.Windows.Controls.Primitives.DataGridCellsPresenter presenter = FindVisualChild <System.Windows.Controls.Primitives.DataGridCellsPresenter>(rowContainer);
         if (presenter == null)
         {
             /* if the row has been virtualized away, call its ApplyTemplate() method
              * to build its visual tree in order for the DataGridCellsPresenter
              * and the DataGridCells to be created */
             rowContainer.ApplyTemplate();
             presenter = FindVisualChild <System.Windows.Controls.Primitives.DataGridCellsPresenter>(rowContainer);
         }
         if (presenter != null)
         {
             System.Windows.Controls.DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as System.Windows.Controls.DataGridCell;
             if (cell == null)
             {
                 /* bring the column into view
                  * in case it has been virtualized away */
                 dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                 cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as System.Windows.Controls.DataGridCell;
             }
             return(cell);
         }
     }
     return(null);
 }
コード例 #11
0
        public static void SelectRowByIndex(System.Windows.Controls.DataGrid dataGrid, int rowIndex)
        {
            if (!dataGrid.SelectionUnit.Equals(System.Windows.Controls.DataGridSelectionUnit.FullRow))
            {
                throw new ArgumentException("The SelectionUnit of the DataGrid must be set to FullRow.");
            }

            if (rowIndex < 0 || rowIndex > (dataGrid.Items.Count - 1))
            {
                throw new ArgumentException(string.Format("{0} is an invalid row index.", rowIndex));
            }

            dataGrid.SelectedItems.Clear();
            /* set the SelectedItem property */
            object item = dataGrid.Items[rowIndex]; // = Product X

            dataGrid.SelectedItem = item;

            System.Windows.Controls.DataGridRow row = dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex) as System.Windows.Controls.DataGridRow;
            if (row == null)
            {
                /* bring the data item (Product object) into view
                 * in case it has been virtualized away */
                dataGrid.ScrollIntoView(item);
                row = dataGrid.ItemContainerGenerator.ContainerFromIndex(rowIndex) as System.Windows.Controls.DataGridRow;
            }
            //TODO: Retrieve and focus a DataGridCell object
        }
コード例 #12
0
        public void LoadMethod(object sender, EventArgs e)
        {
            try
            {
                //_lstRoles = (System.Windows.Controls.ListBox)((System.Windows.Window)sender).FindName("lstRoles");
                //_lstUserRoles = (System.Windows.Controls.ListBox)((System.Windows.Window)sender).FindName("lstUserRoles");
                //SelectListItem();
                System.Windows.Controls.DataGrid dgview = null;

                dgview = ((System.Windows.Controls.DataGrid)((System.Windows.Window)sender).FindName("grdPermission"));

                chkAll = ((System.Windows.Controls.CheckBox)((System.Windows.Window)sender).FindName("chkAll"));

                if (dgview != null)
                {
                    chkSelectAllShow   = (System.Windows.Controls.CheckBox)dgview.FindName("chkSelectAllShow");
                    chkSelectAllAdd    = (System.Windows.Controls.CheckBox)dgview.FindName("chkSelectAllAdd");
                    chkSelectAllView   = (System.Windows.Controls.CheckBox)dgview.FindName("chkSelectAllView");
                    chkSelectAllDelete = (System.Windows.Controls.CheckBox)dgview.FindName("chkSelectAllDelete");
                    chkSelectAllPrint  = (System.Windows.Controls.CheckBox)dgview.FindName("chkSelectAllPrint");
                    chkSelectAllModify = (System.Windows.Controls.CheckBox)dgview.FindName("chkSelectAllModify");
                    if (dgview.Items.Count > 0)
                    {
                        dgview.SelectedIndex = 0;
                    }
                }
                HeaderCheck();
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
        }
コード例 #13
0
 public DDPerformanceViewModel(UserInformation userInformation, WPF.MDI.MdiChild mdiChild, System.Windows.Controls.DataGrid dgDDPerformance)
 {
     try
     {
         _userInformation                   = userInformation;
         _mdiChild                          = mdiChild;
         _ddPerformanceBll                  = new DDPerformanceBll(_userInformation);
         this.costSheetReceivedCommand      = new DelegateCommand(this.costSheetReceived);
         this.costSheetCompletedCommand     = new DelegateCommand(this.costSheetCompleted);
         this.partNumbersAllottedCommand    = new DelegateCommand(this.partNumbersAllotted);
         this.documentsReleasedCommand      = new DelegateCommand(this.documentsReleased);
         this.samplesSubmittedCommand       = new DelegateCommand(this.samplesSubmitted);
         this.refreshCommand                = new DelegateCommand(this.Refresh);
         this.performanceSummaryCommand     = new DelegateCommand(this.PerformanceSummary);
         this.mOPCommand                    = new DelegateCommand(this.MOPGraph);
         this.showECNCommand                = new DelegateCommand(this.ShowECN);
         this.showPCNCommand                = new DelegateCommand(this.ShowPCN);
         this.showDesignersCommand          = new DelegateCommand(this.ShowDesigners);
         this.printReportCommand            = new DelegateCommand(this.PrintReport);
         this.showProductInformationCommand = new DelegateCommand(this.ShowProductInformation);
         StartDate                          = Convert.ToDateTime("01/" + DateTime.Now.ToString("MM/yyyy"));
         EndDate         = DateTime.Now;
         _perfOption     = performanceOption.CostSheetReceived;
         DgDDPerformance = dgDDPerformance;
         SetCombo();
         Refresh();
     }
     catch (Exception ex)
     {
         throw ex.LogException();
     }
 }
コード例 #14
0
ファイル: DataGrid.cs プロジェクト: nirex0/NDC
        /// <summary>
        /// Changes the Background property of the control.
        /// </summary>
        /// <param name="targetControl">The control instance.</param>
        /// <param name="toValue">The color to change to.</param>
        /// <param name="duration">Transtition Time in Milliseconds.</param>
        public static void Background(System.Windows.Controls.DataGrid targetControl, Color toValue, int duration)
        {
            ColorAnimation animation = new ColorAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(duration)));

            targetControl.Background = new SolidColorBrush(((SolidColorBrush)targetControl.Background).Color);
            targetControl.Background.BeginAnimation(SolidColorBrush.ColorProperty, animation);
        }
コード例 #15
0
 public static ProductWindow GetProductWindowInstance(System.Windows.Controls.DataGrid productsDataGrid = null)
 {
     if (productWindow == null)
     {
         productWindow = new ProductWindow(productsDataGrid);
     }
     return(productWindow);
 }
コード例 #16
0
ファイル: RequestCollection.cs プロジェクト: Gigagom/hotelAdm
 public static void RequestSsToDG(System.Windows.Controls.DataGrid DG)
 {
     DG.Items.Clear();
     foreach (Request p in RequestsList)
     {
         DG.Items.Add(p);
     }
 }
コード例 #17
0
 public static void ProvidersToDG(System.Windows.Controls.DataGrid DG)
 {
     DG.Items.Clear();
     foreach (Provider p in ProviderList)
     {
         DG.Items.Add(p);
     }
 }
コード例 #18
0
ファイル: SimpleTools.cs プロジェクト: wsmyaopeng/WCS-1
        /// <summary>
        /// (DataGrid)导出为Excel文件
        /// </summary>
        /// <param name="dg"></param>
        public void SaveToExcel(System.Windows.Controls.DataGrid dg)
        {
            //    string fileName = "";
            //    string saveFileName = "";
            //    SaveFileDialog saveDialog = new SaveFileDialog
            //    {
            //        DefaultExt = "xlsx",
            //        Filter = "Excel 文件|*.xlsx",
            //        FileName = fileName
            //    };
            //    saveDialog.ShowDialog();
            //    saveFileName = saveDialog.FileName;
            //    if (saveFileName.IndexOf(":") < 0) return;  //被点了取消
            //    Excel.Application xlApp = new Excel.Application();
            //    if (xlApp == null)
            //    {
            //        System.Windows.MessageBox.Show("无法创建Excel对象,您可能未安装Excel");
            //        return;
            //    }
            //    Excel.Workbooks workbooks = xlApp.Workbooks;
            //    Excel.Workbook workbook = workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
            //    Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1]; //取得sheet1

            //    //写入行
            //    for (int i = 0; i < dg.Columns.Count; i++)
            //    {
            //        worksheet.Cells[1, i + 1] = dg.Columns[i].Header;
            //    }
            //    for (int r = 0; r < dg.Items.Count; r++)
            //    {
            //        for (int i = 0; i < dg.Columns.Count; i++)
            //        {
            //            //if ((dg.Columns[i].GetCellContent(dg.Items[r]).ToString() == "System.Windows.Controls.ContentPresenter"))
            //            //{
            //            //    continue; // 按钮控件类型
            //            //}

            //            worksheet.Cells[r + 2, i + 1] = (dg.Columns[i].GetCellContent(dg.Items[r]) as TextBlock).Text;   //读取DataGrid某一行某一列的信息内容
            //        }
            //        System.Windows.Forms.Application.DoEvents();
            //    }
            //    worksheet.Columns.EntireColumn.AutoFit();
            //    System.Windows.MessageBox.Show(fileName + "保存成功");
            //    if (saveFileName != "")
            //    {
            //        try
            //        {
            //            workbook.Saved = true;
            //            workbook.SaveCopyAs(saveFileName);
            //        }
            //        catch (Exception ex)
            //        {
            //            System.Windows.MessageBox.Show("导出文件可能正在被打断!" + ex.Message);
            //        }
            //    }
            //    xlApp.Quit();
            //    GC.Collect();
        }
コード例 #19
0
ファイル: JPKGenerator.cs プロジェクト: Sonoks/JPK
 public static void CleanDataGrid(System.Windows.Controls.DataGrid dataGrid)
 {
     try
     {
         ObservableCollection<object> oc = new ObservableCollection<object>();
         dataGrid.ItemsSource = oc;
         dataGrid.Items.Refresh();
     }
     catch (Exception ex) { throw new Exception("Wystąpił błąd podczas wczytywania danych", ex); }
 }
コード例 #20
0
        private void Delete(Course course, DataGrid courseGrid)
        {
            var result = MessageBox.Show("Are you sure you want to delete \"" + course.Title + "\"", "Delete",
                                         MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                databaseController.DeleteCourse(course.CourseID);
            }
        }
コード例 #21
0
        public void DeletePerson(System.Windows.Controls.DataGrid Record)
        {
            int id = (Record.SelectedItem as Person).Id;

            var deleteMember = DB.Person.Where(m => m.Id == id).Single();

            DB.Person.Remove(deleteMember);
            DB.SaveChanges();
            FillDataGrid();
            //myDataGrid.ItemsSource = DB.members.ToList();
        }
コード例 #22
0
 public void PopulateDataGrid(System.Windows.Controls.DataGrid datagrid_parameters, int p)
 {
     OpenConnection();
     sql         = "SELECT * FROM setting_parameters WHERE setting_id = " + "'" + p + "';";
     ds          = new DataSet();
     dataAdapter = new MySqlDataAdapter(sql, connection);
     dataAdapter.Fill(ds, "setting_parameters");
     dt = ds.Tables["setting_parameters"];
     datagrid_parameters.DataContext = dt.DefaultView;
     CloseConnection();
 }
コード例 #23
0
 public void exportarDataGrid(ExportarParaArquivo.Formato formato, System.Windows.Controls.DataGrid dg)
 {
     if (dg.HasItems)
     {
         Exportar exportar = new Exportar(formato);
         exportar.exportarDataGrid(dg);
     }
     else
     {
         throw new Exception("Não há itens a serem exportados.");
     }
 }
コード例 #24
0
 public void ShowDetail(StatisticaView view, System.Windows.Controls.DataGrid grid)
 {
     grid.Items.Add(new { Property = "Max", Value = view.Max });
     grid.Items.Add(new { Property = "Min", Value = view.Min });
     grid.Items.Add(new { Property = "Median", Value = view.Median });
     grid.Items.Add(new { Property = "Mean", Value = view.Mean });
     grid.Items.Add(new { Property = "Range", Value = view.Range });
     grid.Items.Add(new { Property = "Variance", Value = view.Variance });
     grid.Items.Add(new { Property = "StandartDeriation", Value = view.StandartDeriation });
     grid.Items.Add(new { Property = "Kurtosis", Value = view.Kurtosis });
     grid.Items.Add(new { Property = "Skewnes", Value = view.Skewnes });
 }
コード例 #25
0
ファイル: JPKGenerator.cs プロジェクト: Sonoks/JPK
 public static void AddDataToDataGrid(object[] o, System.Windows.Controls.DataGrid dataGrid)
 {
     try
     {
         try { dataGrid.Items.Clear(); } catch { }
         ObservableCollection<object> oc = new ObservableCollection<object>(o);
         dataGrid.ItemsSource = oc;
         dataGrid.Items.Refresh();
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Wystąpił błąd podczas dodawania danych do tabeli: {0}", ex.Message));
     }
 }
コード例 #26
0
        private void ShowDebugWindow()
        {
            var w = new Window {
                Title = this.Title + " (DataGrid)", Width = 400, Height = 300, DataContext = this.DataContext
            };
            var dg = new System.Windows.Controls.DataGrid();

            dg.SetBinding(System.Windows.Controls.ItemsControl.ItemsSourceProperty, new Binding("ItemsSource"));
            w.Content = dg;
            w.WindowStartupLocation = WindowStartupLocation.Manual;
            w.Left = this.Left + this.ActualWidth;
            w.Top  = this.Top;
            w.Show();
        }
コード例 #27
0
ファイル: GenerateExcell.cs プロジェクト: hnjm/OneAccount
        public void GenerateExcellWithData(System.Windows.Controls.DataGrid dgExport, string path, Microsoft.Office.Interop.Excel.Range fontRange)
        {
            Microsoft.Office.Interop.Excel.Application xlApp;
            Microsoft.Office.Interop.Excel.Workbook    xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet   xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlApp       = new Microsoft.Office.Interop.Excel.Application();
            xlWorkBook  = xlApp.Workbooks.Add(misValue);
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            xlWorkSheet.Cells.EntireColumn.NumberFormat = "@";
            int ind = 1;

            dgExport.Dispatcher.Invoke((Action)(() =>
            {
                foreach (object ob in dgExport.Columns.Select(cs => cs.Header).ToList())
                {
                    xlWorkSheet.Cells[1, ind] = ob.ToString();
                    ind++;
                }
            }));

            ind = 2;
            foreach (System.Data.DataRowView item in dgExport.Items)
            {
                for (int i = 0; i < dgExport.Columns.Count; i++)
                {
                    xlWorkSheet.Cells[ind, i + 1] = item[i].ToString();
                }
                ind++;
            }
            xlWorkSheet.Columns.AutoFit();


            if (!string.IsNullOrEmpty(path))
            {
                int countColumns = xlWorkSheet.UsedRange.Columns.Count;
                fontRange = xlWorkSheet.Range[xlWorkSheet.Cells[1, 1], xlWorkSheet.Cells[1, countColumns]];

                fontRange.Font.Bold = true;
                fontRange.EntireColumn.ColumnWidth = 30;
                fontRange.HorizontalAlignment      = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

                xlWorkBook.SaveAs(path, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                xlWorkBook.Saved = true;
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
                System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => new wdoMessageBox("Export to excel is Sucessfully done").ShowDialog()));
            }
        }
コード例 #28
0
ファイル: Utils.cs プロジェクト: Jamnine/OrmFrameEmpty
        public static void CommitTables(DependencyObject control)
        {
            if (control is System.Windows.Controls.DataGrid)
            {
                System.Windows.Controls.DataGrid grid = control as System.Windows.Controls.DataGrid;
                grid.CommitEdit(System.Windows.Controls.DataGridEditingUnit.Row, true);
                return;
            }
            int childrenCount = System.Windows.Media.VisualTreeHelper.GetChildrenCount(control);

            for (int childIndex = 0; childIndex < childrenCount; childIndex++)
            {
                CommitTables(System.Windows.Media.VisualTreeHelper.GetChild(control, childIndex));
            }
        }
コード例 #29
0
 public static void SelectDataGridItem(System.Windows.Controls.DataGrid dataGrid,
                                       int index)
 {
     if (0 <= index && index < dataGrid.Items.Count)
     {
         object item = dataGrid.Items[index];
         dataGrid.CurrentItem  = item;
         dataGrid.SelectedItem = item;
         dataGrid.ScrollIntoView(item);
     }
     else
     {
         dataGrid.CurrentItem  = null;
         dataGrid.SelectedItem = null;
     }
 }
コード例 #30
0
 /// <summary>
 /// to update the publication details
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="arg"></param>
 public override void Update(object sender, EventArgs arg)
 {
     System.Windows.Controls.DataGrid dg = (System.Windows.Controls.DataGrid)sender;
     if (dg == wm.dataGridforpublication)
     {
         if (wm.dataGridforpublication.SelectedIndex != -1)
         {
             pub = (Publication)wm.dataGridforpublication.SelectedItem;
         }
         else
         {
             pub = new Publication();
         }
         LoadPublicationDetails();
     }
 }
コード例 #31
0
ファイル: Builder.cs プロジェクト: jcoder58/WPFSharp
 public DataGrid()
 {
     C = new System.Windows.Controls.DataGrid();
 }
コード例 #32
0
        /*This method of type DataGrid, using code ctx.PERSON; select all data from the DataBase of the Person table 
         * and returns a datagrid with its property ItemSource.
         */
        public static System.Windows.Controls.DataGrid LoadData()
        {
            var dgvDati = new System.Windows.Controls.DataGrid();

            using (var ctx = new ContactDataContext(Properties.Settings.Default.path))
            {
                var selectperson = ctx.PERSON;
                dgvDati.ItemsSource = selectperson;
            }

            return dgvDati;
        }