Question on Sample Code

W

WStoreyII

I downloaded this tutorial from the msdn? @
http://msdn.microsoft.com/library/d...tingWindowsFormsDataGridVisualBasicPrimer.asp

Now my question though is on this sub:

Public Class ColoredTextBoxColumn
Inherits DataGridTextBoxColumn

Protected Overloads Overrides Sub Paint(ByVal graph As Graphics, _
ByVal rectbounds As Rectangle, ByVal curmngrSrc As _
CurrencyManager, ByVal RowNumber As Integer, ByVal _
ForeColorBrush As Brush, ByVal BackColorBrush As Brush, _
ByVal AlignmentRight As Boolean)

Dim ObjVal As Object
ObjVal = Me.GetColumnValueAtRow(curmngrSrc, RowNumber)

If Not (IsNothing(ObjVal) Or IsDBNull (ObjVal)) Then
Dim cellValue As Integer
cellValue = CType(ObjVal, Integer)
If (cellValue > 1) Then
' Here is where we are going to do
' the actual painting.
' Color the contents of the cell Red
' and the background of the cell Yellow.
BackColorBrush = Brushes.Yellow
ForeColorBrush = Brushes.Red
Else
BackColorBrush = Brushes.White
ForeColorBrush = Brushes.Black
End If
End If

' Call Paint from the base class to
' accomplish the actual drawing.
MyBase.Paint(graph, rectbounds, curmngrSrc, RowNumber, _
BackColorBrush, ForeColorBrush, AlignmentRight)
End Sub
End Class

What confuses me is that this code runs with out even being called. I have
racked this code all day and can not figure out why it does that or how i
can mimick it
i also dont understand how this code works on all the cells in the grids. i
have not seen an loops in this code at all yet it works ???

WStoreyII
 
T

Tom Leylan

WStoreyII said:
What confuses me is that this code runs with out even being called. I have
racked this code all day and can not figure out why it does that or how i
can mimick it

You might save a considerable amount of time (spent wondering) if you find a
decent book on the theory behind Windows app development. Meanwhile
consider the following: You have a grid on a form. You run the app and the
time has come for the grid to display on that form. How does a grid get
drawn?

There is method included to draw the grid, it is named "paint". But rather
than have it paint everything it was decided that grid columns could benefit
from having their own paint method. But how could developers affect the
display of grids, and buttons and forms and things? It was decided that the
Paint method could be made available to the developer and that way when it
came time to paint (whenever Windows decides it's needed) custom code could
run (instead of or in addition to) the normal code that executes.

Seriously, you can stare at this stuff for years on end and the light bulb
won't go off. That's why books on fundamentals and theory are so valuable.

Now... why is there Overrides, Overloads and Protected in front of the Sub
and why does it call MyBase.Paint?

Tom
 
W

WStoreyII

I agree about the books if i could afford to i would by a everyone that i
could get my hands on. But unfortunately with two car payments insurance
and a 6 month old daugther i dont have a penny left to blow my nose so i
have to try to figure this stuff out the hard way. I am however in school
in a cis program at devry online and i have ten hour days to work on it at
work. i just cant afford the books now.

However just for my knowledge when i get a couple of spare books what is a
good set
not just a book but is there a decent set that comes with like basic
intermediate advance and then like data and web ect. if not what is a good
book for some one at my level ?

WStoreyII
 
C

Cor

Hi WStoryII

I find the quality of the VB resource kit mostly better than the most books
I have seen.

When you have taken a look at it, and took some time it is a very good
instructor for a start from the most things.

(One of the lacks is the updating of a database with a dataadapter and a
dataset in my opinion).

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbrkit/faq/#installvdir

I hope this helps a little bit?

Cor
 
T

Tom Leylan

WStoreyII said:
I agree about the books if i could afford to i would by a everyone that i
could get my hands on.

They don't actually have to be "purchased" they need only be "read." Many
are available in libraries, some can be read for free online and a few of
them are in the $1 bin at the book store.
However just for my knowledge when i get a couple of spare books what is a
good set not just a book but is there a decent set that comes with like basic
intermediate advance and then like data and web ect. if not what is a good
book for some one at my level ?

Unfortunately books don't come in two flavors "good" and "not good" :) I
never know where good information is going to come from and often find one
good chapter in an otherwise bland book. That same book might be great to
somebody who hadn't read anything on the subject before however and the cool
thing I just learned could easily be of no interest to someone else.

Don't mean to belabor the point (and I may have mentioned it here before)
but I wrote an article long ago (1995) titled "Look Towards the Past" which
described how you could learn how to solve problems using today's tools by
reading code presented decades earlier in languages you may have never heard
about. One example is from a Z80 Assembly Language book published in 1979.
I also recommended reading The Elements of Programming Style by Kernighan
and Plaugher published originally in 1974.

Less than a month ago I posted a recommendation here that people read a
particular on-line book on Java (it's free) to increase their understanding
of .Net. The more you look the more things look the same.

Tom
 
W

WStoreyII

you think that they have vb.net books in the library isnt it really new ?

WStoreyII
 
T

Tom Leylan

WStoreyII said:
you think that they have vb.net books in the library isnt it really new ?

I probably wasn't clear. I thought your question originally wasn't so much
about VB.Net as much as "what is paint and how is it called"? Those kinds
of books probably are in the library but search the Internet. There are all
sorts of book .Net-related as well as Windows-related, C, C++, Java,
object-orientation, etc. If there is a University near you I've found them
to be an excellent source of technical books.

I was trying to point out to you (and to anyone else reading this) that you
can concentrate too much on the language. It's just a language. It is like
suggesting that one must learn English in order to write a great book. Of
course you eventually do need to know the syntax, there is no getting around
it but programming computers (or for Windows) didn't start a couple of years
ago when .Net was released.

In any case... best of luck,
Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top