zoukankan      html  css  js  c++  java
  • Winform dataGridView 用法

    //方法一 表头调换, 后台调用 

    this.dataGridView1.Columns["ProductName"].DisplayIndex = 0;

    //方法二  表头调换,属性设置, 页面上拖拽

    this.dataGridView1.AllowUserToOrderColumns = true;

    //3.时间控件默认为空

    public WeighRecord()
    {
    InitializeComponent();
    
    this.RecordTimepx.Format = DateTimePickerFormat.Custom;
    this.RecordTimepx.CustomFormat = " ";
    
    }
    
    private void RecordTimepx_ValueChanged(object sender, EventArgs e)
    {
    this.RecordTimepx.Format = DateTimePickerFormat.Long;
    this.RecordTimepx.CustomFormat = null;
    }

    //4.弹出窗口

           private void ShowSetBtn_Click(object sender, EventArgs e)
           {

                //传入值
                var childList = new List<TableHeader>();
                var headsSet = new WeighRecordSet(childList);
                //事件+回传值
                headsSet.itemTextChanged += new EventHandler((sender1, e1) =>
                {
                    childList = headsSet.list; //回传值   ///其他逻辑 刷新页面啥的
                });
    
                //弹出窗体
                headsSet.ShowDialog();            
    }
      public partial class WeighRecordSet : Form
        {
            public List<TableHeader> list { get; set; }
            public event EventHandler itemTextChanged;
            public WeighRecordSet()
            {
                InitializeComponent();
            }
    
            public WeighRecordSet(List<TableHeader> list)
            {
                InitializeComponent();
            }
    
            //确定
            private void SaveBtn_Click(object sender, EventArgs e)
            {
                //事件
                if (itemTextChanged != null)
                {
                    itemTextChanged(this, e);
                }
                this.Close();
            }
        }

    // 5.dataGridView  单元格修改前后

            //修改前
            string strBefore = "";
            private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
            {
    //选择行
    this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; strBefore = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); string strField = this.dataGridView1.Columns[e.ColumnIndex].DataPropertyName; MessageBox.Show("修改前=" + strBefore); } //修改后 private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { string strAfter = this.dataGridView1.CurrentRow.Cells[e.ColumnIndex].Value.ToString(); if (strAfter == strBefore) { return; } MessageBox.Show("修改后=" + strAfter); }

     //6.弹出是否删除对话框

     MessageBoxButtons btn = MessageBoxButtons.YesNo;
                if (MessageBox.Show("确定要删除么?", "删除数据", btn) == DialogResult.Yes)
                {
                }
  • 相关阅读:
    codeforces#571Div2 D---Vus the Cossack and Numbers【贪心】
    洛谷P1050 循环【java大数】
    洛谷P1972 HH的项链【树状数组】
    uoj#67 新年的毒瘤【Tarjan】
    洛谷1265 公路修建【最小生成树】
    【超实用工具】三维场景绘制工具
    坐标地址批处理工具
    CAD转KML乱码处理
    地理编码逆编码教程
    最新!全球ALOS 12m地形数据介绍及下载
  • 原文地址:https://www.cnblogs.com/chxl800/p/13753210.html
Copyright © 2011-2022 走看看