9. controls properties

Upload: mohd-nafish

Post on 02-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 9. Controls Properties

    1/10

  • 8/10/2019 9. Controls Properties

    2/10

    LIST BOX

    lstListBox .Focus : ------same as Text Block--------

    .IsEnabled : ------same as Text Block--------

    .Items .Add : Adds an Item to the List Box collection.Clear : Clears the collection and releases the refrences on all items

    currently in the list box collection

    .Count : Gets the number of records in the list box collection

    .IndexOf : Returns the index of this collection where the specified item is

    Located

    .Item : Gets or Sets the item at the given zero-based index

    .Remove : Removes the specified item reference from collection or view

    .RemoveAt : Removes the item at the specified Index from collection or view

    .SelectedIndex : Gets or Sets the Index of the first item in the current selection orreturns negative one (-1) if the selection is empty

    .SelectedItem : Gets or Sets the Index of the first item in the current selection or

    returns negative one (-1) if the selection is empty

    .SelectedItems : Gets the list of selected items

    .SelectedValue : Gets or Sets the value of the selected item

    .SelectionMode : Gets or Sets the selection behaviour for the List Box Items

    .Visibility : ------same as Text Block--------

    COMBO BOX

    cboComboBox .Focus : ------same as Text Block--------

    .IsEditable : Gets or Sets the editing property of the element.

    .IsEnabled : ------same as Text Block--------

    .Items .Add : ------same as List Box--------

    .Clear : ------same as List Box--------

    .Count : ------same as List Box--------

    .IndexOf : ------same as List Box--------

    .Item : ------same as List Box--------

    .Remove : ------same as List Box--------

    .RemoveAt : ------same as List Box--------

    .SelectedIndex : ------same as List Box--------

    .SelectedItem : ------same as List Box--------

    .SelectedItems : ------same as List Box--------

    .SelectedValue : ------same as List Box--------

    .SelectionMode : ------same as List Box--------

    .Text : ------same as Text Block--------

  • 8/10/2019 9. Controls Properties

    3/10

    .Visibility : ------same as List Box--------

    BUTTON

    cmdButton .Content : Gets or Sets the content of the button

    .Focus : ------same as Text Block--------

    .IsEnabled : ------same as Text Block--------

    .Visibility : ------same as Text Block--------

    GRID

    grdGrid .Children .Add : ------same as List Box--------

    .Clear : ------same as List Box--------

    .Count : ------same as List Box--------

    .IndexOf : ------same as List Box--------

    .Item : ------same as List Box--------

    .Remove : ------same as List Box--------

    .RemoveAt : ------same as List Box--------

    .Focus : ------same as Text Block--------

    .IsEnabled : ------same as Text Block--------

    .Visibility : ------same as Text Block--------

    CHECK BOX

    chkCheckBox .Content : ------same as Button--------

    .Focus : ------same as Text Block--------

    .IsChecked : Gets or Sets whether the Element is checked

    .IsEnabled : ------same as Text Block--------

    .Visibility : ------same as Text Block--------

    RADIO BUTTON

    rdbRadioButton .Content : ------same as Button--------

    .Focus : ------same as Text Block--------

    .IsChecked : ------same as Check Box--------

    .IsEnabled : ------same as Text Block--------

    .Visibility : ------same as Text Block--------

  • 8/10/2019 9. Controls Properties

    4/10

  • 8/10/2019 9. Controls Properties

    5/10

    .ToString : ------same as Calendar--------

    .Visibility : ------same as Text Block--------

    STACK PANEL

    stkStackPanel .Children .Add : ------same as List Box--------.Clear : ------same as List Box--------

    .Count : ------same as List Box--------

    .IndexOf : ------same as List Box--------

    .Item : ------same as List Box--------

    .Remove : ------same as List Box--------

    .RemoveAt : ------same as List Box--------

    .Focus : ------same as Text Block--------

    .IsEnabled : ------same as Text Block--------

    . Visibility : ------same as Text Block--------

    WRAP PANEL

    wrpWrapPanel.Children .Add : ------same as Stack Panel--------

    .Clear : ------same as Stack Panel --------

    .Count : ------same as Stack Panel --------

    .IndexOf : ------same as Stack Panel --------

    .Item : ------same as Stack Panel --------

    .Remove : ------same as Stack Panel --------

    .RemoveAt : ------same as Stack Panel --------

    .Focus : ------same as Stack Panel --------

    .IsEnabled : ------same as Stack Panel --------

    . Visibility : ------same as Stack Panel --------

    USER CONTROL

    ctrUserControl

    COLLECTION

    colCollection .Add : Add elements to the present value list.

    .Remove : Remove the elements from the present value list.

    .Count : Counts the total number of elements in the collection.

    .Clear : Clears the collection and removes all elements from it.

  • 8/10/2019 9. Controls Properties

    6/10

    COLLECTIONS

    In general terms, a collectionis an object used for grouping and managing related objects. Visual Basic .Net

    Collections are data structures that holds data in different ways for flexible operations and is an ordered setof items that can be referred to as a unit. Visual Basic also provides a Collectionclass, with which you can

    define and create your own collections. The Collectionclass also provides you with the built-in functionality

    to loop through elements using For Each...Nextand to retrieve elements by index.

    A collection can be zero-basedor one-based, depending on what its starting index is. The former

    means that the index of the first item in the collection is 0, and the latter means that it is 1. An

    example of a zero-based collection is the .NET Framework Controlscollection, discussed earlier

    on this page. The Visual Basic Collectionobject is an example of a one-based collection.

    One-based collections can be more intuitive to Visual Basic users, because the index ranges from 1

    through the value of theCount Property (Collection Object),which returns the number of items in a

    collection.

    Instances of the Visual Basic Collectionclass allow you to access an item using either a numeric

    index or a Stringkey. You can add items to Visual Basic Collectionobjects either with or without

    specifying a key. If you add an item without a key, you must use its numeric index to access it.

    The Visual Basic Collectionobject is a general-purpose programming tool; it is more flexible than

    some other collections. It has anAdd Method (Collection Object) for putting items into the

    collection and aRemove Method (Collection Object) for taking items out.

    The Visual Basic Collectionobject provides a convenient way to refer to a related group of items as

    a single object. The items, or elements, in a collection need only be related by the fact that they exist

    in the collection. Elements of a collection do not have to share the same data type.

    You can create a collection the same way you create other objects, as the following example

    illustrates.

    Dim colCollection As New Microsoft.VisualBasic.Collection()

    Or simply; Dim colCollection as New Collection

    Once you have created a collection, you can do any of the following:

    Add an element with theAdd Method.

    Remove an element with theRemove Method.

    Remove all elements with theClear Method.

    Find out how many elements the collection contains with theCount Property.

    Check whether a specific element is present with theContains Method.

    Return a specific element from the collection with theItem Property.

    Iterate through the entire collection with theFor Each...Next Statement (Visual Basic).

    http://msdn.microsoft.com/en-us/library/61h34247%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/2ef45ab9%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/e9hxy57s%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/2ef45ab9%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/e9hxy57s%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/ms172934%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/61h34247%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/ms172935%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/a82kxee5%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/5ebk1751%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/5ebk1751%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/a82kxee5%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/ms172935%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/61h34247%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/ms172934%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/e9hxy57s%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/2ef45ab9%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/e9hxy57s%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/2ef45ab9%28v=vs.80%29.aspxhttp://msdn.microsoft.com/en-us/library/61h34247%28v=vs.80%29.aspx
  • 8/10/2019 9. Controls Properties

    7/10

    The properties and methods of the Collectionobject provide only the most basic services for

    collections. For example, the Addmethod cannot check the type of an element being added to a

    collection, which you might want to do to ensure that the collection contains only one kind of

    element. If you can ensure this in the Addmethod, you have a strongly-typedcollection, and you do

    not have to convert the return from the Itemproperty to its run-time data type. This improves your

    performance.

    You can provide more robust functionalityand additional properties, methods, and eventsby

    creating your own collection class.

    COLLECTIONVS ARRAY

    Collections are very similar to arrays. They are used to store a number of values (or variables), so

    that you can process them all.

    There are a number of differences between arrays and collections. First difference is that the

    indexing for arrays starts with zero, while for a collection it starts with 1. To understand this,

    consider the image below:

  • 8/10/2019 9. Controls Properties

    8/10

    Now the statement V = A(3) will place the value 55 in V because the indexing start at zero in

    arrays. However the similar statement V = C(3) will place 43 instead because collection indexing is

    different. The same applies for the second statement.

    Another important difference is the data type. All Array elements has the same data type. So if you

    have an array:

    DimA(0 To 9) As Integer

    then A(0), A(1), A(2) A(9) are all Integers. Collections on the other hand do not require this. You

    can store integers, reals, strings, bytes, etc. in the same collection. This can be illustrated below:

    Usually you will use the same data type for all elements of the collection; however you still have

    the option to use different data types whenever you need to.

    Another difference between arrays and collections is that collections can add elements and remove

    elements directly and change in size without any need for some kind of processing, while arrays are

    fixed in size, and you cannot insert values at specific locations at random.

  • 8/10/2019 9. Controls Properties

    9/10

    Finally array elements can be updated and overwritten, while collections are not. To make this clear

    check out this:

    In this example if you write C(3) = 55 you get an error, that is because collection does not allow

    you to update or overwrite the content of an element. However there is a way to overcome this. We

    will discuss this later.

    Now let us see how to define a collection. There are two ways to define a collection:

    DimC AsNewCollection

    In this example you create a collection object that is ready to be used. So you can add, remove

    elements, get the number of items, or do whatever you want with the collection directly. Another

    way is:

    DimC AsCollection

    here C is not ready yet to be used. It does not point to a collection yet. You can never use it. To be

    able to use it later on in the code you should write:

    C =NewCollection

    This will allow you to use the collection without any problem. The first method of defining a

    collection is the one you will probably use the most.

    Now in order to add elements to the collection you use the add method.

  • 8/10/2019 9. Controls Properties

    10/10

    When you write C.Add the compiler shows you the parameters that you should provide. The ones in

    the square brackets are optional. The parameters are:

    Item: is the value you want to store Key: you can provide a text value to quickly access the elements of collection instead of

    providing numbers to access them. For example the code below will store the value 40 in V:

    DimC AsNewCollection

    C.Add(33, "Smith")

    C.Add(40, "Michel")

    C.Add(77, "John")

    DimV AsString

    V = C("Michel")

    Before: is the index of the item you want the new element to be inserted before.

    After: is the index of the item you want the new element to be inserted after.

    Next is removing elements. This simple, you just provide the index of the element you want to

    remove:

    C.Remove(3)

    This removes the 3rdelement from the collection.

    Also getting the number of elements is as easy. You use the count function.

    I = C.Count

    Finally we describe how to simulate the functionality replacing or updating an item in the array

    using collection.

    If we write :

    C.Add(N, , , 7)

    C.Remove(7)

    This will have exactly the same effect as:

    A(6) = N