2013-06-05 69 views
0

即時通訊構建一個批量插入應用程序,以便在Excel之間將數據傳輸到Windows窗體中的SQL Server .net 3.5 問題是,有時Excel數據在進入Sql Server之前需要一些更改,這就是爲什麼我需要使用可編輯的datagridview創建一個與過程中的中間層一樣工作的應用程序。datagridview不更新編輯更改

該應用程序包含一個datagridview中的excel內容,然後使用背景變化,工具提示等進行一些驗證。因此,如果有一些單元格帶有驗證,則用戶按F2並更改相應的內容。

問題是,當用戶結束更改單元格時,我想再次應用驗證過程(更改backcolor行,添加工具提示等),並且這不再起作用,只是一次工作。換句話說,在datagridview單元格發生一些變化後,任何改變單元格背景顏色的方法都不起作用。

有些想法?感謝大家。

注:

這是我4驗證方法之一:

**enter code here** 

Public Sub Validate() 
    For Each x As DataGridViewRow In DataGridView1.Rows 
     If IsDBNull(x.Cells(0).Value) Then 
      DataGridView1.Rows(x.Index).Cells(0).Style.BackColor = Color.Red 
     End If 
     If IsDBNull(x.Cells(1).Value) Then 
      DataGridView1.Rows(x.Index).Cells(1).Style.BackColor = Color.Red 
     End If 
     If IsDBNull(x.Cells(2).Value) Then 
      DataGridView1.Rows(x.Index).Cells(2).Style.BackColor = Color.Red 
     End If 

     If IsDBNull(x.Cells(3).Value) Then 
      DataGridView1.Rows(x.Index).Cells(3).Style.BackColor = Color.Yellow 
     End If 
     If IsDBNull(x.Cells(4).Value) Then 
      DataGridView1.Rows(x.Index).Cells(4).Style.BackColor = Color.Yellow 
     End If 
     If IsDBNull(x.Cells(5).Value) Then 
      DataGridView1.Rows(x.Index).Cells(5).Style.BackColor = Color.Yellow 
     End If 


     If IsDBNull(x.Cells(6).Value) Then 
      DataGridView1.Rows(x.Index).Cells(6).Style.BackColor = Color.Red 
     End If 
     If IsDBNull(x.Cells(7).Value) Then 
      DataGridView1.Rows(x.Index).Cells(7).Style.BackColor = Color.Red 
     End If 


     If IsDBNull(x.Cells(8).Value) Then 
      DataGridView1.Rows(x.Index).Cells(8).Style.BackColor = Color.Yellow 
     End If 
     If IsDBNull(x.Cells(9).Value) Then 
      DataGridView1.Rows(x.Index).Cells(9).Style.BackColor = Color.Yellow 
     End If 
     If IsDBNull(x.Cells(10).Value) Then 
      DataGridView1.Rows(x.Index).Cells(10).Style.BackColor = Color.Yellow 
     End If 
     If IsDBNull(x.Cells(11).Value) Then 
      DataGridView1.Rows(x.Index).Cells(11).Style.BackColor = Color.Yellow 
     End If 
     If IsDBNull(x.Cells(12).Value) Then 
      DataGridView1.Rows(x.Index).Cells(12).Style.BackColor = Color.Yellow 
     End If 


     If IsDBNull(x.Cells(13).Value) Then 
      DataGridView1.Rows(x.Index).Cells(13).Style.BackColor = Color.Red 
     End If 
     If IsDBNull(x.Cells(14).Value) Then 
      DataGridView1.Rows(x.Index).Cells(14).Style.BackColor = Color.Red 
     End If 
     If IsDBNull(x.Cells(15).Value) Then 
      DataGridView1.Rows(x.Index).Cells(15).Style.BackColor = Color.Red 
     End If 

     If IsDBNull(x.Cells(16).Value) Then 
      DataGridView1.Rows(x.Index).Cells(16).Style.BackColor = Color.Yellow 
     End If 
     If IsDBNull(x.Cells(17).Value) Then 
      DataGridView1.Rows(x.Index).Cells(17).Style.BackColor = Color.Yellow 
     End If 



     If IsDBNull(x.Cells(18).Value) Then 
      DataGridView1.Rows(x.Index).Cells(18).Style.BackColor = Color.Red 
     End If 
     If IsDBNull(x.Cells(19).Value) Then 
      DataGridView1.Rows(x.Index).Cells(19).Style.BackColor = Color.Red 
     End If 
     If IsDBNull(x.Cells(20).Value) Then 
      DataGridView1.Rows(x.Index).Cells(20).Style.BackColor = Color.Red 
     End If 

    Next 
End Sub 

回答

0

你應該看着你的RowDataBound事件,並運用你的着色變更。

protected void DataGridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    Validate() 'add any other coloring changes here as well 
} 

這將完成是強制的色彩變化發生在每次行獲得反彈的時間(這是每一個變化到DataGrid後 - 不幸的是,他們是不是最有效的成分在那裏)

+0

感謝您的答案,但我使用Windows窗體。 –

+0

在這種情況下,請查看OnRowLeave事件,並調用其中的方法,因爲只要有人點擊下一行或表單中的其他控件(包括單擊按鈕之前),就會觸發該方法。 – user2366842

+0

完成,謝謝很多。 –