473,397 Members | 2,084 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,397 software developers and data experts.

Why would DataGridView.ColumnCount be valid on one form and be 0 when referenced from

I use the following code to populate and format a DataGridView on one form:
Expand|Select|Wrap|Line Numbers
  1.         Dim qryString As String = "SELECT tblBasicData.DataField1 AS Item, tblBasicData.DataField2 AS Hazard, " &
  2.             "tblHIDChecklist.[Exists (Y/N)] AS [Exists], tblHIDChecklist.Description, tblBasicData.DataOrder " &
  3.             "FROM tblBasicData INNER JOIN tblHIDChecklist ON tblBasicData.BasicDataUID = tblHIDChecklist.BasicDataUID " &
  4.             "WHERE (((tblHIDChecklist.Export)=True)) " &
  5.             "UNION " &
  6.             "SELECT tblHIDDetail.HIDDetailUID AS Item, tblHIDDetail.Description AS Hazard, " &
  7.             "tblHIDDetail.Quantity AS [Exists], tblHIDDetail.Units AS Descripition, tblBasicData.DataOrder " &
  8.             "FROM (tblBasicData INNER JOIN tblHIDChecklist ON tblBasicData.BasicDataUID = tblHIDChecklist.BasicDataUID) " &
  9.             "INNER JOIN tblHIDDetail ON tblHIDChecklist.HIDChecklistUID = tblHIDDetail.HIDChecklistUID " &
  10.             "ORDER BY DataOrder;"
  11.  
  12.         ConnDB()
  13.         Dim cmd As New System.Data.OleDb.OleDbCommand(qryString, Conn)
  14.         dapDGV.SelectCommand = New OleDb.OleDbCommand(qryString, Conn)
  15.  
  16.         Dim cmb As New System.Data.OleDb.OleDbCommandBuilder(dapDGV)
  17.         dapDGV.Fill(dasDGV)
  18.         dgvExport.DataSource = dasDGV.Tables(0)
  19.         Conn.Close()
  20.         dgvExport.Columns("DataOrder").Visible = False
  21.         If dasDGV.Tables(0).Rows.Count > 0 Then
  22.             'Sequence through dataset and remove UIDs from any Detail records.
  23.             'Convert any -1 or 0s to blanks in all checklist records
  24.             For iRow As Integer = 0 To dgvExport.Rows.Count - 1
  25.                 If Len(dgvExport.Rows(iRow).Cells("Item").Value) = 36 Then
  26.                     dgvExport.Rows(iRow).Cells("Item").Value = ""
  27.                 End If
  28.                 If dgvExport.Rows(iRow).Cells("Exists").Value = -1 Then
  29.                     dgvExport.Rows(iRow).Cells("Exists").Value = ""
  30.                 ElseIf dgvExport.Rows(iRow).Cells("Exists").Value = 0 Then
  31.                     dgvExport.Rows(iRow).Cells("Exists").Value = ""
  32.                 End If
  33.             Next
  34.         Else
  35.             MsgBox("No records have been identified for export.")
  36.         End If
  37.  
  38.         MsgBox(dgvExport.ColumnCount)
  39. End Sub
I open a 2nd form using Form2.Show() where the first step is :
Expand|Select|Wrap|Line Numbers
  1. MsgBox(frmHazCatExport.dgvExport.ColumnCount)
When I test the routine, the first form shows data and the msgbox displays that there are 5 columns in the datagridview. However, when I open the 2nd form the msgbox displays that the columncount is 0. I am running this test because I'm trying to access columns in the datagridview but I am only able to access the form and the DGV itself. Anything beyond that (i.e., rows, columns) generates an error I assume because form2 thinks there are 0 columns in the DGV on the first form. The error generated is "Reference to a non-shared member requires an object reference." I'm confused. How can the form1 tell me there are 5 columns and the "next" step tell me there are 0 columns?
May 10 '17 #1
1 1581
Frinavale
9,735 Expert Mod 8TB
When you open form2 do you have a proper reference to the instantiated form1?

Is your Grid View public?

Did you consider adding a property "column count" in Form 1 that you can access in Form 2?
May 11 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Raj | last post by:
I have a c# program in which I used cast. That worked perfectly on .Net platform 1.0. When I moved to .Net 2003, I am getting the execption "Specified cast is not valid". I have not made any...
2
by: Krzysztof Karnicki | last post by:
I would like develop Form on my Windows Application, that is going to notify the user, just like Microsoft Office 2003 shows that there are new mail coming. When I use System.Windows.Forms.Form and...
3
by: Jon S via DotNetMonster.com | last post by:
Hi all, I'm having a problem updating a simple change I've made to a Access 2000 table through databinding. The error I get is : An unhandled exception of type...
1
by: Ya Ya | last post by:
I am developing a DLL (class library) for a web application of mine. In the web.config of the web application I have set: culture="en-GB" uiCulture="en" in order that the date format will be...
1
by: Nathan Sokalski | last post by:
When testing a form of mine which uses RequiredFieldValidators that have the Display property set to "Dynamic" the ErrorMessage property is automatically removed when an entry is completely typed...
1
by: Henry Lee | last post by:
hi , all This is driving me crazy , I use msgbox method in .net 2.0 environment and it is running fine on my IIS (Windows 2000) until today. The error is like "Showing a modal dialog box or form...
1
by: Greg | last post by:
I'm using a DataGridView object bound to an xml datasource. I have added 2 unbound columns which are populated based on the calculations of data from other columns. When the data in the other...
0
by: hangdee | last post by:
I want to create 2 same structure datagridview in a form. But when I set same column name in datagridview, it prompts that same name is used by another component. So is it true that we cannot...
8
by: blknmld69 | last post by:
I am working on a major project. I keep getting the error non-static variable calcGrade cannot be referenced from a static context calcGrade.studentList = new Student(); import java.util.*; ...
5
oll3i
by: oll3i | last post by:
public IBagResult cartesianProduct(IAbstractQueryResult resLeft, IAbstractQueryResult resRight){ method inside } } IBagResult commaRes =...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.