473,388 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

VB.NET Datagrid Problem

Hi,

I have a form containing a datagrid where users can enter in their
specified information for each row and column. Behind the scenes I
have a sub which handles datagrid.CurrentCellChanged because I need to
be able to execute some code whenever a user clicks in a different
cell of the datagrid. Inside this sub I place the datagrid.datasource
into a data table so that I can work with it's contents. However, I
am getting "Out of Range" errors sometimes when I try to execute this
code:

Dim index As Integer = dgRentPool.CurrentRowIndex
Dim tbl As DataTable = dgRentPool.DataSource
Dim row As DataRow

row = tbl.Rows(index)

It appears that occasionally even though the datagrid recognizes that
the current row is "1" for example, the number of rows contained in
the datagrid.datasource is only 1 instead of 2.

Does anyone have any ideas on what is causing this error and how I can
resolve it??

Thanks!!

Joy
Nov 21 '05 #1
4 2988

August 9, 2004

You are getting that because the array of rows is zero-based.
Try using this statement instead:

row = tbl.Rows(index - 1)

All arrays in Visual Studio are zero-based. Have a nice day!

Joseph MCP
"si***********@yahoo.com" wrote:
Hi,

I have a form containing a datagrid where users can enter in their
specified information for each row and column. Behind the scenes I
have a sub which handles datagrid.CurrentCellChanged because I need to
be able to execute some code whenever a user clicks in a different
cell of the datagrid. Inside this sub I place the datagrid.datasource
into a data table so that I can work with it's contents. However, I
am getting "Out of Range" errors sometimes when I try to execute this
code:

Dim index As Integer = dgRentPool.CurrentRowIndex
Dim tbl As DataTable = dgRentPool.DataSource
Dim row As DataRow

row = tbl.Rows(index)

It appears that occasionally even though the datagrid recognizes that
the current row is "1" for example, the number of rows contained in
the datagrid.datasource is only 1 instead of 2.

Does anyone have any ideas on what is causing this error and how I can
resolve it??

Thanks!!

Joy

Nov 21 '05 #2
Thank you but when I try the code you suggested:

row = tbl.Rows(index - 1)

I get an "Out of Bounds" error as well because the following statement:

Dim index As Integer = dgRentPool.CurrentRowIndex

returns the value of 0 for the first row in the datagrid. Any other
suggestions??

Joy


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

August 9, 2004

This is just a theory, but try stepping through the code and
making sure that when you assign the datatable to the source,
that the table really is populated with the information. If you
assigned the datagrid's datasource property with a dataset, then
you might try this code instead...

dim tbl as datatable = Dataset.Tables(Table#) ' Or .(TableName)

Just a theory, but I would see if the table was populated, before
calling the row = ..... line.
Joseph MCP
"Joy Labadie" wrote:
Thank you but when I try the code you suggested:

row = tbl.Rows(index - 1)

I get an "Out of Bounds" error as well because the following statement:

Dim index As Integer = dgRentPool.CurrentRowIndex

returns the value of 0 for the first row in the datagrid. Any other
suggestions??

Joy


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #4
In my form's New() sub I do the following:

Dim tblRentPool As DataTable = New DataTable
Dim row As DataRow

tblRentPool.Columns.Add("Months")
row = tblRentPool.NewRow()
tblRentPool.Rows.Add(row)

dgRentPool.DataSource = tblRentPool

I want the user to be able to enter in the information for the datagrid
at run-time. By default a datagrid creates a row beneath the current
row the user is working on so the user can continue populating the
datagrid when they finish filling out the current row.

However, when the user then clicks on this new row provided by the
datagrid and it calls the datagrid.CurrentCellChanged sub, it is not
able to find the corresponding row in the datagrid.datasource. So it
appears the datagrid is not updating the data table associated with the
datasource when it creates this new row visually in the datagrid.

Isn't the datagrid.datasource supposed to keep track of this
information?

Joy
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.