Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing datagridview from form to class

0 views
Skip to first unread message

LuvinLunch

unread,
Dec 22, 2009, 7:18:22 AM12/22/09
to
Hi,

I need some advice on how to use a datagridview properly. I'm
converting a vb6 app to vb.net. In the vb6 application I was passing
an empty datagrid by referene to a class I'd written, I was populating
the datagrid and passing it back to the form all set up for action.

I've tried doing the same in vb.net but the class I've written doesn't
recognise the datagridview. So my question is, is passing the
datagridview from a form class to a class I've written the best way to
populate my datagridview? I'm really keen to have the populating of
the grid done in the class and not on the form. Should I be
inheriting the grid into the class? Is the way I'm passing it
incorrect?

All advice gratefully received.

LL

Joe Cool

unread,
Dec 22, 2009, 9:18:20 AM12/22/09
to

I'm not sure but it sounds like the problem is that you don't have an:

Imports System.Windows.Forms

statement in the class.

LuvinLunch

unread,
Dec 22, 2009, 9:45:42 AM12/22/09
to
Joe Cool,

You're right. Oh dear, the joys of a new language.

Thanks a million for your help.

LL

Gregory A. Beamer

unread,
Dec 22, 2009, 4:01:37 PM12/22/09
to
LuvinLunch <martin...@yahoo.ie> wrote in news:d21e0201-9edc-47ae-
bef4-d35...@r5g2000yqb.googlegroups.com:

> I've tried doing the same in vb.net but the class I've written doesn't
> recognise the datagridview. So my question is, is passing the
> datagridview from a form class to a class I've written the best way to
> populate my datagridview? I'm really keen to have the populating of
> the grid done in the class and not on the form. Should I be
> inheriting the grid into the class? Is the way I'm passing it
> incorrect?

I am going to counter what "Joe" stated. In a "proper" app, the middle
tier works with data as objects, not as pulled from controls. You are
best to archtiect the solution so the bound data is what you are passing
and not some view from a DataGrid. When you start working with UI
controls, you tightly bind to the UI, making it hard to ever produce
another type of UI for the app without rewriting a huge portion of the
code.

Yes, this may not be an issue for you, but it is something to think
about esp. with the new technology being projectile vomited out at a
high pace.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

Cor Ligthert[MVP]

unread,
Dec 23, 2009, 1:52:14 PM12/23/09
to
The datagridview (but that not alone) has a datasource, that is the way you
handle it after VB6.
Simply pass the content of the datasource (always an Ilist implementing
type, but much more variations than the recordset)

The only trouble can be as it is a anonymous class, but even that you can
first convert tolist.

Cor

"LuvinLunch" <martin...@yahoo.ie> wrote in message
news:d21e0201-9edc-47ae...@r5g2000yqb.googlegroups.com...

LuvinLunch

unread,
Jan 4, 2010, 6:38:59 AM1/4/10
to
Hi Gregory and Cor,

Thanks a million for the advice. I thought there might be something I
shoudl be doing that would make the upkeep of my code easier but I
just didnt' know what it was. If either had some sample code of what
you've suggested it'd be much appreciated.

LL

0 new messages