当前位置: 首页>>代码示例>>C#>>正文


C# DataGrid.SelectAllCells方法代码示例

本文整理汇总了C#中System.Windows.Controls.DataGrid.SelectAllCells方法的典型用法代码示例。如果您正苦于以下问题:C# DataGrid.SelectAllCells方法的具体用法?C# DataGrid.SelectAllCells怎么用?C# DataGrid.SelectAllCells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.DataGrid的用法示例。


在下文中一共展示了DataGrid.SelectAllCells方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExportToExcel

        public static void ExportToExcel(DataGrid dgDisplay)
        {
            dgDisplay.SelectAllCells();
            dgDisplay.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
            ApplicationCommands.Copy.Execute(null, dgDisplay);
            String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
            String result = (string)Clipboard.GetData(DataFormats.Text);
            dgDisplay.UnselectAllCells();
            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "xls|*.xls";

            save.ShowDialog();
            if (!string.IsNullOrEmpty(save.FileName))
            {
                using (StreamWriter writer = new StreamWriter(save.FileName))
                {
                    writer.WriteLine(result);
                }
            }

            MessageBox.Show(" Exporting DataGrid data to Excel file created");
        }
开发者ID:AllanWLie,项目名称:UnitGate,代码行数:23,代码来源:ExportService.cs

示例2: DataGridtoDataTable

        //public static Run LoadStringTo(RichTextBox rtb, string tx)
        //{

        //    if (tx == "") return null;

        //    TextRange textRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);

        //    MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(tx));

        //    textRange.Load(ms, DataFormats.Rtf);

        //    FlowDocument fd = rtb.Document;

        //    System.Windows.Documents.Paragraph pr = fd.Blocks.First() as  System.Windows.Documents.Paragraph;



        //    return null;
        //}




        //public static ComboBoxItem FindComboItem(ComboBox combo, string text)
        //{
        //    ComboBoxItem cit = new ComboBoxItem();

        //    foreach (var vit in combo.Items)
        //    {
        //       ComboBoxItem c = (ComboBoxItem)vit;
        //        if (vit.ToString() == text)
        //            cit = c;
        //   }

        //    return cit;

        //}
        public static DataTable DataGridtoDataTable(DataGrid dg)
        {


            dg.SelectAllCells();
            dg.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
            ApplicationCommands.Copy.Execute(null, dg);
            dg.UnselectAllCells();
            String result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
            string[] Lines = result.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            string[] Fields;
            Fields = Lines[0].Split(new char[] { ',' });
            int Cols = Fields.GetLength(0);
            DataTable dt = new DataTable();
            //1st row must be column names; force lower case to ensure matching later on.
            for (int i = 0; i < Cols; i++)
                dt.Columns.Add(Fields[i].ToUpper(), typeof(string));
            DataRow Row;
            for (int i = 1; i < Lines.GetLength(0) - 1; i++)
            {
                Fields = Lines[i].Split(new char[] { ',' });
                Row = dt.NewRow();
                for (int f = 0; f < Cols; f++)
                {
                    Row[f] = Fields[f];
                }
                dt.Rows.Add(Row);
            }
            return dt;

        }
开发者ID:DevGenox,项目名称:PersonelKayitveRaporBETA,代码行数:68,代码来源:Class1.cs


注:本文中的System.Windows.Controls.DataGrid.SelectAllCells方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。