当前位置:网站首页>Basic use of DataGridView 0526
Basic use of DataGridView 0526
2022-06-09 21:49:00 【pyhui2020】
Introduce data network view

rehearse Go to dgv Logic for binding data in

private void Form1_Load(object sender, EventArgs e)
{
// Get a warehouse with data
/// Definition sql sentence
String sql = "select * from sanguo";
/// Get the connection object
String connStr = "Data Source=.;Initial Catalog=mySchool;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
/// Get trolley object
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
/// Get the warehouse
DataSet ds = new DataSet();
/// The trolley is unloaded to the warehouse
adapter.Fill(ds, "hero_table");
/// Give Way datagridview The data source of points to the data table in the warehouse
/// Data network view object . data source = Tables in the warehouse
dgvSanguo.DataSource = ds.Tables["hero_table"];
}
}

Column set

Add columns to the column set
At the same time, set the display text of the column object

Currently, only columns have been added
The system does not know what data this column should display

Tell the system what to display in the current column
according to sql Statement

Root us sql Statement to point to the column data

result

Disable automatic column generation
dgvSanguo.AutoGenerateColumns = false;
Close the leftmost column

Select the whole line
selectionMode
FullRowSelect
Let the column be covered with dgv

The user is not allowed to add rows at the least position
/// allow allow user user towards to add to add That's ok row Add data in the last row
dgvSanguo.AllowUserToAddRows = false;
Trolley update data
// Directly upgrade the trolley Let the trolley return the updated data
new SqlCommandBuilder(adapter);
// Trolley update data
adapter.Update(ds, "hero_table");
Selected row set
Number of tests
private void button2_Click(object sender, EventArgs e)
{
// Get the selected row set , Be similar to listview Control selectedItems
int c = dgvSanguo.SelectedRows.Count;
MessageBox.Show(c.ToString());
}
A collection of cells in rows
Number of test cells
private void button2_Click(object sender, EventArgs e)
{
// Get the selected row set , Be similar to listview Control selectedItems
int c = dgvSanguo.SelectedRows[0].Cells.Count;
MessageBox.Show(c.ToString());
}
Get cell value
private void button2_Click(object sender, EventArgs e)
{
String v = dgvSanguo.SelectedRows[0].Cells[1].Value.ToString();
MessageBox.Show(v);
}
Get the selected row in dgv Subscript positions of all rows in the
int idx = dgvSanguo.SelectedRows[0].Index;
MessageBox.Show(idx.ToString());
边栏推荐
- Deploy MySQL based on statefulset in kubernetes (Part 2)
- Laravel8 use when search
- [cf] 797 div3 D.Black and White Stripe
- Pycharm进入debug模式后一直显示collecting data解决方法
- Programming question: count the letters that appear most frequently in the string
- Goldfish rhca memoirs: do447 management list -- management list variables
- STM32 memory knowledge
- [cf] 797 div3 D.Black and White Stripe
- Mmdetection train your own coco data set and common problems
- Dongle driven solution
猜你喜欢

Unbutu configuring DHCP server and client connections

js基本数据类型和引用数据类型

How to locate the cause of high CPU on the server

易买网开发 趣买买 项目资源一览 0605

datagridview的基本使用 0526

Yolo series target detection post-processing - non maximum suppression

scratch编程 飞翔的小鸟 开发笔记 0604

发电厂企业的关口表参数里的组合无功1和组合无功2的含义--抄表数采问题

Logistic regression summary

spider pi 智能视觉六足机器人 颜色追踪 人脸识别 0604
随机推荐
What is the difference between a WiFi 6 router and a WiFi 5 router
与鲲鹏代码迁移工具的初次邂逅
js 强制类型转换 和 隐式类型转换 和 Unicode编码
Leetcode:547. Circle of friends
Wechat applet obtains provincial and urban information according to longitude and latitude
Comprendre le go des modules go. MOD et go. SUM
Logistic regression summary
Mqtt graphical client-mqttx installation and use tutorial
Shell record
PaddleNLP--UIE(二)--小样本快速提升性能(含doccona标注)
[code audit] Buu_ [GWCTF 2019]mypassword
Design and Simulation of SD card reading and writing based on FPGA Verilog
实例:用C#.NET手把手教你做微信公众号开发(19)--使用微信支付转账到微信粉丝零钱账户
如何定比特到服務器CPU飆高的原因
How to make our self built site have a custom domain name (1)
Scheduled backup of laravel 8 database
The difference between CompareTo and compare
数据库每日一题---第7天:订单最多的客户
Mmdetection train your own coco data set and common problems
STM32 memory knowledge