DataGridView的。更改包含特定文本的特定列下的单元格。 [英] DataGridView. Changing cells under certain column that contain certain text.
问题描述
确定。所以我要做的是
1.获取第三列下的所有单元格
2.获取单元格值
3.如果任何单元格包含数字1我想将其更改为名称Free
4.如果任何单元格包含数字2 我想把它更改为名称付费
5.如果任何单元格包含数字3我想将其更改为名称待定
5.如果任何单元格包含数字4我想将其更改为名称完成
4.我希望在第三列以下的所有单元格上发生这种情况
到目前为止,我认为我已经设法将所有细胞信息放入变量(我认为)。下面是代码(此代码是我尝试更改其中一个单元格)
Ok. So what i am trying to do is
1. Get all cells that are under the third column
2. Get the cell values
3. If any of the cells contain the number "1" i want to change it to name "Free"
4. If any of the cells contain the number "2" i want to change it to name "Paid"
5. If any of the cells contain the number "3" i want to change it to name "Pending"
5. If any of the cells contain the number "4" i want to change it to name "Complete"
4. I want this to occur on all cells below the third column only
So far i think i have managed to get all the cell information put into a variable (i think). Below is the code (This code is me trying to just change one of the cells)
Dim a As Integer = 1
Dim a1 As String = "Free"
Dim cellValues As New List(Of Object)
For Each row As DataGridViewRow In DGStateInfo.Rows
cellValues.Add(row.Cells(2).Value)
Next
If cellValues.Contains(a) Then
cellValues.Contains(a1)
End If
'This is where i get confused
If cellValues.Contains(a) Then
cellValues.Contains(a1)
End If
说实话,我甚至不确定我是否正确地采用这种方式。这是我第二周尝试不同代码而没有运气。
我知道你可以使用DataGridView1.Insert(0 ,Free)命令,但问题是加载到datgridview中的数据在程序的每次加载时在不同的单元格中都有不同的数据。
我也试过这个
To be honest i'm not even sure if i'm going about this the right way. This is going on my second week of trying different code with no luck.
I do know that you can use the DataGridView1.Insert(0, "Free") command but the problem is that the data that is loading into the datgridview with have different data in different cells at every load of the program.
I have also tried this
Dim value As Integer
For Each row As DataGridViewRow In DataGridView1.DataSource
DataGridView1.Item(0, 1).Value = value
Next
If Value.text = 1 than
value = "free"
End If
这个
And this
Dim cellValues As New List(Of Object)
For i = 0 To DataGridView1.Rows.Count - 1
cellValues.Add(DataGridView1(0, i).Value)
Next
感谢先进的帮助!
Thanks in advanced for the help!
推荐答案
我的坏。这只适用于ASP.Net。
这个问题是关于Windows Forms的。
如果有人有兴趣,以下适用于ASP.Net
My bad. This only works in ASP.Net.
And this question is about Windows Forms.
In case anyone is interested, the following works for ASP.Net
For Each row As GridViewRow In DGStateInfo.Rows
If row.Cells(2).Text = "1" Then
row.Cells(2).Text = "Free"
ElseIf row.Cells(2).Text = "2" Then...
'Etc...
'Etc...
'Etc...
End If
Next
row.Cells(x).Text是您需要检查然后更改的属性。
row.Cells(x).Text is the property you need to check and then change.
这篇关于DataGridView的。更改包含特定文本的特定列下的单元格。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!