获取特定行的datagridview单元格列值 [英] get datagridview cell column values of specific row
本文介绍了获取特定行的datagridview单元格列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从编程选择的datagridview行中获取特定单元格的值,我有一个存储日期的应用程序,然后比较单元格的日期和date.today是epual或在一个月内小于单元格日期来生成一个消息框,我想获取所选单元格的其他行的单元格值(name,car_num等)并在消息框中生成它们。
代码
私人 Sub Button1_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New 日期
dt = 日期 .Parse(DataGridView1.CurrentCell.Value)
TextBox1.Text = DataGridView1.CurrentCell.Value.ToString
如果(日期。今天> =(dt.AddMonths(-1))) 和(日期。今天< = dt)然后
DataGridView1.CurrentCell.Style.BackColor = Color.Beige
MessageBox.Show( date,car num,name, date)
< span class =code-keyword>结束 如果
结束 Sub
解决方案
使用DataGridView1.CurrentRow.Cells(name)。或者
DataG ridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(name)。Value
Dim rowContent 作为 字符串 = 字符串 .Empty
对于 columnCounter As 整数 = 0 DataGridView1.ColumnCount - 1
rowContent = rowContent& & DataGridView1.CurrentRow.Cells(columnCounter).Value.ToString()
Next
MessageBox.Show(rowContent)
Hi,
I want to get values from specific cells from a datagridview row which is selected programmatically, I have an application which stores dates and then compare the dates of cells and when the date.today is epual or with in a month less than the cell date to produce a message box, I want to take the other row's cell values of the selected cells (name, car_num etc) and produce them in the message box.
code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New Date
dt = Date.Parse(DataGridView1.CurrentCell.Value)
TextBox1.Text = DataGridView1.CurrentCell.Value.ToString
If (Date.Today >= (dt.AddMonths(-1))) And (Date.Today <= dt) Then
DataGridView1.CurrentCell.Style.BackColor = Color.Beige
MessageBox.Show("date,car num, name", "date")
End If
End Sub
解决方案
Use DataGridView1.CurrentRow.Cells("name").Value or
DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells("name").Value
Dim rowContent As String = String.Empty For columnCounter As Integer = 0 To DataGridView1.ColumnCount - 1 rowContent = rowContent & " " & DataGridView1.CurrentRow.Cells(columnCounter).Value.ToString() Next MessageBox.Show(rowContent)
这篇关于获取特定行的datagridview单元格列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文