In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to operate DataGridView in C# to get or set the contents of the current cell", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to operate DataGridView in C# to get or set the contents of the current cell"!
The current cell refers to the cell in which the DataGridView focus is located, which can be obtained through the CurrentCell property of the DataGridView object. Returns null if the current cell does not exist.
Get the contents of the current cell:
Object obj = this.dgv_PropDemo.CurrentCell.Value
Note: the return value is of type object.
Get the column Index of the current cell:
Int columnIndex = this.dgv_PropDemo.CurrentCell.ColumnIndex
Gets the Index of the row in the current cell:
Int rowIndex= this.dgv_PropDemo.CurrentCell.RowIndex
In addition, use the DataGridView.CurrentCellAddress property to determine the row in which the cell resides:
Int row= this.dgv_PropDemo.CurrentCellAddress.Y
Column:
Int column = this.dgv_PropDemo.CurrentCellAddress.X
Note: both the row and column indexes of DataGridView start at 0.
The current cell can be changed by setting the CurrentCell of the DataGridView object.
DataGridView1.CurrentCell=DataGridView1 [int columnIndex,int rowIndex]
Note: if the selected mode of DataGridVIew is row selection, the entire row of the current cell is selected. Otherwise, only the current cell set will be selected.
Set CurrentCell to the current cell that Null can deactivate.
Example: set the current CurrentCell for the first row and the second column
This.dgv_PropDemo.CurrentCell = this.dgv_PropDemo [1,0]
Example: traversing the DataGridView by up and down
/ traverse / private void btn_Up_Click (object sender, EventArgs e) {/ / get the index of the previous row int upRowIndex = this.dgv_PropDemo.CurrentCell.RowIndex-1; if (upRowIndex
< 0) { //选中最后一行 this.dgv_PropDemo.CurrentCell = this.dgv_PropDemo[0, this.dgv_PropDemo.RowCount - 1]; } else { this.dgv_PropDemo.CurrentCell = this.dgv_PropDemo[0, upRowIndex]; } } /// /// 向下遍历 /// /// /// private void btn_Down_Click(object sender, EventArgs e) { //获取下一行的索引 int nextRowIndex = this.dgv_PropDemo.CurrentCell.RowIndex + 1; if (nextRowIndex >This.dgv_PropDemo.RowCount-1) {this.dgv_PropDemo.CurrentCell = this.dgv_PropDemo [0,0];} else {this.dgv_PropDemo.CurrentCell = this.dgv_PropDemo [0, nextRowIndex] }} at this point, I believe you have a deeper understanding of "how to operate DataGridView to get or set the contents of the current cell in C#". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.