当前位置:网站首页>C reads excel specific data into specific columns of DataGridView

C reads excel specific data into specific columns of DataGridView

2022-04-23 21:25:00 Plant a sweet smell

C# Read Excel Specific data to DataGridView In a specific column of

1. Studying recently DataGridView Read Excel When , I found that I read more data every time , I didn't read what I wanted excel Column data , Baidu has not found what it wants . Then I was checking DataGridView When the column attribute of DataPropertyName This attribute .

2.DataPropertyName The attribute of means : Gets or sets the properties of the data source or the name and address of the database column DataGridView binding .

1. The interface operation binding is as follows :

Let the columns you add DataPropertyName And Excel Your column name is always ok
 Insert picture description here

2. The code operation is as follows :

DataGridView And get Excel Of DataTable If the column properties of are consistent .

DataGridView.Columns["ColMac"].DataPropertyName = dt.Columns["MAC"].ColumnName;

There are many pits on the way to beginner's school , I hope these will help you . Encourage them together !

版权声明
本文为[Plant a sweet smell]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/110/202204200619557349.html