|
-
Apr 22nd, 2008, 01:48 PM
#1
Thread Starter
Member
[RESOLVED] Index out of range exception
Hi Techies
I recently added code to a form event called Shown to make certain cells of each row of my datagridview read-only. Then I set the focus of the datagridview to the last entry of the dgv with the following code.
dgvCashJournal.Focus()
dgvCashJournal.CurrentCell = dgvCashJournal(0,
dgvCashJournal.RowCount - 1)
The problem I am having is I get an index out of range exception when I attempt to do anything after the dgv is displayed. I cannot exit the routine or refresh the data. The person who gave me the original code is no longer available. I know I need to put some code in place to handle this exception but don't know where or how. Can anyone help?
Papiens
-
Apr 22nd, 2008, 02:30 PM
#2
Re: Index out of range exception
Just put your code in a If block like this, that is you only set the currentcell if you have at least a row in your datagridview.
Code:
Dim rowCount As Integer = dgvCashJournal.Rows.Count
If rowCount > 0 Then
dgvCashJournal.Focus()
dgvCashJournal.CurrentCell = dgvCashJournal.Item(0, rowCount - 1)
End If
-
Jul 21st, 2008, 03:41 PM
#3
Thread Starter
Member
Re: [RESOLVED] Index out of range exception
stanav
thanks for the heads up. I have already resolved this issue and forgot I had this request out. Thanks for your time.
Papiens
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|