VB datagrid row and column

I am trying to access MDB data with a datagrid in VB Express.  I have a datagrid called design and am trying to use values from the grid columns to draw lines in the picturebox.  

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Draw.Click


        Dim bit As Bitmap = New Bitmap(Picturebox1.Width, Picturebox1.Height)
        Dim g As Graphics = Graphics.FromImage(bit)
        Dim myPen As Pen = New Pen(Color.White, 0.5)
        Dim design As DataGridView

        Dim H, W, D, L, B, T 'dimensions and locations from grid Design
        Dim M As Integer
        W = design(1, 1)
        D = design(1, 1)
        M = 20
        g.DrawLine(myPen, 0, 5, Picturebox1.Width, Picturebox1.Height)
        g.DrawLine(myPen, M, M + H, M + W, M + H)
        Picturebox1.Image = bit

    End Sub

But this does not work.  Help please...

Dave
eeprogramsAsked:
Who is Participating?
 
Bob LearnedCommented:
1) If you are a VB6 developer by trade, than I can still feel your pain.  I have finally made the transition, but it was a long painful road.

2) Tell me what you are trying to do, and I will try to explain so that you can understand how to use a DataGridView.

3) This previously answered question has an example DataGridView form + designer that you can take a look at:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21765949.html

Bob
0
 
Bob LearnedCommented:
Dave,

Are you getting an exception, like "Object variable not set"?

Bob
0
 
eeprogramsAuthor Commented:
Bob,

The message is on the line W = design (1,1) and it says Variable 'design' is used before it has been assigned a value.  A null reference exception could result at runtime.

When I run it I get Object reference not set to create a object instance.

The grid is bound to the dtabase and the data in the db shows on the screen in the grid display.


Thanks,

Dave
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Bob LearnedCommented:
1) If you have a DataGridView on the form, called 'design', then this line will cause you problems:

   Dim design As DataGridView

   The problem is that it hides the module-level 'design', and doesn't allow access to the control.

2) When you declare a line like that with 2005, you need to declare it like this to avoid that warning:

   Dim design As DataGridView = Nothing

Bob
0
 
eeprogramsAuthor Commented:
Sorry -- frustrated and blew that code away.

I can't seem to understand get the whole datagridview thing.

What I am trying to do is have a datgridview with mulitple rows how distances of lines at multiple columns.  I would like to be able to draw those lines on a picture box.

I had this working ok in vb6 - but net is killing me.

Dave
0
 
eeprogramsAuthor Commented:
Bob,

I may have sent this already.

I see by your code you're a sports guy.  I designed the basketball product at www.statkeeper.com while I was coaching.  That got me into VB becuase I eventually I ended up fixing bugs when the contractor(s) who wrote the code moved on.

I build furniture and thought a simple design aid would help me.  I'd like to have a grid or parts and dimensions -- rows hold components (such as the front) and columns would hold the part name and H,W,D dimensions.  By chainging the dimesnions I could explore design alternatives.

I'd like to use the H,W,D values to draw lines on a picturebox.  It really seems pretty simple and I had it more or less running in VB6 - but thought I'd try in VB.NET (the future??? -- It does seem to have some nice features.)

If you can just set up the basics (if that's not too much to ask) - then I can foolk with it.

Thanks,

Dave
0
 
Bob LearnedCommented:
I used to live in St. Louis for about 5 years, and became a Cardinals fan.  I also like stats, too.  My old job used to be with a company that sold Statistical Process Control software written in VB6.

Let me see if I can understand what you are doing:

1) Example data:

   Component       Part                  Height (in.)    Width (in.)    Depth (in.)
   -------------       -----                  -----------     -----------      ------------
   Desk                 Drawer             6                  18                24

2) Are you looking to draw in 3-D?

3) Is there only 1 PictureBox, or should there be a column in the DataGridView to display the picture?

Bob
0
 
eeprogramsAuthor Commented:
Bob,

Yes a bit as you have it -- although the desk has six views -- one per side.  So like this:

Component      View            H "       W "     D  "   Material type (drop down list select)
Desk                 front           36        48     24      OAK board
                        right side    36         24    48       pylwood
                        left side       36        24    48       etc
                        top            n/a         48    24       etc
                        bottom       n/a         48    24      etc

In the default view only the front and side would show in 2d.  

Compexity abounds -- side views may contain drawers and such and they would be, in my idea, 'sub reports' or 'subs' rows of the view on which they exist.  For example -- clicking on 'front' view would open more rows in which I could locate drawer positions by locating them X inches from bottom and y inches from left of view.  However -- the basic rows above would do nicely.

The diagram would appear in 2d in the picture box -- with the front and one side as the default view.  

Things that would happen later:

There would be a need to erase the image or a line of the image.  I did this by redrawing the line with the background color.  

In the vb6 version I allow scaling of image -- since it must fit into the picturebox.

Filling in collor might be nice as well.  

I'm thinking of only rectanges and squares -- curves are later if ever.

3d would be the cat's pajamas -- but not really a requirement if too complex.  I thought DirectX might do this in the future.

There's more to it -- but this is the skeleton.  I see this as something to add onto as I use it and learn what's missing.


Thanks again,

Dave
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.