2013-01-10 62 views
-1

我有一個屏幕包含兩個按鈕和一個6列的數據網格。當按下按鈕1時,它顯示第1到第4列的行中的數據。當我按下按鈕2時,我希望我的應用程序填充行中的其餘列(即第5列和第6列)。通過單擊按鈕完成行的第二部分?

解決方案可能很明顯,但我不知道如何解決它。

編輯:對不起,我忘記提到之前,當我點擊第二個按鈕,數據出現在正確的位置,即在最後兩列。除了它不在同一行。數據出現一行。

這裏是我的代碼:

Private Sub btnClockIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClockIn.Click 

Homescreen.DataGridViewEmployee.ColumnCount = 6 
Homescreen.DataGridViewEmployee.Columns(0).Name = "Employee Number" 
Homescreen.DataGridViewEmployee.Columns(1).Name = "Day" 
Homescreen.DataGridViewEmployee.Columns(2).Name = "Week Number" 
Homescreen.DataGridViewEmployee.Columns(3).Name = "Time In" 
Homescreen.DataGridViewEmployee.Columns(4).Name = "Time Out" 
Homescreen.DataGridViewEmployee.Columns(5).Name = "Hours" 

Dim row As String() = New String() {ENumber, day, WeekNum, StartTime, "", ""} 
Homescreen.DataGridViewEmployee.Rows.Add(row) 
Homescreen.DataGridViewEmployee.ReadOnly = True 

Private Sub btnClockOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClockOut.Click 

Homescreen.DataGridViewEmployee.ColumnCount = 6 
Homescreen.DataGridViewEmployee.Columns(0).Name = "Employee Number" 
Homescreen.DataGridViewEmployee.Columns(1).Name = "Day" 
Homescreen.DataGridViewEmployee.Columns(2).Name = "Week Number" 
Homescreen.DataGridViewEmployee.Columns(3).Name = "Time In" 
Homescreen.DataGridViewEmployee.Columns(4).Name = "Time Out" 
Homescreen.DataGridViewEmployee.Columns(5).Name = "Hours" 

Dim row As String() = New String() {"", "", "", "", EndTime, Diff} 
Homescreen.DataGridViewEmployee.Rows.Add(row) 
Homescreen.DataGridViewEmployee.ReadOnly = True 

回答

0

的問題是,你正在使用的rows.add()方法,因爲它被命名爲第二個按鈕添加到行。如果你想添加到最後一排,你需要使用rows(rows.Count -1)然後編輯該列表中的相關領域,以獲得最後一行

Dim row as DataGridViewRow = rows(rows.Count -1) 
row(4) = EndTime 
row(5) = Diff 

這是不必要的每按下按鈕設置數據網格視圖的屬性,以便所有關於列名的代碼都可以被刪除,只讀設置也可以被刪除。

相關問題