Setting focus to a cell within a datagrid with no data in it

GornHorse

Well-known member
Joined
May 27, 2003
Messages
105
Location
Australia
Hi There,

I need to set focus to the first column of a new row in a datagrid.

Everytime i try to set focus to the cell, it comes back with an error.

If i try to create a new row and then try to set focus to it, it continually keeps creating new rows (it seems to put itself into a continuous cycle, because i certainly didnt put it in any cycle!).

I have a datagrid with a datatable as the datasource. There is no data in the datatable during design time, the user enters this while the program is open. When they get to column 6, columns 7, 8, and 9 are dynamically input by the system (this works fine). However, after i have dynamically entered the data into column 9, i want to set the focus to cell(currentrow + 1, 0) so that the user can begin entering the next line of data immediately.

However, the focus just wont set.

Here is my code:


Sub BatchPayments_AutoFillDetails(ByVal sender As Object, ByVal e As EventArgs) Handles dgBatchPayments.CurrentCellChanged
Dim currcellcol As Integer
Dim currcellrow As Integer
Dim membernolookup As String
Dim memberfname As String
Dim membersname As String
Dim memberinits As String
currcellcol = dgBatchPayments.CurrentCell.ColumnNumber
currcellrow = dgBatchPayments.CurrentCell.RowNumber
If currcellcol = 1 Then
dgBatchPayments.Item(currcellrow, 0) = String.Format("{0:C}", CDbl(dgBatchPayments.Item(currcellrow, 0)))
End If
If currcellcol = 6 Then
membernolookup = dgBatchPayments.Item(currcellrow, 5)
MADConnector is my own class
SessionObj = MADConnector.MAD_Connect()
FileObj = MADConnector.InitializeFileObject("MEMBER")
memberfname = MADConnector.Retrieve1ValueFromRecord(FileObj, 2, membernolookup)
membersname = MADConnector.Retrieve1ValueFromRecord(FileObj, 1, membernolookup)
MADConnector.MAD_CloseFile(FileObj)
MADConnector.MAD_Disconnect(SessionObj)
memberfname = memberfname.Remove(1, (memberfname.Length - 1))
If membersname.Length > 5 Then
membersname = membersname.Remove(5, (membersname.Length - 5))
End If
memberinits = memberfname & " " & membersname
dgBatchPayments.Item(currcellrow, 6) = memberinits
Dim lysubscriptionbal As Integer
Dim yearforsubs As String
SessionObj = MADConnector.MAD_Connect()
FileObj = MADConnector.InitializeFileObject("TRANSACTION.INDEX")
lysubscriptionbal = CInt(MADConnector.Retrieve1ValueFromRecord(FileObj, 3, membernolookup))
MADConnector.MAD_CloseFile(FileObj)
MADConnector.MAD_Disconnect(SessionObj)
If lysubscriptionbal > 0 Then
yearforsubs = (Format(System.DateTime.Today, "yyyy")) - 1
Else
yearforsubs = Format(System.DateTime.Today, "yyyy")
End If
dgBatchPayments.Item(currcellrow, 7) = dgBatchPayments.Item(currcellrow, 0)
Dim gstamount As Double
gstamount = CDbl(dgBatchPayments.Item(currcellrow, 7)) / 11
dgBatchPayments.Item(currcellrow, 8) = yearforsubs
dgBatchPayments.Item(currcellrow, 9) = String.Format("{0:C}", gstamount)
cumulativetotal = cumulativetotal + CDec(dgBatchPayments.Item(currcellrow, 0))
cumulativenumpayments = cumulativenumpayments + 1
Me.tbAmountTotal.Text = String.Format("{0:C}", CDbl(cumulativetotal))
Me.tbCount.Text = cumulativenumpayments

if i try this on its own, it comes back with an error
dgBatchPayments.CurrentCell = dgBatchPayments(currcellrow + 1, 0)

i have also tried using this in place of the above, but it loops over
the dt.rows.add() continually without breaking for some reason...
dt.Rows.Add(dt.NewRow())
dgBatchPayments.CurrentCell = dgBatchPayments(currcellrow + 1, 0)
End If
End Sub


Please provide some assistance with this, as its really beginning to frustrate me!!!


Regards,
Michelle
 
Hi There,

after much deliberation, it wasnt that hard at all. The following is the code:

myGrid.CurrentCell = New DataGridCell(1,1)

Not hard at all!!!

Its always something small??!!

Cheers,
Michelle
 
Back
Top