zoukankan      html  css  js  c++  java
  • C# winform DatagridView 的简单操作

    数据显示操作:

    dgBill.Columns[0].DataPropertyName = "key1";
    dgBill.Columns[1].DataPropertyName = "key2";
    dgBill.Columns[2].DataPropertyName = "key3";

    DataTable dt = new DataTable();
    dt.Columns.Add("key1", Type.GetType("System.String"));
    dt.Columns.Add("key2", Type.GetType("System.String"));
    dt.Columns.Add("key3", Type.GetType("System.String"));

    DataRow dr = null;

    dr = dt.NewRow();

    dr["key1"] = "key1";
    dr["key1"] =  "key2";
    dr["key1"] = "key3";
    dt.Rows.Add(dr);
    this.dgBill.DataSource = dt;

    选择一行数据:

    //右键菜单事项
    private void dg1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
    {
    if (e.Button == MouseButtons.Right)
    {
    if (e.RowIndex >= 0)
    {
    //若行已是选中状态就不再进行设置
    dg1.ClearSelection();
    dg1.Rows[e.RowIndex].Selected = true;

    //设置当前行
    dg1.CurrentCell = dg1.Rows[e.RowIndex].Cells[0];

    //弹出操作菜单
    contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
    }
    }
    }

    //选择菜单的时候,进行获取右键一行的数据

    DataGridViewRow rowData = dgBill.CurrentRow;
    if (rowData != null)
    {
    if (rowData.Cells["ID"].Value != null)
    {

    }
    else
    {
    MessageBox.Show("数据转换异常", "提示", MessageBoxButtons.OK);
    }
    }

  • 相关阅读:
    自定义checkbox样式
    自定义select样式
    jsonp
    I/O复用 poll简介
    DOS和DDOS攻击
    TCP状态转换图解析
    Makefile入门
    I/O复用select 使用简介
    替换文本内容
    share memory
  • 原文地址:https://www.cnblogs.com/wlming/p/5224822.html
Copyright © 2011-2022 走看看