コード例 #1
0
 public void InitDGVPlants()
 {
     using (var context = new AquariumContext())
     {
         context.Plants.Load();
         DGVPlant.DataSource = context.Plants.Local.ToBindingList();
         DGVPlant.Columns["Statistics"].Visible = false;
         DGVPlant.Columns["Id"].HeaderText      = "№";
         DGVPlant.Columns["Name"].HeaderText    = "Название";
         DGVPlant.Columns["Type"].HeaderText    = "Разновидность";
         DGVPlant.Refresh();
     }
 }
コード例 #2
0
        private void MenuItemExcel_Click(object sender, EventArgs e)
        {
            switch (TabControl.SelectedIndex)
            {
            case 0:
                DGVFish.SelectAll();
                var data0 = DGVFish.GetClipboardContent();
                if (data0 != null)
                {
                    Clipboard.SetDataObject(data0);
                }
                break;

            case 1:
                DGVPlant.SelectAll();
                var data1 = DGVPlant.GetClipboardContent();
                if (data1 != null)
                {
                    Clipboard.SetDataObject(data1);
                }
                break;

            case 2:
                DGVStatistics.SelectAll();
                var data2 = DGVStatistics.GetClipboardContent();
                if (data2 != null)
                {
                    Clipboard.SetDataObject(data2);
                }
                break;
            }
            Microsoft.Office.Interop.Excel.Application xlexcel;
            Microsoft.Office.Interop.Excel.Workbook    xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet   xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlexcel = new Microsoft.Office.Interop.Excel.Application {
                Visible = true
            };
            xlWorkBook  = xlexcel.Workbooks.Add(misValue);
            xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            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);
        }