当前位置:网站首页>【C#语言】DataGridView隐藏行列
【C#语言】DataGridView隐藏行列
2022-08-07 19:11:00 【文布斯】
在实践中,有时需要将表中数据隐藏。
属性:
获取或设置一个值,指示该列是否可见。
public override bool Visible { get; set; }


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test_DataGridView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = Source();
}
//数据表资源
private DataTable Source()
{
DataTable mydt = new DataTable();
mydt.Columns.Add("姓名");
mydt.Columns.Add("年龄");
mydt.Columns.Add("分数");
String[,] str = new String[,] { { "张三", "21", "90" }, { "李四", "22", "93" }, { "王五", "23", "99" } };
for (int i = 0; i < 3; i++)
{
DataRow dr = mydt.NewRow();
dr[0] = str[i, 0];
dr[1] = str[i, 1];
dr[2] = str[i, 2];
mydt.Rows.Add(dr);
}
return mydt;
}
//获取单元格信息
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//获取单元格坐标
int col = dataGridView1.CurrentCellAddress.X + 1;
int row = dataGridView1.CurrentCellAddress.Y + 1;
//获取单元格内容
String content = dataGridView1.CurrentCell.Value.ToString();
MessageBox.Show("行:" + row.ToString() + " 列:" + col.ToString() + " 内容:" + content);
}
//隐藏年龄
private void button1_Click(object sender, EventArgs e)
{
String bts = button1.Text;
if (bts == "隐藏年龄")
{
dataGridView1.Columns[1].Visible = false;
bts = "显示年龄";
button1.Text = bts;
}
else
{
dataGridView1.Columns[1].Visible = true;
bts = "隐藏年龄";
button1.Text = bts;
}
}
}
}
边栏推荐
- Scala entry to proficient (Shang Silicon Valley study notes)
- Workplace Experience Sharing--Details that are easily overlooked when checking data by timestamp in the interface
- Graduation Summary
- Database table design with tree structure
- 第三章 运算符与标识符与关键字
- What is deadlock?How to solve the deadlock problem?
- vulnhub靶机22 02-Breakout.zip
- Technology Sharing | How to do json response assertion in interface automation test?
- 个体工商户注册登记流程!(详细版)
- Mysql.索引数据结构演进
猜你喜欢
随机推荐
9. The usage of squeeze in paddlepaddle, cut to the desired dimension
复爱合缘风波后高管调整:命庄海为总裁 王靖为CFO
拍摄视频,真的帧率越高越好吗?
DELL SC Combe Store Forgotten Password Reset Method
语法基础(判断语句)
数据库小记
Database Notes
vulnhub range serial-php penetration
Laravel 5.1 框架默认不支持 MySQL 8.0 数据库,如果需要支持,请参考以下方法
音视频开发之旅(66) - 音频变速不变调的原理
抓包工具:Fiddler下载、安装、使用 教程
认识UDS诊断29认证服务
tensorflow 2.x 学习笔记
conda环境启动jupyter notebook,但是环境没有切换的问题
Audio and video development journey (66) - the principle of audio variable speed without pitch
nn.Module的children()与modules()方法、如何获取网络的某些层
Idle Mystic's potential multiplayer strategy game
Jumping Stone (Dynamic Programming)
After love or edge after executives adjustment: life ZhuangHai Wang Jing as CFO for President
职场经验分享--接口中按时间戳查数据容易被忽略的细节









