• (5)C#工具箱-数据


    1.DataSet

    2.DataGridView

    dataGridView是一个显示网络数据的控件

    (1)绑定dataSet

    DataSet ds = new DataSet();
    //执行数据库查询,返回一个dataset
    ds = DB.Query();
    //服务端,给dataset的table[0]表起名叫tab。绑定时一定要带上定义的表名
    //光标默认定位在第一行第一列
    dataGridView1.DataSource = ds.Tables["tab"];

    (2)修改字体和颜色

    //更改字体
    dataGridView1.DefaultCellStyle.Font = new Font("宋体", 10);
    //更改某单元格的字体颜色
    dataGridView1.Rows[1].Cells[1].Style.ForeColor = Color.Red;
    //更改某单元格的背景颜色
    dataGridView1.Rows[0].Cells[1].Style.BackColor = Color.Pink;
    //选中单元格时的背景色
    dataGridView1.Rows[1].Cells[0].Style.SelectionBackColor = Color.Red;

    (3)获得值和索引

     选中单个表格或单个行号、列号选中时。当选中多数据时,只能获得第一个

    //获得当前单元格的值
    string a = dataGridView1.CurrentCell.Value.ToString();
    //获得当前单元格所在列索引
    int b = dataGridView1.CurrentCell.ColumnIndex;
    //获得当前单元格所在行索引
    int c = dataGridView1.CurrentCell.RowIndex;
    // 设定 (列, 行) 为当前单元格
    dataGridView1.CurrentCell = dataGridView1[3, 1];

       选中多格或多行、多列

     (4)设置单元格可读、可写性

    // 设置 DataGridView1 为只读,用户无法在单元格输入
    dataGridView1.ReadOnly = true;
    //用户无法选择多行或者多列
    dataGridView1.MultiSelect = false;
    //滚动条显示类型 左右、垂直、全部、全不
    dataGridView1.ScrollBars = ScrollBars.Both;

      (5)隐藏

    (6)增加、删除、修改

    (7)事件

    上百个事件,有空再看

    3.BindingSource

    4.BindingNavigator

    把控件拖到dataGridView里,制作翻页和新增、删除

     

    5.Chart 图表控件

  • 相关阅读:
    Pycharm破解
    Web UI绕过登录的实现
    使用Docker安装Jenkins服务
    Appium 基于控件左滑操作
    Pytest执行用例报Hint: make sure your test modules/packages have valid Python names.
    Selenium文件上传
    获取Android手机日志
    Linux机器间ssh免密登录
    JMeter中使用Put请求方式请求接口
    python发送post请求上传文件,无法解析上传的文件
  • 原文地址:https://www.cnblogs.com/buchizaodian/p/5790583.html
Copyright © 2020-2023  润新知