SlideShare a Scribd company logo
1
Visual Basic .Net
BT0082 Part-2
BY milan K Antony
1.Describe the Data Form Wizard in Visual Studio .NET.
VB.Net allows you many ways to connect to a database or a data source.The technology
2
used to interact with a database or data source is called ADO.NET. The ADO parts stands for
Active Data Objects which, admittedly,
doesn’t explain much. But just like System was a Base Class (leader of a hierarchy, if you like), so
is ADO. Forming the foundation of the ADO Base Class are five other major objects:
Connection
, Command
, DataReader
, DataSet
, DataAdapter
The Connection Object is what you need if you want to connect to a database. There are a number
of different connection objects, and the one you use depends largely on the type of database you're
connecting to. LE stands for Object Linking and Embedding, and it’s basically a lot of objects
(COM objects) bundled together that allow you to connect to data sources in general, and not just
databases. You can use it, for example, to connect to text files, SQL Server, email, and a whole lot
more.
3
There are a number of different OLE DB objects (called data providers), but the one we'll use is
called "Jet". Others are SQL Server and Oracle. Whichever version you have, though, the variable
con will now hold the
Connection Object. Notice that there is a full stop after the OleDB part. You'll then get a pop up
box from where you can select OleDbConnection. This is the object that you use to connect to an
Access database.
So place a button on your form. Change the Name property to btnLoad. Double click your button to
open up the code window. here are Properties and Methods associated with the Connection Object,
of course. We want to start with the ConnectionString property. This can take many parameters.
Fortunately, we only need a few of these.
We need to pass two things to our new Connection Object: the technology we want to use to do the
connecting to our database; and where the database is. (If your database was password and user
name protected, you
would add these two parameters as well. Ours isn't, so we only need the two.)
The technology is called the Provider; and you use "Data Source" to specify where your database
is.
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
Source = C:AddressBook.mdb"
Notice the two parts, separated by a semi-colon:
1st Part: PROVIDER=Microsoft.Jet.OLEDB.4.0
2nd Part: Data Source = C:AddressBook.mdb
The first part specifies which provider technology we want to use to do the connecting (JET). The
second part, typed after a semi-colon, points to where the database is. In the above code, the
database is on the C drive, in
4
the root folder. The name of the Acc ess file we want to connect to is called AddressBook.mdb.
connecting (JET). The second part, typed after a semi-colon, points to
where the database is. In the above code, the database is on the C drive, in the root folder. The name
of the Access file we want to connect to is called AddressBook.mdb. (Note that "Data Source" is
two words, and not one.) But your coding window should now look like this:
Private Sub btnLoad_Click(ByVal Sender as Object,_
ByVal e as System.EventArgs) _
Handles btnLoad.Click
Dim con as new OleDb.OleDbConnection
Con.ConnectionString = “Provider = Microsoft.Jet.OLEDB.4.0; DataSource
= C:AddressBook.mdb”
This assumes that you have copied the AddressBook database over to the
root folder of your C Drive. If you've copied it to another folder, change the
"Data Source" part to match. For example, if you copied it to a folder called "databases" you'd put
this:
Data Source = C:databasesAddressBook.mdb
In our code , though, ConnectionString is a property of the con variable. The con variable holds our
Connection Object. We're passing the Connection String the name of a data provider, and a path to
the database.
1.Describe the concept of record navigation in VB.NET.
o move backwards through the DataSet, we need to decrement the inc counter. This means
is deducting 1 from whatever is currently in inc. But we also need to check that inc doesn't go past
zero, which is the first
record in the DataSet. Here's the code to add to your btnPrevious:
5
If inc > 0 Then
inc = inc - 1
NavigateRecords()
Else
MsgBox("First Record")
End If
So the If statement first checks that inc is greater than zero. If it is, inc gets 1 deducted from. Then
the NavigateRecords() subroutine gets called. If inc
is zero or less, then we display a message.
When you've finished adding the code, test your program out. Click the Previous button first. The
message box should display, even though no records have been loaded into the textboxes. This is
because the variable
inc has a value of -1 when the form first loads. It only gets moved on to zero when the Next button
is clicked. You could amend your IF Statement to this:
If inc > 0 Then
inc = inc - 1
NavigateRecords()
ElseIf inc = -1 Then
MsgBox("No Records Yet")
ElseIf inc = 0 Then
MsgBox("First Record")
End If
This new If Statement now checks to see if inc is equal to minus 1, and displays a message if it
6
does. It also checks if inc is equal to zero, and displays the "First Record" message box.
(ii) Moving to the Last Record in the DataSet
To jump to the last record in the DataSet, you only need to know how many records have been
loaded into the DataSet - the MaxRows variable in our code. You can then set the inc counter to that
value, but minus 1. Here's the code to add to your btnLast:
if inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
The reason we're saying MaxRows - 1 is that the row count might be 5, say, but the first record in
the DataSet starts at zero. So the total number of records would be zero to 4. Inside of the If
Statement, we're setting the inc counter to MaxRows - 1, then calling thE NavigateRecords()
subroutine.
That's all we need to do. So run your program. Click the Last button, and you should see the last
record displayed in your textboxes.
Moving to the First Record in the DataSet
Moving to the first record is fairly straightforward. We only need to set the inc counter to zero, if
it's not already at that value. Then call the Sub:
If inc <> 0 Then
inc = 0
NavigateRecords()
End If
Add the code to your btnFirst. Run your program and test out all of your buttons. You should be
able to move through the names in the database, and jump to the first and last records.
7
2.Explain the theory behind declaring arrays in VB.NET.
Arrays occupy space in memory. The programmer specifies the array type and the number
of elements required by the array so that the compiler may
reserve the appropriate amount of memory. Arrays may be declared as Public (in a code module),
module or local. Module arrays are declared in the general declarations using keyword Dim or
Private. Local arrays are
declared in a procedure using Dim or Static. Ar ray must be declared explicitly with keyword "As".
There are two types of arrays in Visual Basic namely:
Fixed-Size Array: The size of array always remains the same-size doesn't change during the
program execution.
Dynamic Array: The size of the array can be changed at the run time- size changes during the
program execution.
When an upper bound is specified in the declaration, a Fixed-array is created. The upper limit
should always be within the range of long data type.
Declaring a fixed-array
Dim numbers(5) As Integer
In the above illustration, numbers is the name of the array, and the number
6 included in the parentheses is the upper limit of the array. The above declaration creates an array
with 6 elements, with index numbers running from 0 to 5.
If we want to specify the lower limit then the parentheses should include both the lower and upper
limit along with the To keyword. Arrays can have multiple dimensions. A common use of
multidimensional
arrays is to represent tables of values consisting of information arranged in rows and columns. To
identify a particular table element, we must specify
8
two indexes: The first (by convention) identifies the element's row and the second (by convention)
identifies the element's column. Tables or arrays that require two indexes to identify a particular
element are called two dimensional arrays. Note that multidimensional arrays can have more than
two dimensions. Visual Basic supports at least 60 array dimensions, but most people will need to
use more than two or three dimensional-arrays.
The following statement declares a two-dimensional array 50 by 50 array within a procedure.
Dim AvgMarks (50, 50)
It is also possible to define the lower limits for one or both the dimensions as for fixed size arrays.
An example for this is given here.
Dim Marks (101 To 200, 1 To 100)
Basically, you can create either static or dynamic arrays. Static arrays must include a fixed number
of iems, and this number must be known at compile
time so that the compiler can set aside the necessary amount of memory.You create a static array
using a Dim statement with a constant argument:
' This is a static array.
Dim Names(100) As String
Visual Basic starts indexing the array with 0. Therefore, the preceding array actually holds 101
items.
Most programs don't use static arrays because programmers rarely know at compile time how many
items you need and also because static arrays can't be resized during execution. Both these issues
are solved by dynamic
arrays. You declare and create dynamic arrays in two distinct steps. In general, you declare the
array to account for its visibility (for example, at the
beginning of a module if you want to make it visible by all the procedures of the module) using a
9
Dim command with an empty pair of brackets. Then you create the array when you actually need it,
using a ReDim statement:
' An array defined in a BAS module (with Private scope)
Dim Customers() As String
...
Sub Main()
' Here you create the array.
ReDim Customer(1000) As String
End Sub
if you don't specify the lower index of an array, Visual Basic assumes it to be 0, unless an Option
Base 1 statement is placed at the beginning of the module. My suggestion is this: Never use an
Option Base statement
because it makes code reuse more difficult. (You can't cut and paste routines wit hout worrying
about the current Option Base.) If you want to explicitly use a lower index different from 0, use
this syntax instead:
ReDim Customers(1 To 1000) As String
Dynamic arrays can be re-created at will, each time with a different number of items. When you re-
create a dynamic array, its contents are reset to 0 (or
to an empty string) and you lose the data it contains. If you want to resize an array without losing
its contents, use the ReDim Preserve command:
ReDim Preserve Customers(2000) As String
When you're resizing an array, you can't change the number of its dimensions nor the type of the
values it contains. Moreover, when you're
10
using ReDim Preserve on a multidimensional array, you can resize only its last dimension:
ReDim Cells(1 To 100, 10) As Integer
...
ReDim Preserve Cells(1 To 100, 20) As Integer ' This works.
ReDim Preserve Cells(1 To 200, 20) As Integer ' This doesn't.
Finally, you can destroy an array using the Erase statement. If the array is dynamic, Visual Basic
releases the memory allocated for its elements (and you can't read or write them any longer); if the
array is static, its elements are set to 0 or to empty strings.
UDT structures can include both static and dynamic arrays. Here's a sample structure that contains
both types:
Type MyUDT
StaticArr(100) As Long
DynamicArr() As Long
End Type
...
Dim udt As MyUDT
' You must DIMension the dynamic array before using it.
ReDim udt.DynamicArr(100) As Long
' You don't have to do that with static arrays.
udt.StaticArr(1) = 1234
The memory needed by a static array is allocated within the UDT structure; for example, the
StaticArr array in the preceding code snippet takes exactly 400 bytes. Conversely, a dynamic array
in a UDT takes only 4 bytes, which form a pointer to the memory area where the actual data is
stored. Dynamic arrays are advantageous when each individual UDT variable might host a
11
different number of array items. As with all dynamic arrays, if you don't dimension a dynamic
array within a UDT before accessing its items, you get an error 9—"Subscript out of range."
3.Describe the mechanism of creating transparent images using ImageList Control.
he ImageList control has a MaskColor property whose value determines the color
that should be considered transparent when you're performing
graphical operations on individual ListImage objects or when you're displaying images inside other
controls. By default, this is the gray color (&HC0C0C0), but you can change it both at design time
in the Color tab of
the Properties dialog box and at run time via code.
When a graphical operation is performed, none of the pixels in the image that are the color defined
by MaskColor are transferred. To actually display
transparent images, however, you must ensure that the UseMaskColor property is set to True,
which is its default value. You can modify this value in the General tab of the Properties dialog box
or at run time via code:
' Make white the transparent color.
ImageList1.MaskColor = vbWhite
4.Explain the design time property settings of a ListView Control.
While you can use the regular Properties window to set most properties of a
ListView control, it's surely preferable to use a ListView control's custom
Properties dialog box
12
The ListView
control supports four basic view modes: Icon, SmallIcon, List, and Report. To see how each mode
is rendered, try the corresponding items in the Windows Explorer View menu The ListView
control exposes two distinct collections: The ListItems collection comprises individual ListItem
objects, each one corresponding to
an item in the control, whereas the ColumnHeaders collection includes ColumnHeader objects that
affect the appearance of the individual headers visible in Report mode. A third collection,
ListSubItems, contains data for all the cells displayed in Report mode.
5.Describe the concept of setting a connection string with an example.
There are Properties and Methods associated with the Connection Object, of course. We
want to start with the ConnectionString property. This can take many parameters. Fortunately, we
only need a few of these.
We need to pass two things to our new Connection Object: the technology we want to use to do the
connecting to our database; and where the database is. (If your database was password and user
name protected, you
13
would add these two parameters as well. Ours isn't, so we only need thetwo.) The technology is
called the Provider; and you use "Data Source" to specify where your database is. This should be
entered on the same line, and not two as it is below. So add this to your code:
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data
Source = C:AddressBook.mdb"
Notice the two parts, separated by a semi-colon:
1st Part: PROVIDER=Microsoft.Jet.OLEDB.4.0
2nd Part: Data Source = C:AddressBook.mdb
The first part specifies which provider technology we want to use to do the connecting (JET). The
second part, typed after a semi-colon, points to where the database is. In the above code, the
database is on the C drive, in
the root folder. The name of the Access file we want to connect to is called AddressBook.mdb.
Private Sub btnLoad_Click(ByVal Sender as Object,_
ByVal e as System.EventArgs) _
Handles btnLoad.Click
Dim con as new OleDb.OleDbConnection
Con.ConnectionString = “Provider = Microsoft.Jet.OLEDB.4.0; DataSource
= C:AddressBook.mdb”
This assumes that you have copied the AddressBook database over to the root folder of your C
Drive. If you've copied it to another folder, change the "Data Source" part to match. For example, if
you copied it to a folder called "databases" you'd put this:
Data Source = C:databasesAddressBook.mdb
In our code , though, ConnectionString is a property of the con variable.The con variable holds our
Connection Object. We're passing the Connection String the name of a data provider, and a path to
14
the database. Describe the process of adding, updating, and deleting records with an example. The
button that gets switched on is the
Commit Changes button. The Enabled property of btnCommit gets set to True. But, for this to
work, you need to set it to False when the form loads. So return to your Form. Click btnCommit to
select it. Then locate the
Enabled Property in the Properties box. Set it to False. When the Form starts up, the button will be
switched off. The Clear/Cancel button can be used to switch it back on again. So add this code to
your btnClear:
btnCommit.Enabled = False
btnAddNew.Enabled = True
btnUpdate.Enabled = True
btnDelete.Enabled = True
inc = 0
NavigateRecords()
We're switching the Commit Changes button off, and the other three back on. The other two lines
just make sure that we display the first record again, after the Cancel button is clicked. Otherwise
the textboxes will all be blank. To add a new record to the database, we'll use the Commit Changes
button. So double click your btnCommit to access its code. Add the following:
If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("AddressBook").NewRow()
dsNewRow.Item("FirstName") = txtFirstName.Text
dsNewRow.Item("Surname") = txtSurname.Text
15
ds.Tables("AddressBook").Rows.Add(dsNewRow)
da.Update(ds, "AddressBook")
MsgBox("New Record added to the Database")
btnCommit.Enabled = False
btnAddNew.Enabled = True
btnUpdate.Enabled = True
btnDelete.Enabled = True
End If
The actual values we want to store in the rows are coming from the textboxes. So we have these two
lines:
dsNewRow.Item("FirstName") = txtFirstName.Text
dsNewRow.Item("Surname") = txtSurname.Text
The dsNewRow object we created has a Property called Item. This is like the Item property you
used earlier. It represents a column in your DataSet. We could have said this instead:
dsNewRow.Item(1) = txtFirstName.Text
dsNewRow.Item(2) = txtSurname.Text
The Item property is now using the index number of the DataSet columns, rather than the names.
The result is the same, though: to store new values in these properties. We're storing the text from
the textboxes to our new Row. We now only need to call the Method that actually adds the Row to
the
DataSet:
ds.Tables("AddressBook").Rows.Add(dsNewRow)
To add the Row, you use the Add method of the Rows property of the DataSet. In between the
round brackets, you need the name of your DataRow Updating:
16
To reference a particular column (item) in a row of the DataSet, the code is this:
ds.Tables("AddressBook").Rows(2).Item(1)
That will return whatever is at Item 1 on Row 2.
As well as returning a value, you can also set a value. You do it like this:
ds.Tables("AddressBook").Rows(2).Item(1) = "Jane"
Now Item 1 Row 2 will contain the text "Jane". This won't, however, affect the database! The
changes will just get made to the DataSet. To illustrate
this, add the following code to your btnUpdate:
ds.Tables("AddressBook").Rows(inc).Item(1) =
txtFirstName.Text
ds.Tables("AddressBook").Rows(inc).Item(2) =
txtSurname.Text
MsgBox("Data updated")
Run your program, and click the Next Record button to move to the first record. "John" should be
displayed in your first textbox, and "Smith" in the second textbox. Click inside the textboxes and
change "John" to "Joan" and "Smith" to "Smithy". Now click your
Update Record button. Move to the next record by clicking your Next Record button, and
then move back to the first record. You should see that the first record is now "Joan Smithy".
Close down your program, then run it again. Click the Next Record button
to move to the first record. It will still be "John Smith".
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("AddressBook").Rows(inc).Item(1) =
txtFirstName.Text
17
ds.Tables("AddressBook").Rows(inc).Item(2) =
txtSurname.Text
da.Update(ds, "AddressBook")
MsgBox("Data updated")
The first new line is this:
Dim cb As New OleDb.OleDbCommandBuilder(da)
To update the database itself, you need something called a Command Builder. The Command
Builder will build a SQL string for you. In between round brackets, you type the name of your
Data Adapter, da in our case. The command builder is then stored in a variable, which we have
called cb.
The second new line is where the action is:
da.Update(ds, "AddressBook")
The da variable is holding our Data Adapter. One of the methods of the Data Adapter is Update. In
between the round brackets, you need the name of your DataSet (ds, for us). The "AddressBook"
part is optional.
Delete a Record from a Database:
The code to delete a record is a little easier than last time. Double click your
btnDelete and add the following:
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("AddressBook").Rows(inc).Delete()
MaxRows = MaxRows - 1
inc = 0
NavigateRecords()
18
da.Update(ds, "AddressBook")
6.Explain the usage of variants in VB.NET.
Arrays can be stored in variant variables. It also discusses about passage of
multidimensional arrays to routines expecting variant parameters. You can
create an array of Variant elements on the fly using the Array function and store it in a Variant
variable.
Visual Basic lets you store arrays in Variant variables and then access the array items using the
Variant variable as if it were an array:
ReDim Names(100) As String, var As Variant
' Initialize the Names array (omitted).
var = Names() ' Copy the array into the Variant.
Print var(1) ' Access array items through the Variant.
you can pass an array to a procedure that expects a Variant parameter and then access the
elements of the array through that parameter:
' A polymorphic function that sums the values in any array Function ArraySum(arr As Variant)
As Variant
Dim i As Long, result As Variant
For i = LBound(arr) To UBound(arr)
result = result + arr(i)
Next
ArraySum = result
End Function
7.Describe the process of extracting and drawing images using ImageList Control.
19
Each ListImage object exposes a Picture property, which lets you extract the image and assign it to
another control, typically a PictureBox or Image
control:
Set Picture1.Picture = ImageList1.ListImages("Cut").Picture
In general, you can use the Picture property of a ListImage object whenever you would use
the Picture property of a PictureBox or an Image control, as
in the following example:
' Save an image to a disk file.
SavePicture ImageList1.ListImages("Cut").Picture, "C:cut.bmp"
' Display an image on the current form, zooming it by a factor ' of 4 along the X-axis, and 8
along the Y-axis. With ImageList1
PaintPicture .ListImages("Cut").Picture, 0, 0, _
ScaleX(.ImageWidth, vbPixels) * 4, ScaleY(.ImageHeight, vbPixels) * 8
End With
Using the PaintPicture method, you can display any ListImage object on a form or in a PictureBox
control, or you can print it to the Printer object. ListImage objects also expose an ExtractIcon
method, which creates an icon out of the image and returns it to the caller. You can therefore use
this method whenever an icon is expected, as in this code:
Form1.MouseIcon = ImageList1.ListImages("Pointer").ExtractIcon
Unlike standard collections, keys in the ListImages collection are dealt with
in a case-sensitive way. In other words, "Pointer" and "pointer" are assumed to be different items.
8.Describe the runtime properties of ListView Control.
Adding ListItem Objects Add([Index], [Key], [Text], [Icon], [SmallIcon]) As
ListItem
20
Index is the position at which you place the new item. (If you omit Index, the item is added to the
end of the collection.) Key is the inserted item's optional
key in the ListItems collection, Text is the string displayed in the control, Icon is an index or a key
in the ImageList control pointed to by the Icons property, and SmallIcon is an index or a key in the
ImageList control pointed to by the SmallIcons property. All these arguments are optional. The Add
method returns a reference to the ListIte m object being created,
which you can use to set those properties whose values can't be passed to the Add method itself, as
in the following example:
' Create a new item with a "ghosted" appearance.
Dim li As ListItem
Set li = ListView1.ListItems.Add(, , "First item", 1)
li.Ghosted = True
ListItem objects support a number of new properties. The Bold and ForeColor properties affect the
boldface and color attributes of the objects. The ToolTipText property allows you to define a
different ToolTip for each
item, and the Checked property sets or returns the state of the check box beside the item (if the
ListView's Checkboxes property is True). When you have to assign multiple properties, you can
use a With clause with the Add method:
With ListView1.ListItems.Add(, , "John Ross", 1)
.Bold = True
.ForeColor = vbRed
.ToolTipText = "Manager of the Sales Dept."
End With
When working with ListView controls whose MultiSelect property is True, the user can select
21
multiple items by clicking on them while pressing the Ctrl or the Shift key. You can modify the
selection state of a ListItem object via code by assigning the appropriate value to t he Selected
property. With such ListView controls, you must also assign the SelectedItem property to make a
ListItem the current item:
' Make the first ListItem object the current one.
Set ListView1.SelectedItem = ListView1.ListItems(1)
' Select it.
ListView1.ListItems(1).Selected = True
Adding ColumnHeaders Objects
Often you don't know at design time what columns should be displayed in a ListView control. For
example, you might be showing the result of a user-defined query, in which case you don't know the
number and the names of
the fields involved. In such circumstances, you must create ColumnHeader objects at run time with
the Add method of the ColumnHeaders collection, which has this syntax:
Add([Index], [Key], [Text], [Width], [Alignment], [Icon]) _
As ColumnHeader
Index is the position in the collection, Key is an optional key, Text is the string displayed in the
header, and Width is the column's width in twips.
Alignment is one of the following constants: 0-lvwColumnLeft, 1-lvwColumnRight, or 2-
lvwColumnCenter. Icon is an index or a key in the ListImage control referenced by the
ColumnHeaderIcons property. With the
exception of the Tag property, these are the only properties that can be assigned when a
ColumnHeader object is created, so you can usually discard the return value of the Add method:
22
' Clear any existing column header.
ListView1.ColumnHeaders.Clear
' The alignment for the first column header must be lvwColumnLeft.
istView1.ColumnHeaders.Add , , "Last Name", 2000, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "First Name", 2000, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Salary", 1500, lvwColumnRight
Adding ListSubItems
Each ListItem object supports a ListSubItems collection, which lets you
create values displayed in the same row as the main ListItem object when the control is in Report
mode. This collection replaces the SubItems array that was present in previous versions of the
control. (The array is still
supported for backward compatibility.) You can create new ListSubItem objects us ing the Add
method of the ListSubItems collection:
Add([Index], [Key], [Text], [ReportIcon], [ToolTipText]) _
As ListSubItem
Index is the position in the collection of the new item, Key is its optional key,
Text is the string that will be displayed in the grid cell, ReportIcon is the index or the key of an
icon in the ImageList control referenced by the SmallIcons property, and ToolTipText is the text of
a ToolTip that appears when the user keeps the mouse hovering over this item. You can also assign
individual Bold and ForeColor attributes to each ListSubItem:
' This ListItem goes under ColumnHeader(1).
With ListView1.ListItems.Add(, , "Ross", 1)
.Bold = True
23
' This ListSubItem goes under ColumnHeader(2).
With .ListSubItems.Add(, , "John")
.Bold = True
End With
' This ListSubItem goes under ColumnHeader(3).
With .ListSubItems.Add(, , "80,000")
.Bold = True
.ForeColor = vbRed
End With
End With
Loading Data from Databases
the ListView control can't be automatically bound to a database through Data, RemoteData, or an
ADO Data control. In other words, if you want to load database data into this control you're on
your ow n. The task of filling a ListView control with data read from a recordset isn't conceptually
difficult, but you have to account for a few details. First you must retrieve the list of fields
contained in the recordset and create a corresponding number of ColumnHeader objects of a
suitable width. You also have to discard fields
that can't be displayed in ListView controls (for example, BLOB fields), and you must determine
the best alignment for each field (to the right for numbers and dates, to the left for all others).
Sorting and Reordering Columns
you can get the same effect at run time by setting the Sorted, SortKey, and SortOrdaer
properties. Usually you do this when the end user clicks on a column header, an action that you can
trap in the ColumnClick event:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As _
24
MSComctlLib.ColumnHeader)
ListView1.SortKey = ColumnHeader.Index - 1
ListView1.Sorted = True
End Sub

More Related Content

What's hot

Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
senthil0809
 
BP208 Fabulous Feats with @Formula
BP208 Fabulous Feats with @FormulaBP208 Fabulous Feats with @Formula
BP208 Fabulous Feats with @Formula
Kathy Brown
 
Basic Analysis using R
Basic Analysis using RBasic Analysis using R
Basic Analysis using R
Sankhya_Analytics
 
LectureNotes-06-DSA
LectureNotes-06-DSALectureNotes-06-DSA
LectureNotes-06-DSA
Haitham El-Ghareeb
 
LectureNotes-03-DSA
LectureNotes-03-DSALectureNotes-03-DSA
LectureNotes-03-DSA
Haitham El-Ghareeb
 
LectureNotes-05-DSA
LectureNotes-05-DSALectureNotes-05-DSA
LectureNotes-05-DSA
Haitham El-Ghareeb
 
Ado.net by Awais Majeed
Ado.net by Awais MajeedAdo.net by Awais Majeed
Ado.net by Awais Majeed
Awais Majeed
 
E2D3 ver. 0.2 API Instruction
E2D3 ver. 0.2 API InstructionE2D3 ver. 0.2 API Instruction
E2D3 ver. 0.2 API Instruction
E2D3.org
 
Sql server lab_2
Sql server lab_2Sql server lab_2
Sql server lab_2
vijay venkatash
 
Introduction To R Language
Introduction To R LanguageIntroduction To R Language
Introduction To R Language
Gaurang Dobariya
 
70 562
70 56270 562
BAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureBAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 Lecture
Wake Tech BAS
 
Arrays
ArraysArrays
Arrays
Faisal Aziz
 
Create and analyse programs
Create and analyse programsCreate and analyse programs
Create and analyse programs
Dr. C.V. Suresh Babu
 
Java chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useJava chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
First approach in linq
First approach in linqFirst approach in linq
First approach in linq
Vignesh Nethaji
 
DatumTron In-Memory Graph Database
DatumTron In-Memory Graph DatabaseDatumTron In-Memory Graph Database
DatumTron In-Memory Graph Database
Ashraf Azmi
 
Oracle interview questions
Oracle interview questionsOracle interview questions
Oracle interview questions
barbie0909
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
krishna singh
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
koolkampus
 

What's hot (20)

Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
BP208 Fabulous Feats with @Formula
BP208 Fabulous Feats with @FormulaBP208 Fabulous Feats with @Formula
BP208 Fabulous Feats with @Formula
 
Basic Analysis using R
Basic Analysis using RBasic Analysis using R
Basic Analysis using R
 
LectureNotes-06-DSA
LectureNotes-06-DSALectureNotes-06-DSA
LectureNotes-06-DSA
 
LectureNotes-03-DSA
LectureNotes-03-DSALectureNotes-03-DSA
LectureNotes-03-DSA
 
LectureNotes-05-DSA
LectureNotes-05-DSALectureNotes-05-DSA
LectureNotes-05-DSA
 
Ado.net by Awais Majeed
Ado.net by Awais MajeedAdo.net by Awais Majeed
Ado.net by Awais Majeed
 
E2D3 ver. 0.2 API Instruction
E2D3 ver. 0.2 API InstructionE2D3 ver. 0.2 API Instruction
E2D3 ver. 0.2 API Instruction
 
Sql server lab_2
Sql server lab_2Sql server lab_2
Sql server lab_2
 
Introduction To R Language
Introduction To R LanguageIntroduction To R Language
Introduction To R Language
 
70 562
70 56270 562
70 562
 
BAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureBAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 Lecture
 
Arrays
ArraysArrays
Arrays
 
Create and analyse programs
Create and analyse programsCreate and analyse programs
Create and analyse programs
 
Java chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and useJava chapter 6 - Arrays -syntax and use
Java chapter 6 - Arrays -syntax and use
 
First approach in linq
First approach in linqFirst approach in linq
First approach in linq
 
DatumTron In-Memory Graph Database
DatumTron In-Memory Graph DatabaseDatumTron In-Memory Graph Database
DatumTron In-Memory Graph Database
 
Oracle interview questions
Oracle interview questionsOracle interview questions
Oracle interview questions
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
 

Similar to Bt0082 visual basic2

Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docxScanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
anhlodge
 
Sharbani bhattacharya VB Structures
Sharbani bhattacharya VB StructuresSharbani bhattacharya VB Structures
Sharbani bhattacharya VB Structures
Sharbani Bhattacharya
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
Sadhana Sreekanth
 
Ado.Net
Ado.NetAdo.Net
Ado.Net
LiquidHub
 
Core C# Programming Constructs, Part 1
Core C# Programming Constructs, Part 1Core C# Programming Constructs, Part 1
Core C# Programming Constructs, Part 1
Vahid Farahmandian
 
systems labOnce the Application has started up and you are at the .docx
systems labOnce the Application has started up and you are at the .docxsystems labOnce the Application has started up and you are at the .docx
systems labOnce the Application has started up and you are at the .docx
perryk1
 
Once the Application has started up and you are at the Start Page, s.docx
Once the Application has started up and you are at the Start Page, s.docxOnce the Application has started up and you are at the Start Page, s.docx
Once the Application has started up and you are at the Start Page, s.docx
arnit1
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
Ali Shah
 
VB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.pptVB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.ppt
BhuvanaR13
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basic
Techglyphs
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
mwillmer
 
Oracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityOracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivity
rohit vishwakarma
 
I am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdfI am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdf
mallik3000
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
Ado.net
Ado.netAdo.net
Ado.net
pacatarpit
 
C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
C++ Homework Help
 
Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.Net
FaRid Adwa
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
dunhamadell
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding Manual
Vizwik
 

Similar to Bt0082 visual basic2 (20)

Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docxScanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
Scanned by CamScannerModule 03 Lab WorksheetWeb Developmen.docx
 
Sharbani bhattacharya VB Structures
Sharbani bhattacharya VB StructuresSharbani bhattacharya VB Structures
Sharbani bhattacharya VB Structures
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
 
Ado.Net
Ado.NetAdo.Net
Ado.Net
 
Core C# Programming Constructs, Part 1
Core C# Programming Constructs, Part 1Core C# Programming Constructs, Part 1
Core C# Programming Constructs, Part 1
 
systems labOnce the Application has started up and you are at the .docx
systems labOnce the Application has started up and you are at the .docxsystems labOnce the Application has started up and you are at the .docx
systems labOnce the Application has started up and you are at the .docx
 
Once the Application has started up and you are at the Start Page, s.docx
Once the Application has started up and you are at the Start Page, s.docxOnce the Application has started up and you are at the Start Page, s.docx
Once the Application has started up and you are at the Start Page, s.docx
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
 
VB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.pptVB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.ppt
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basic
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Oracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityOracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivity
 
I am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdfI am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdf
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Ado.net
Ado.netAdo.net
Ado.net
 
C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
 
Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.Net
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding Manual
 

More from Techglyphs

Bt9002 Grid computing 2
Bt9002 Grid computing 2Bt9002 Grid computing 2
Bt9002 Grid computing 2
Techglyphs
 
Bt9002 grid computing 1
Bt9002 grid computing 1Bt9002 grid computing 1
Bt9002 grid computing 1
Techglyphs
 
Bt8901 objective oriented systems2
Bt8901 objective oriented systems2Bt8901 objective oriented systems2
Bt8901 objective oriented systems2
Techglyphs
 
Bt0062 fundamentals of it(1)
Bt0062 fundamentals of it(1)Bt0062 fundamentals of it(1)
Bt0062 fundamentals of it(1)
Techglyphs
 
Bt0062 fundamentals of it(2)
Bt0062 fundamentals of it(2)Bt0062 fundamentals of it(2)
Bt0062 fundamentals of it(2)
Techglyphs
 
Bt0064 logic design1
Bt0064 logic design1Bt0064 logic design1
Bt0064 logic design1
Techglyphs
 
Bt0064 logic design2
Bt0064 logic design2Bt0064 logic design2
Bt0064 logic design2
Techglyphs
 
Bt0066 database management system1
Bt0066 database management system1Bt0066 database management system1
Bt0066 database management system1
Techglyphs
 
Bt0066 database management system2
Bt0066 database management system2Bt0066 database management system2
Bt0066 database management system2
Techglyphs
 
Bt0067 c programming and data structures2
Bt0067 c programming and data structures2Bt0067 c programming and data structures2
Bt0067 c programming and data structures2
Techglyphs
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1
Techglyphs
 
Bt0068 computer organization and architecture
Bt0068 computer organization and architecture Bt0068 computer organization and architecture
Bt0068 computer organization and architecture
Techglyphs
 
Bt0068 computer organization and architecture 2
Bt0068 computer organization and architecture 2Bt0068 computer organization and architecture 2
Bt0068 computer organization and architecture 2
Techglyphs
 
Bt0070 operating systems 1
Bt0070 operating systems  1Bt0070 operating systems  1
Bt0070 operating systems 1
Techglyphs
 
Bt0070 operating systems 2
Bt0070 operating systems  2Bt0070 operating systems  2
Bt0070 operating systems 2
Techglyphs
 
Bt0072 computer networks 1
Bt0072 computer networks  1Bt0072 computer networks  1
Bt0072 computer networks 1
Techglyphs
 
Bt0072 computer networks 2
Bt0072 computer networks  2Bt0072 computer networks  2
Bt0072 computer networks 2
Techglyphs
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2
Techglyphs
 
Bt0074 oops with java
Bt0074 oops with javaBt0074 oops with java
Bt0074 oops with java
Techglyphs
 
Bt0075 rdbms with mysql 1
Bt0075 rdbms with mysql 1Bt0075 rdbms with mysql 1
Bt0075 rdbms with mysql 1
Techglyphs
 

More from Techglyphs (20)

Bt9002 Grid computing 2
Bt9002 Grid computing 2Bt9002 Grid computing 2
Bt9002 Grid computing 2
 
Bt9002 grid computing 1
Bt9002 grid computing 1Bt9002 grid computing 1
Bt9002 grid computing 1
 
Bt8901 objective oriented systems2
Bt8901 objective oriented systems2Bt8901 objective oriented systems2
Bt8901 objective oriented systems2
 
Bt0062 fundamentals of it(1)
Bt0062 fundamentals of it(1)Bt0062 fundamentals of it(1)
Bt0062 fundamentals of it(1)
 
Bt0062 fundamentals of it(2)
Bt0062 fundamentals of it(2)Bt0062 fundamentals of it(2)
Bt0062 fundamentals of it(2)
 
Bt0064 logic design1
Bt0064 logic design1Bt0064 logic design1
Bt0064 logic design1
 
Bt0064 logic design2
Bt0064 logic design2Bt0064 logic design2
Bt0064 logic design2
 
Bt0066 database management system1
Bt0066 database management system1Bt0066 database management system1
Bt0066 database management system1
 
Bt0066 database management system2
Bt0066 database management system2Bt0066 database management system2
Bt0066 database management system2
 
Bt0067 c programming and data structures2
Bt0067 c programming and data structures2Bt0067 c programming and data structures2
Bt0067 c programming and data structures2
 
Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1Bt0067 c programming and data structures 1
Bt0067 c programming and data structures 1
 
Bt0068 computer organization and architecture
Bt0068 computer organization and architecture Bt0068 computer organization and architecture
Bt0068 computer organization and architecture
 
Bt0068 computer organization and architecture 2
Bt0068 computer organization and architecture 2Bt0068 computer organization and architecture 2
Bt0068 computer organization and architecture 2
 
Bt0070 operating systems 1
Bt0070 operating systems  1Bt0070 operating systems  1
Bt0070 operating systems 1
 
Bt0070 operating systems 2
Bt0070 operating systems  2Bt0070 operating systems  2
Bt0070 operating systems 2
 
Bt0072 computer networks 1
Bt0072 computer networks  1Bt0072 computer networks  1
Bt0072 computer networks 1
 
Bt0072 computer networks 2
Bt0072 computer networks  2Bt0072 computer networks  2
Bt0072 computer networks 2
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2
 
Bt0074 oops with java
Bt0074 oops with javaBt0074 oops with java
Bt0074 oops with java
 
Bt0075 rdbms with mysql 1
Bt0075 rdbms with mysql 1Bt0075 rdbms with mysql 1
Bt0075 rdbms with mysql 1
 

Recently uploaded

Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 

Recently uploaded (20)

Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 

Bt0082 visual basic2

  • 1. 1 Visual Basic .Net BT0082 Part-2 BY milan K Antony 1.Describe the Data Form Wizard in Visual Studio .NET. VB.Net allows you many ways to connect to a database or a data source.The technology
  • 2. 2 used to interact with a database or data source is called ADO.NET. The ADO parts stands for Active Data Objects which, admittedly, doesn’t explain much. But just like System was a Base Class (leader of a hierarchy, if you like), so is ADO. Forming the foundation of the ADO Base Class are five other major objects: Connection , Command , DataReader , DataSet , DataAdapter The Connection Object is what you need if you want to connect to a database. There are a number of different connection objects, and the one you use depends largely on the type of database you're connecting to. LE stands for Object Linking and Embedding, and it’s basically a lot of objects (COM objects) bundled together that allow you to connect to data sources in general, and not just databases. You can use it, for example, to connect to text files, SQL Server, email, and a whole lot more.
  • 3. 3 There are a number of different OLE DB objects (called data providers), but the one we'll use is called "Jet". Others are SQL Server and Oracle. Whichever version you have, though, the variable con will now hold the Connection Object. Notice that there is a full stop after the OleDB part. You'll then get a pop up box from where you can select OleDbConnection. This is the object that you use to connect to an Access database. So place a button on your form. Change the Name property to btnLoad. Double click your button to open up the code window. here are Properties and Methods associated with the Connection Object, of course. We want to start with the ConnectionString property. This can take many parameters. Fortunately, we only need a few of these. We need to pass two things to our new Connection Object: the technology we want to use to do the connecting to our database; and where the database is. (If your database was password and user name protected, you would add these two parameters as well. Ours isn't, so we only need the two.) The technology is called the Provider; and you use "Data Source" to specify where your database is. con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:AddressBook.mdb" Notice the two parts, separated by a semi-colon: 1st Part: PROVIDER=Microsoft.Jet.OLEDB.4.0 2nd Part: Data Source = C:AddressBook.mdb The first part specifies which provider technology we want to use to do the connecting (JET). The second part, typed after a semi-colon, points to where the database is. In the above code, the database is on the C drive, in
  • 4. 4 the root folder. The name of the Acc ess file we want to connect to is called AddressBook.mdb. connecting (JET). The second part, typed after a semi-colon, points to where the database is. In the above code, the database is on the C drive, in the root folder. The name of the Access file we want to connect to is called AddressBook.mdb. (Note that "Data Source" is two words, and not one.) But your coding window should now look like this: Private Sub btnLoad_Click(ByVal Sender as Object,_ ByVal e as System.EventArgs) _ Handles btnLoad.Click Dim con as new OleDb.OleDbConnection Con.ConnectionString = “Provider = Microsoft.Jet.OLEDB.4.0; DataSource = C:AddressBook.mdb” This assumes that you have copied the AddressBook database over to the root folder of your C Drive. If you've copied it to another folder, change the "Data Source" part to match. For example, if you copied it to a folder called "databases" you'd put this: Data Source = C:databasesAddressBook.mdb In our code , though, ConnectionString is a property of the con variable. The con variable holds our Connection Object. We're passing the Connection String the name of a data provider, and a path to the database. 1.Describe the concept of record navigation in VB.NET. o move backwards through the DataSet, we need to decrement the inc counter. This means is deducting 1 from whatever is currently in inc. But we also need to check that inc doesn't go past zero, which is the first record in the DataSet. Here's the code to add to your btnPrevious:
  • 5. 5 If inc > 0 Then inc = inc - 1 NavigateRecords() Else MsgBox("First Record") End If So the If statement first checks that inc is greater than zero. If it is, inc gets 1 deducted from. Then the NavigateRecords() subroutine gets called. If inc is zero or less, then we display a message. When you've finished adding the code, test your program out. Click the Previous button first. The message box should display, even though no records have been loaded into the textboxes. This is because the variable inc has a value of -1 when the form first loads. It only gets moved on to zero when the Next button is clicked. You could amend your IF Statement to this: If inc > 0 Then inc = inc - 1 NavigateRecords() ElseIf inc = -1 Then MsgBox("No Records Yet") ElseIf inc = 0 Then MsgBox("First Record") End If This new If Statement now checks to see if inc is equal to minus 1, and displays a message if it
  • 6. 6 does. It also checks if inc is equal to zero, and displays the "First Record" message box. (ii) Moving to the Last Record in the DataSet To jump to the last record in the DataSet, you only need to know how many records have been loaded into the DataSet - the MaxRows variable in our code. You can then set the inc counter to that value, but minus 1. Here's the code to add to your btnLast: if inc <> MaxRows - 1 Then inc = MaxRows - 1 NavigateRecords() End If The reason we're saying MaxRows - 1 is that the row count might be 5, say, but the first record in the DataSet starts at zero. So the total number of records would be zero to 4. Inside of the If Statement, we're setting the inc counter to MaxRows - 1, then calling thE NavigateRecords() subroutine. That's all we need to do. So run your program. Click the Last button, and you should see the last record displayed in your textboxes. Moving to the First Record in the DataSet Moving to the first record is fairly straightforward. We only need to set the inc counter to zero, if it's not already at that value. Then call the Sub: If inc <> 0 Then inc = 0 NavigateRecords() End If Add the code to your btnFirst. Run your program and test out all of your buttons. You should be able to move through the names in the database, and jump to the first and last records.
  • 7. 7 2.Explain the theory behind declaring arrays in VB.NET. Arrays occupy space in memory. The programmer specifies the array type and the number of elements required by the array so that the compiler may reserve the appropriate amount of memory. Arrays may be declared as Public (in a code module), module or local. Module arrays are declared in the general declarations using keyword Dim or Private. Local arrays are declared in a procedure using Dim or Static. Ar ray must be declared explicitly with keyword "As". There are two types of arrays in Visual Basic namely: Fixed-Size Array: The size of array always remains the same-size doesn't change during the program execution. Dynamic Array: The size of the array can be changed at the run time- size changes during the program execution. When an upper bound is specified in the declaration, a Fixed-array is created. The upper limit should always be within the range of long data type. Declaring a fixed-array Dim numbers(5) As Integer In the above illustration, numbers is the name of the array, and the number 6 included in the parentheses is the upper limit of the array. The above declaration creates an array with 6 elements, with index numbers running from 0 to 5. If we want to specify the lower limit then the parentheses should include both the lower and upper limit along with the To keyword. Arrays can have multiple dimensions. A common use of multidimensional arrays is to represent tables of values consisting of information arranged in rows and columns. To identify a particular table element, we must specify
  • 8. 8 two indexes: The first (by convention) identifies the element's row and the second (by convention) identifies the element's column. Tables or arrays that require two indexes to identify a particular element are called two dimensional arrays. Note that multidimensional arrays can have more than two dimensions. Visual Basic supports at least 60 array dimensions, but most people will need to use more than two or three dimensional-arrays. The following statement declares a two-dimensional array 50 by 50 array within a procedure. Dim AvgMarks (50, 50) It is also possible to define the lower limits for one or both the dimensions as for fixed size arrays. An example for this is given here. Dim Marks (101 To 200, 1 To 100) Basically, you can create either static or dynamic arrays. Static arrays must include a fixed number of iems, and this number must be known at compile time so that the compiler can set aside the necessary amount of memory.You create a static array using a Dim statement with a constant argument: ' This is a static array. Dim Names(100) As String Visual Basic starts indexing the array with 0. Therefore, the preceding array actually holds 101 items. Most programs don't use static arrays because programmers rarely know at compile time how many items you need and also because static arrays can't be resized during execution. Both these issues are solved by dynamic arrays. You declare and create dynamic arrays in two distinct steps. In general, you declare the array to account for its visibility (for example, at the beginning of a module if you want to make it visible by all the procedures of the module) using a
  • 9. 9 Dim command with an empty pair of brackets. Then you create the array when you actually need it, using a ReDim statement: ' An array defined in a BAS module (with Private scope) Dim Customers() As String ... Sub Main() ' Here you create the array. ReDim Customer(1000) As String End Sub if you don't specify the lower index of an array, Visual Basic assumes it to be 0, unless an Option Base 1 statement is placed at the beginning of the module. My suggestion is this: Never use an Option Base statement because it makes code reuse more difficult. (You can't cut and paste routines wit hout worrying about the current Option Base.) If you want to explicitly use a lower index different from 0, use this syntax instead: ReDim Customers(1 To 1000) As String Dynamic arrays can be re-created at will, each time with a different number of items. When you re- create a dynamic array, its contents are reset to 0 (or to an empty string) and you lose the data it contains. If you want to resize an array without losing its contents, use the ReDim Preserve command: ReDim Preserve Customers(2000) As String When you're resizing an array, you can't change the number of its dimensions nor the type of the values it contains. Moreover, when you're
  • 10. 10 using ReDim Preserve on a multidimensional array, you can resize only its last dimension: ReDim Cells(1 To 100, 10) As Integer ... ReDim Preserve Cells(1 To 100, 20) As Integer ' This works. ReDim Preserve Cells(1 To 200, 20) As Integer ' This doesn't. Finally, you can destroy an array using the Erase statement. If the array is dynamic, Visual Basic releases the memory allocated for its elements (and you can't read or write them any longer); if the array is static, its elements are set to 0 or to empty strings. UDT structures can include both static and dynamic arrays. Here's a sample structure that contains both types: Type MyUDT StaticArr(100) As Long DynamicArr() As Long End Type ... Dim udt As MyUDT ' You must DIMension the dynamic array before using it. ReDim udt.DynamicArr(100) As Long ' You don't have to do that with static arrays. udt.StaticArr(1) = 1234 The memory needed by a static array is allocated within the UDT structure; for example, the StaticArr array in the preceding code snippet takes exactly 400 bytes. Conversely, a dynamic array in a UDT takes only 4 bytes, which form a pointer to the memory area where the actual data is stored. Dynamic arrays are advantageous when each individual UDT variable might host a
  • 11. 11 different number of array items. As with all dynamic arrays, if you don't dimension a dynamic array within a UDT before accessing its items, you get an error 9—"Subscript out of range." 3.Describe the mechanism of creating transparent images using ImageList Control. he ImageList control has a MaskColor property whose value determines the color that should be considered transparent when you're performing graphical operations on individual ListImage objects or when you're displaying images inside other controls. By default, this is the gray color (&HC0C0C0), but you can change it both at design time in the Color tab of the Properties dialog box and at run time via code. When a graphical operation is performed, none of the pixels in the image that are the color defined by MaskColor are transferred. To actually display transparent images, however, you must ensure that the UseMaskColor property is set to True, which is its default value. You can modify this value in the General tab of the Properties dialog box or at run time via code: ' Make white the transparent color. ImageList1.MaskColor = vbWhite 4.Explain the design time property settings of a ListView Control. While you can use the regular Properties window to set most properties of a ListView control, it's surely preferable to use a ListView control's custom Properties dialog box
  • 12. 12 The ListView control supports four basic view modes: Icon, SmallIcon, List, and Report. To see how each mode is rendered, try the corresponding items in the Windows Explorer View menu The ListView control exposes two distinct collections: The ListItems collection comprises individual ListItem objects, each one corresponding to an item in the control, whereas the ColumnHeaders collection includes ColumnHeader objects that affect the appearance of the individual headers visible in Report mode. A third collection, ListSubItems, contains data for all the cells displayed in Report mode. 5.Describe the concept of setting a connection string with an example. There are Properties and Methods associated with the Connection Object, of course. We want to start with the ConnectionString property. This can take many parameters. Fortunately, we only need a few of these. We need to pass two things to our new Connection Object: the technology we want to use to do the connecting to our database; and where the database is. (If your database was password and user name protected, you
  • 13. 13 would add these two parameters as well. Ours isn't, so we only need thetwo.) The technology is called the Provider; and you use "Data Source" to specify where your database is. This should be entered on the same line, and not two as it is below. So add this to your code: con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:AddressBook.mdb" Notice the two parts, separated by a semi-colon: 1st Part: PROVIDER=Microsoft.Jet.OLEDB.4.0 2nd Part: Data Source = C:AddressBook.mdb The first part specifies which provider technology we want to use to do the connecting (JET). The second part, typed after a semi-colon, points to where the database is. In the above code, the database is on the C drive, in the root folder. The name of the Access file we want to connect to is called AddressBook.mdb. Private Sub btnLoad_Click(ByVal Sender as Object,_ ByVal e as System.EventArgs) _ Handles btnLoad.Click Dim con as new OleDb.OleDbConnection Con.ConnectionString = “Provider = Microsoft.Jet.OLEDB.4.0; DataSource = C:AddressBook.mdb” This assumes that you have copied the AddressBook database over to the root folder of your C Drive. If you've copied it to another folder, change the "Data Source" part to match. For example, if you copied it to a folder called "databases" you'd put this: Data Source = C:databasesAddressBook.mdb In our code , though, ConnectionString is a property of the con variable.The con variable holds our Connection Object. We're passing the Connection String the name of a data provider, and a path to
  • 14. 14 the database. Describe the process of adding, updating, and deleting records with an example. The button that gets switched on is the Commit Changes button. The Enabled property of btnCommit gets set to True. But, for this to work, you need to set it to False when the form loads. So return to your Form. Click btnCommit to select it. Then locate the Enabled Property in the Properties box. Set it to False. When the Form starts up, the button will be switched off. The Clear/Cancel button can be used to switch it back on again. So add this code to your btnClear: btnCommit.Enabled = False btnAddNew.Enabled = True btnUpdate.Enabled = True btnDelete.Enabled = True inc = 0 NavigateRecords() We're switching the Commit Changes button off, and the other three back on. The other two lines just make sure that we display the first record again, after the Cancel button is clicked. Otherwise the textboxes will all be blank. To add a new record to the database, we'll use the Commit Changes button. So double click your btnCommit to access its code. Add the following: If inc <> -1 Then Dim cb As New OleDb.OleDbCommandBuilder(da) Dim dsNewRow As DataRow dsNewRow = ds.Tables("AddressBook").NewRow() dsNewRow.Item("FirstName") = txtFirstName.Text dsNewRow.Item("Surname") = txtSurname.Text
  • 15. 15 ds.Tables("AddressBook").Rows.Add(dsNewRow) da.Update(ds, "AddressBook") MsgBox("New Record added to the Database") btnCommit.Enabled = False btnAddNew.Enabled = True btnUpdate.Enabled = True btnDelete.Enabled = True End If The actual values we want to store in the rows are coming from the textboxes. So we have these two lines: dsNewRow.Item("FirstName") = txtFirstName.Text dsNewRow.Item("Surname") = txtSurname.Text The dsNewRow object we created has a Property called Item. This is like the Item property you used earlier. It represents a column in your DataSet. We could have said this instead: dsNewRow.Item(1) = txtFirstName.Text dsNewRow.Item(2) = txtSurname.Text The Item property is now using the index number of the DataSet columns, rather than the names. The result is the same, though: to store new values in these properties. We're storing the text from the textboxes to our new Row. We now only need to call the Method that actually adds the Row to the DataSet: ds.Tables("AddressBook").Rows.Add(dsNewRow) To add the Row, you use the Add method of the Rows property of the DataSet. In between the round brackets, you need the name of your DataRow Updating:
  • 16. 16 To reference a particular column (item) in a row of the DataSet, the code is this: ds.Tables("AddressBook").Rows(2).Item(1) That will return whatever is at Item 1 on Row 2. As well as returning a value, you can also set a value. You do it like this: ds.Tables("AddressBook").Rows(2).Item(1) = "Jane" Now Item 1 Row 2 will contain the text "Jane". This won't, however, affect the database! The changes will just get made to the DataSet. To illustrate this, add the following code to your btnUpdate: ds.Tables("AddressBook").Rows(inc).Item(1) = txtFirstName.Text ds.Tables("AddressBook").Rows(inc).Item(2) = txtSurname.Text MsgBox("Data updated") Run your program, and click the Next Record button to move to the first record. "John" should be displayed in your first textbox, and "Smith" in the second textbox. Click inside the textboxes and change "John" to "Joan" and "Smith" to "Smithy". Now click your Update Record button. Move to the next record by clicking your Next Record button, and then move back to the first record. You should see that the first record is now "Joan Smithy". Close down your program, then run it again. Click the Next Record button to move to the first record. It will still be "John Smith". Dim cb As New OleDb.OleDbCommandBuilder(da) ds.Tables("AddressBook").Rows(inc).Item(1) = txtFirstName.Text
  • 17. 17 ds.Tables("AddressBook").Rows(inc).Item(2) = txtSurname.Text da.Update(ds, "AddressBook") MsgBox("Data updated") The first new line is this: Dim cb As New OleDb.OleDbCommandBuilder(da) To update the database itself, you need something called a Command Builder. The Command Builder will build a SQL string for you. In between round brackets, you type the name of your Data Adapter, da in our case. The command builder is then stored in a variable, which we have called cb. The second new line is where the action is: da.Update(ds, "AddressBook") The da variable is holding our Data Adapter. One of the methods of the Data Adapter is Update. In between the round brackets, you need the name of your DataSet (ds, for us). The "AddressBook" part is optional. Delete a Record from a Database: The code to delete a record is a little easier than last time. Double click your btnDelete and add the following: Dim cb As New OleDb.OleDbCommandBuilder(da) ds.Tables("AddressBook").Rows(inc).Delete() MaxRows = MaxRows - 1 inc = 0 NavigateRecords()
  • 18. 18 da.Update(ds, "AddressBook") 6.Explain the usage of variants in VB.NET. Arrays can be stored in variant variables. It also discusses about passage of multidimensional arrays to routines expecting variant parameters. You can create an array of Variant elements on the fly using the Array function and store it in a Variant variable. Visual Basic lets you store arrays in Variant variables and then access the array items using the Variant variable as if it were an array: ReDim Names(100) As String, var As Variant ' Initialize the Names array (omitted). var = Names() ' Copy the array into the Variant. Print var(1) ' Access array items through the Variant. you can pass an array to a procedure that expects a Variant parameter and then access the elements of the array through that parameter: ' A polymorphic function that sums the values in any array Function ArraySum(arr As Variant) As Variant Dim i As Long, result As Variant For i = LBound(arr) To UBound(arr) result = result + arr(i) Next ArraySum = result End Function 7.Describe the process of extracting and drawing images using ImageList Control.
  • 19. 19 Each ListImage object exposes a Picture property, which lets you extract the image and assign it to another control, typically a PictureBox or Image control: Set Picture1.Picture = ImageList1.ListImages("Cut").Picture In general, you can use the Picture property of a ListImage object whenever you would use the Picture property of a PictureBox or an Image control, as in the following example: ' Save an image to a disk file. SavePicture ImageList1.ListImages("Cut").Picture, "C:cut.bmp" ' Display an image on the current form, zooming it by a factor ' of 4 along the X-axis, and 8 along the Y-axis. With ImageList1 PaintPicture .ListImages("Cut").Picture, 0, 0, _ ScaleX(.ImageWidth, vbPixels) * 4, ScaleY(.ImageHeight, vbPixels) * 8 End With Using the PaintPicture method, you can display any ListImage object on a form or in a PictureBox control, or you can print it to the Printer object. ListImage objects also expose an ExtractIcon method, which creates an icon out of the image and returns it to the caller. You can therefore use this method whenever an icon is expected, as in this code: Form1.MouseIcon = ImageList1.ListImages("Pointer").ExtractIcon Unlike standard collections, keys in the ListImages collection are dealt with in a case-sensitive way. In other words, "Pointer" and "pointer" are assumed to be different items. 8.Describe the runtime properties of ListView Control. Adding ListItem Objects Add([Index], [Key], [Text], [Icon], [SmallIcon]) As ListItem
  • 20. 20 Index is the position at which you place the new item. (If you omit Index, the item is added to the end of the collection.) Key is the inserted item's optional key in the ListItems collection, Text is the string displayed in the control, Icon is an index or a key in the ImageList control pointed to by the Icons property, and SmallIcon is an index or a key in the ImageList control pointed to by the SmallIcons property. All these arguments are optional. The Add method returns a reference to the ListIte m object being created, which you can use to set those properties whose values can't be passed to the Add method itself, as in the following example: ' Create a new item with a "ghosted" appearance. Dim li As ListItem Set li = ListView1.ListItems.Add(, , "First item", 1) li.Ghosted = True ListItem objects support a number of new properties. The Bold and ForeColor properties affect the boldface and color attributes of the objects. The ToolTipText property allows you to define a different ToolTip for each item, and the Checked property sets or returns the state of the check box beside the item (if the ListView's Checkboxes property is True). When you have to assign multiple properties, you can use a With clause with the Add method: With ListView1.ListItems.Add(, , "John Ross", 1) .Bold = True .ForeColor = vbRed .ToolTipText = "Manager of the Sales Dept." End With When working with ListView controls whose MultiSelect property is True, the user can select
  • 21. 21 multiple items by clicking on them while pressing the Ctrl or the Shift key. You can modify the selection state of a ListItem object via code by assigning the appropriate value to t he Selected property. With such ListView controls, you must also assign the SelectedItem property to make a ListItem the current item: ' Make the first ListItem object the current one. Set ListView1.SelectedItem = ListView1.ListItems(1) ' Select it. ListView1.ListItems(1).Selected = True Adding ColumnHeaders Objects Often you don't know at design time what columns should be displayed in a ListView control. For example, you might be showing the result of a user-defined query, in which case you don't know the number and the names of the fields involved. In such circumstances, you must create ColumnHeader objects at run time with the Add method of the ColumnHeaders collection, which has this syntax: Add([Index], [Key], [Text], [Width], [Alignment], [Icon]) _ As ColumnHeader Index is the position in the collection, Key is an optional key, Text is the string displayed in the header, and Width is the column's width in twips. Alignment is one of the following constants: 0-lvwColumnLeft, 1-lvwColumnRight, or 2- lvwColumnCenter. Icon is an index or a key in the ListImage control referenced by the ColumnHeaderIcons property. With the exception of the Tag property, these are the only properties that can be assigned when a ColumnHeader object is created, so you can usually discard the return value of the Add method:
  • 22. 22 ' Clear any existing column header. ListView1.ColumnHeaders.Clear ' The alignment for the first column header must be lvwColumnLeft. istView1.ColumnHeaders.Add , , "Last Name", 2000, lvwColumnLeft ListView1.ColumnHeaders.Add , , "First Name", 2000, lvwColumnLeft ListView1.ColumnHeaders.Add , , "Salary", 1500, lvwColumnRight Adding ListSubItems Each ListItem object supports a ListSubItems collection, which lets you create values displayed in the same row as the main ListItem object when the control is in Report mode. This collection replaces the SubItems array that was present in previous versions of the control. (The array is still supported for backward compatibility.) You can create new ListSubItem objects us ing the Add method of the ListSubItems collection: Add([Index], [Key], [Text], [ReportIcon], [ToolTipText]) _ As ListSubItem Index is the position in the collection of the new item, Key is its optional key, Text is the string that will be displayed in the grid cell, ReportIcon is the index or the key of an icon in the ImageList control referenced by the SmallIcons property, and ToolTipText is the text of a ToolTip that appears when the user keeps the mouse hovering over this item. You can also assign individual Bold and ForeColor attributes to each ListSubItem: ' This ListItem goes under ColumnHeader(1). With ListView1.ListItems.Add(, , "Ross", 1) .Bold = True
  • 23. 23 ' This ListSubItem goes under ColumnHeader(2). With .ListSubItems.Add(, , "John") .Bold = True End With ' This ListSubItem goes under ColumnHeader(3). With .ListSubItems.Add(, , "80,000") .Bold = True .ForeColor = vbRed End With End With Loading Data from Databases the ListView control can't be automatically bound to a database through Data, RemoteData, or an ADO Data control. In other words, if you want to load database data into this control you're on your ow n. The task of filling a ListView control with data read from a recordset isn't conceptually difficult, but you have to account for a few details. First you must retrieve the list of fields contained in the recordset and create a corresponding number of ColumnHeader objects of a suitable width. You also have to discard fields that can't be displayed in ListView controls (for example, BLOB fields), and you must determine the best alignment for each field (to the right for numbers and dates, to the left for all others). Sorting and Reordering Columns you can get the same effect at run time by setting the Sorted, SortKey, and SortOrdaer properties. Usually you do this when the end user clicks on a column header, an action that you can trap in the ColumnClick event: Private Sub ListView1_ColumnClick(ByVal ColumnHeader As _