zoukankan      html  css  js  c++  java
  • winform——绑定DataGridView

    ========================================================================================
    ==重点需要掌握==
    AutoSizeColumnsMode 设置为File 列填充效果
    RowHeadersVisible 设置false 第一列不显示
    SelectionModel 设置FullRowSelect 行被选中
    AllowUserToResizeColumns 设置False DataGridView是否可以调整列的大小
    AllowUserToResizeRows 设置False DataGridView是否可以调整行的大小:

    绑定DataGridView控件的方法:
    this.datagridview.DataSource=DBHelper.ExecuteTable("sql语句").DefaultView;

    取DataGridView的值绑定到文本框
    实现方式:在CellClick事件中实现如下代码
    方法1
    int rowIndex=this.dataGridView控件.CurrentCell.RowIndex;
    this.文本框名.Text = this.dataGridView控件[0,rowIndex].Value.ToString();
    this.文本框名.Text = this.dataGridView控件[1,rowIndex].Value.ToString();
    ========================================================================================


    注意:下列代码中的i是定义成全局变量
    ///[第一行] 代码如下:
    //获取选中行的索引值
    this.i = this.dataGridView1.SelectedCells[0].RowIndex;
    if (this.i <= 0)
    {
    MessageBox.Show("已经是第一行了!",
    "提示",
    MessageBoxButtons.OK,
    MessageBoxIcon.Information);
    }
    else
    {
    this.dataGridView1.Rows[i].Selected = false;
    this.dataGridView1.Rows[0].Selected = true;
    }
    ///[下一行] 代码如下:
    //获取选中行的索引值
    this.i = this.dataGridView1.SelectedCells[0].RowIndex;
    if (this.i < this.dataGridView1.RowCount - 1)
    {
    this.dataGridView1.Rows[i].Selected = false;
    this.dataGridView1.Rows[++i].Selected = true;
    }
    else
    {
    MessageBox.Show("已经是最后一行了!",
    "提示",
    MessageBoxButtons.OK,
    MessageBoxIcon.Information);
    }
    ///[上一行] 代码如下:
    //获取选中行的索引值
    this.i = this.dataGridView1.SelectedCells[0].RowIndex;
    if (this.i <= 0)
    {
    MessageBox.Show("已经是第一行了!",
    "提示",
    MessageBoxButtons.OK,
    MessageBoxIcon.Information);
    }
    else
    {
    this.dataGridView1.Rows[i].Selected = false;
    this.dataGridView1.Rows[--i].Selected = true;
    }
    ///[最后行] 代码如下:
    //获取选中行的索引值
    this.i = this.dataGridView1.SelectedCells[0].RowIndex;
    if (this.i < this.dataGridView1.RowCount - 1)
    {
    this.dataGridView1.Rows[i].Selected = false;
    this.dataGridView1.Rows[this.dataGridView1.RowCount - 1].Selected = true;
    }
    else
    {
    MessageBox.Show("已经是最后一行了!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

  • 相关阅读:
    5种主要聚类算法的简单介绍-转发
    序列标注中的BIO标注介绍
    Lecture1- Introduction and Word Vectors 斯坦福 nlp 教程
    Word embedding
    RNN
    《生成对抗网络GAN的原理与应用专题》笔记
    《自控力》《基因组:人类自传》的读后联想
    开源共享一个训练好的中文词向量(语料是维基百科的内容,大概1G多一点)
    “程序的迭代”——复杂性度量随想
    人工智能算法脑图
  • 原文地址:https://www.cnblogs.com/you-zi/p/4351179.html
Copyright © 2011-2022 走看看