首页 > 代码库 > dataGridView

dataGridView

 

1、技术分享

            dataGridView1.Columns[0].HeaderCell.Value = http://www.mamicode.com/"!!!";
            dataGridView1.Rows[0].HeaderCell.Value = http://www.mamicode.com/"===";
            dataGridView1.TopLeftHeaderCell.Value = "????";

2、拷贝

            //除了DataGridViewClipboardCopyMode.Disable样式的其他样式
            dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable ;//按住Control-C即可将数据写入剪贴板中

           
            Clipboard.SetDataObject(dataGridView1.GetClipboardContent());//将数据提交到剪贴板,视情况而定该代码有没有
 //取值
            IDataObject i=  Clipboard.GetDataObject();
            if (i.GetDataPresent(DataFormats.Text))
                textBox1.Text = i.GetData(DataFormats.Text).ToString();
            else if (i.GetDataPresent(DataFormats.Html))
                textBox1.Text = i.GetData(DataFormats.Html).ToString();
//更简单的取值
textBox1.Text = Clipboard.GetText();

3、当对单元格内容进行格式修改时,CellParsing事件比较好(如变成大些)

       private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
        {
            e.Value = e.Value.ToString().ToUpper();
            e.ParsingApplied = true;
        }

完!

 

dataGridView