473,490 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing a Datagrid from Within a Class

I'm really stuck on this, I just can't seem to figure it out. In the
code below I read the item property of a Datagrid I have on my form.
However, I get an error about the datagrid1 part saying "Reference to a
non-shared member requires an object reference." How do I go about
creating a reference to my datagrid? I'd be eternally grateful to
anyone who can help me with this as I just can't seem to make any
progress with this.

Here's my code:

Public Class PrintStatement
Inherits PrintDocument
Protected Overrides Sub OnPrintPage(ByVal e As
PrintPageEventArgs)
MyBase.OnPrintPage(e)

Dim fnt As New Font("Courier New", 8, FontStyle.Regular,
GraphicsUnit.Point)

Dim LineX As Integer = 0
'loop through every row in the dataset
Dim iCtr As Integer
For iCtr = 0 To dsCashSale.Tables("dtCashSale").Rows.Count
- 1
e.Graphics.DrawString(Datagrid1.Item(iCtr, 1), fnt,
Brushes.Black, 20, LineX)
LineX = LineX + 12
Next

fnt.Dispose()
' Indicate that there are no more pages.
e.HasMorePages = False

End Sub
End Class

Nov 21 '05 #1
1 1082
Hi,

Try something like this.

Public Class PrintStatement
Inherits PrintDocument

dim dg as datagrid
dim dscashsale as datagrid

public sub New(byval MyDatagrid as datagrid, MyDataSet as dataset)
dg=mydatagrid
dscashsale=mydataset
end sub

Protected Overrides Sub OnPrintPage(ByVal e As
PrintPageEventArgs)
MyBase.OnPrintPage(e)

Dim fnt As New Font("Courier New", 8, FontStyle.Regular,
GraphicsUnit.Point)

Dim LineX As Integer = 0
'loop through every row in the dataset
Dim iCtr As Integer
For iCtr = 0 To dsCashSale.Tables("dtCashSale").Rows.Count
- 1
e.Graphics.DrawString(dg.Item(iCtr, 1), fnt,
Brushes.Black, 20, LineX)
LineX = LineX + 12
Next

fnt.Dispose()
' Indicate that there are no more pages.
e.HasMorePages = False

End Sub
End Class

Ken
----------------------------
"Jasper Jones" <ja*******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I'm really stuck on this, I just can't seem to figure it out. In the
code below I read the item property of a Datagrid I have on my form.
However, I get an error about the datagrid1 part saying "Reference to a
non-shared member requires an object reference." How do I go about
creating a reference to my datagrid? I'd be eternally grateful to
anyone who can help me with this as I just can't seem to make any
progress with this.

Here's my code:

Public Class PrintStatement
Inherits PrintDocument
Protected Overrides Sub OnPrintPage(ByVal e As
PrintPageEventArgs)
MyBase.OnPrintPage(e)

Dim fnt As New Font("Courier New", 8, FontStyle.Regular,
GraphicsUnit.Point)

Dim LineX As Integer = 0
'loop through every row in the dataset
Dim iCtr As Integer
For iCtr = 0 To dsCashSale.Tables("dtCashSale").Rows.Count
- 1
e.Graphics.DrawString(Datagrid1.Item(iCtr, 1), fnt,
Brushes.Black, 20, LineX)
LineX = LineX + 12
Next

fnt.Dispose()
' Indicate that there are no more pages.
e.HasMorePages = False

End Sub
End Class
Nov 21 '05 #2

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

Similar topics

1
3642
by: TB | last post by:
Relatively new to .NET so please bear with me... I'm making an ASP.NET web application and am using VB to code. I'll try to set the stage here... The class and property names are generic to make...
0
1121
by: TB | last post by:
(re-wording a previous post.. this makes much more sense, sorry for any duplication) First off, I've got three classes: Class MyItem Public PropertyOne As String Public PropertyTwo As String...
1
1624
by: Vagabond Software | last post by:
I am creating a custom datagrid based, in part, from someone else's code. The author declared a derived datagrid class in a windows form, then declared a derived ColumnStyle class, in the same form,...
1
1158
by: Jim | last post by:
I have a class that inherits from the DataGrid class. I want to know when the datasource of my datagrid has changed, but want to execute a function within my extended datagrid class. For...
3
1633
by: Craig G | last post by:
i have a user control which is basically a datagrid, which has add/edit/delete buttons on the grid is there anyway of accessing the actual datagrid from the form itself? basically i want to...
2
6371
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
3
1402
by: CJ | last post by:
I have a page with a bunch of iframes (which make up a tab control). At least one of these iframes contains an aspx page, which in turn contains a .ascx component. This component then contains a...
0
2780
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
2
3424
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
0
7112
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
7146
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
7183
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...
1
6852
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...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
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...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.