由于我使用RowPrePaint
,因此我一直在构建应用程序时遇到了一些问题。无论代码执行的顺序如何,事件似乎都粘贴在所有内容之上。
我遇到了一个细胞工具提示位于其下方的问题;我不得不找到一种完全不同的方法来传达细胞的文本。 现在我只是尝试显示一个消息框,如果我的If语句不符合,但即使这样也不会显示,除非用户按下Alt键(我通过关闭并再次运行代码进行检查)。 / p>
所以我的问题是为什么RowPrePaint
事件将自己置于一切之上并且有没有办法在不将代码移动到cellformatting
事件的情况下改变它?提前谢谢。
我在下面包含了我的if语句,但我知道代码本身不是问题。
Dim RSScon As New SqlClient.SqlConnection("ConnectionString")
Dim cmd As New SqlCommand("SELECT Comment FROM StepBackTable WHERE Retsch_ID = '" & Convert.ToInt32(DataGridView1.Rows(rowindex).Cells(0).Value) & "' AND Col_index = '" & Convert.ToInt32(columnindex) & "';", RSScon)
Dim Rdr_Info As SqlDataReader
RSScon.Open()
Rdr_Info = cmd.ExecuteReader(CommandBehavior.Default)
If Rdr_Info.HasRows Then
While Rdr_Info.Read()
ViewComForm.Show()
ViewComForm.TextBox1.Text = Rdr_Info("Comment")
End While
Else
MessageBox.Show("There are no comments assiated with this stage of the job",
"Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)
End If
Rdr_Info.Close()
cmd.Dispose()
RSScon.Close()
编辑:TaW的RowPrePaint代码
For colval1 As Integer = 5 To 28
If Convert.ToInt32(DataGridView1.Rows(e.RowIndex).Cells(29).Value) = 1 Or Convert.ToInt32(DataGridView1.Rows(e.RowIndex).Cells(29).Value) = 5 Then
DataGridView1.Rows(e.RowIndex).Cells(colval1).Value = 2
DataGridView1.Rows(e.RowIndex).Cells(29).Value = 1
ElseIf Convert.ToInt32(DataGridView1.Rows(e.RowIndex).Cells(29).Value) = 4 Then
DataGridView1.Rows(e.RowIndex).Cells(colval1).Value = 4
DataGridView1.Rows(e.RowIndex).Cells(29).Value = 4
End If
Next colval1
If DataGridView1.Rows(e.RowIndex).Cells(3).Value = 7 Then
DataGridView1.Rows(e.RowIndex).Cells(0).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(1).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(2).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(3).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(4).Style.BackColor = Color.LightSkyBlue
ElseIf DataGridView1.Rows(e.RowIndex).Cells(3).Value = 8 Then
DataGridView1.Rows(e.RowIndex).Cells(0).Style.ForeColor = Color.White
DataGridView1.Rows(e.RowIndex).Cells(1).Style.ForeColor = Color.White
DataGridView1.Rows(e.RowIndex).Cells(2).Style.ForeColor = Color.White
DataGridView1.Rows(e.RowIndex).Cells(3).Style.ForeColor = Color.White
DataGridView1.Rows(e.RowIndex).Cells(4).Style.ForeColor = Color.White
End If
Dim value As Integer = Convert.ToInt32(DataGridView1.Rows(e.RowIndex).Cells(5).Value)
Select Case value
Case "0"
DataGridView1.Rows(e.RowIndex).Cells(5).Style.BackColor = Color.Empty
DataGridView1.Rows(e.RowIndex).Cells(5).Style.ForeColor = Color.White
Case "1"
DataGridView1.Rows(e.RowIndex).Cells(0).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(1).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(2).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(4).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(5).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(5).Style.ForeColor = Color.LightSkyBlue
Case "2"
DataGridView1.Rows(e.RowIndex).Cells(0).Style.BackColor = Color.Chartreuse
DataGridView1.Rows(e.RowIndex).Cells(1).Style.BackColor = Color.Chartreuse
DataGridView1.Rows(e.RowIndex).Cells(2).Style.BackColor = Color.Chartreuse
DataGridView1.Rows(e.RowIndex).Cells(4).Style.BackColor = Color.Chartreuse
DataGridView1.Rows(e.RowIndex).Cells(5).Style.BackColor = Color.Chartreuse
DataGridView1.Rows(e.RowIndex).Cells(5).Style.ForeColor = Color.Chartreuse
Case "4"
DataGridView1.Rows(e.RowIndex).Cells(0).Style.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(1).Style.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(2).Style.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(4).Style.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(5).Style.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(5).Style.ForeColor = Color.Red
Case "5"
DataGridView1.Rows(e.RowIndex).Cells(0).Style.BackColor = Color.RoyalBlue
DataGridView1.Rows(e.RowIndex).Cells(1).Style.BackColor = Color.RoyalBlue
DataGridView1.Rows(e.RowIndex).Cells(2).Style.BackColor = Color.RoyalBlue
DataGridView1.Rows(e.RowIndex).Cells(4).Style.BackColor = Color.RoyalBlue
DataGridView1.Rows(e.RowIndex).Cells(5).Style.BackColor = Color.RoyalBlue
DataGridView1.Rows(e.RowIndex).Cells(5).Style.ForeColor = Color.RoyalBlue
End Select
For colval As Integer = 6 To 28
Dim value6 As Integer = DataGridView1.Rows(e.RowIndex).Cells(colval).Value
Select Case value6
Case "0"
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.BackColor = Color.Empty
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.ForeColor = Color.White
Case "1"
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.BackColor = Color.LightSkyBlue
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.ForeColor = Color.LightSkyBlue
Case "2"
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.BackColor = Color.Chartreuse
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.ForeColor = Color.Chartreuse
Case "3"
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.ForeColor = Color.Red
Case "4"
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.ForeColor = Color.Red
Case "5"
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.BackColor = Color.RoyalBlue
DataGridView1.Rows(e.RowIndex).Cells(colval).Style.ForeColor = Color.RoyalBlue
End Select
Next colval
Dim value29 As Integer = DataGridView1.Rows(e.RowIndex).Cells(29).Value
Select Case value29
Case "0"
DataGridView1.Rows(e.RowIndex).Cells(29).Style.BackColor = Color.Empty
DataGridView1.Rows(e.RowIndex).Cells(29).Style.ForeColor = Color.White
Case "1"
DataGridView1.Rows(e.RowIndex).Cells(29).Style.BackColor = Color.Chartreuse
DataGridView1.Rows(e.RowIndex).Cells(29).Style.ForeColor = Color.Chartreuse
Case "4"
DataGridView1.Rows(e.RowIndex).Cells(29).Style.BackColor = Color.Red
DataGridView1.Rows(e.RowIndex).Cells(29).Style.ForeColor = Color.Red
End Select
If DataGridView1.Rows(e.RowIndex).Cells(7).Value = 5 And DataGridView1.Rows(e.RowIndex).Cells(3).Value = 8 Then
DataGridView1.Rows(e.RowIndex).Cells(9).Value = 5
DataGridView1.Rows(e.RowIndex).Cells(8).Value = 5
End If
If DataGridView1.Rows(e.RowIndex).Cells(10).Value = 5 And DataGridView1.Rows(e.RowIndex).Cells(3).Value = 8 Then
DataGridView1.Rows(e.RowIndex).Cells(11).Value = 5
DataGridView1.Rows(e.RowIndex).Cells(12).Value = 5
End If
If DataGridView1.Rows(e.RowIndex).Cells(13).Value = 5 And DataGridView1.Rows(e.RowIndex).Cells(3).Value = 8 Then
DataGridView1.Rows(e.RowIndex).Cells(14).Value = 5
DataGridView1.Rows(e.RowIndex).Cells(15).Value = 5
DataGridView1.Rows(e.RowIndex).Cells(16).Value = 5
End If
If DataGridView1.Rows(e.RowIndex).Cells(22).Value = 5 And DataGridView1.Rows(e.RowIndex).Cells(3).Value = 8 Then
DataGridView1.Rows(e.RowIndex).Cells(23).Value = 5
End If
If DataGridView1.Rows(e.RowIndex).Cells(27).Value = 5 And DataGridView1.Rows(e.RowIndex).Cells(3).Value = 8 Then
DataGridView1.Rows(e.RowIndex).Cells(29).Value = 1
End If
If DataGridView1.Rows(e.RowIndex).Cells(9).Value = 1 And DataGridView1.Rows(e.RowIndex).Cells(3).Value = 7 Then
DataGridView1.Rows(e.RowIndex).Cells(10).Value = 1
End If
If DataGridView1.Rows(e.RowIndex).Cells(12).Value = 1 And DataGridView1.Rows(e.RowIndex).Cells(3).Value = 7 Then
DataGridView1.Rows(e.RowIndex).Cells(13).Value = 1
End If
If DataGridView1.Rows(e.RowIndex).Cells(19).Value = 1 And DataGridView1.Rows(e.RowIndex).Cells(3).Value = 7 Then
DataGridView1.Rows(e.RowIndex).Cells(20).Value = 1
End If