Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Working with Check List Box in VB.Net

Author: Zunnair
Download Source Code :

In this article I will try to show the way in which you can use check list box Control in useful and Exact manner for which it is made.remeber check List Box’s Application is different.

For better Undersatnding Follow these Steps.

1-Make  Application


2-Drag Check List Box From ToolBar To Form


3- Nd Also Place A label


4- after that write these line of code this code in fact make globel Const string which will be used in future as Check lidst box Input.


   Inherits System.Windows.Forms.Form

    Private Const CMD_LOAD_XML_FILE As String = "1"

    Private Const CMD_LOAD_XML_STRING As String = "2"

    Private Const CMD_TEST_FOR_CHILD_NODES As String = "3"

    Private Const CMD_ITERATE_ALL_NODES As String = "4"

    Private Const CMD_DETERMINE_NODE_TYPE As String = "5"

    Private Const CMD_LIST_ALL_ELEMENT_NODES As String = "6"

    Private Const CMD_LIST_ELEMENTS_BY_TAG As String = "7"

    Private Const CMD_SELECT_NODES As String = "8"

    Private Const CMD_SELECT_NODE As String = "9"

    Private Const CMD_NAVIGATE_RELATED_NODES As String = "10"

    Private Const CMD_RETRIEVE_ATTRIBUTES As String = "11"

    Private Const CMD_CREATE_XML As String = "12"

    Private Const CMD_ADD_OR_DELETE_ELEMENTS As String = "13"

    Private Const CMD_ADD_OR_DELETE_ATTRIBUTES As String = "14"

    Private Const CMD_MODIFY_ELEMENT As String = "15"

    Private Const CMD_MODIFY_ATTRIBUTE As String = "16"

    Private Const CMD_VALID_XML As String = "17"

    Private Const CMD_PARSE_ERRORS As String = "18"



Notice that I have used the ViewState. The reason is I need to maintain the value of read file at multiple post backs. Notice one more thing here I have used the ‘ReadAllText’ method that returns the file in form of string. You can perform the similar task by using the StreamReader. But this will not read file from server it reads from buffer. To read file from server you always need to save the file in ‘wwwroot’ and then access. Remember one thing, to work with File Class you need to import the System.IO namespace. Now add the code in cmdViewFilePro event: 


5- now by Doubvle clicking on form its load Event is created then used that Event and write the code below as it is written .this code infact use to insert the values of Ckeck list box.


With Me.CLB.Items

            .Add(CMD_LOAD_XML_FILE, False)

            .Add(CMD_LOAD_XML_STRING, False)

            .Add(CMD_TEST_FOR_CHILD_NODES, False)

            .Add(CMD_ITERATE_ALL_NODES, False)

            .Add(CMD_DETERMINE_NODE_TYPE, False)

            .Add(CMD_LIST_ALL_ELEMENT_NODES, False)

            .Add(CMD_LIST_ELEMENTS_BY_TAG, False)

            .Add(CMD_SELECT_NODES, False)

            .Add(CMD_SELECT_NODE, False)

            .Add(CMD_NAVIGATE_RELATED_NODES, False)

            .Add(CMD_RETRIEVE_ATTRIBUTES, False)

            .Add(CMD_CREATE_XML, False)

            .Add(CMD_ADD_OR_DELETE_ELEMENTS, False)

            .Add(CMD_MODIFY_ELEMENT, False)

            .Add(CMD_ADD_OR_DELETE_ATTRIBUTES, False)

            .Add(CMD_MODIFY_ATTRIBUTE, False)

            .Add(CMD_VALID_XML, False)

            .Add(CMD_PARSE_ERRORS, False)

        End With


Now in the lats create the check list box check event by selecting the events against Check list Box events.

And write the Code below this code infact distinguish between the check list of Box and generate its String value and Copy it to the label.


Private Sub CLB_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CLB.ItemCheck

        If e.NewValue = CheckState.Checked Then

            Select Case Me.CLB.Items(e.Index).ToString()

                Case CMD_LOAD_XML_FILE

                    Label1.Text = CMD_LOAD_XML_FILE

                Case CMD_LOAD_XML_STRING

                    Label1.Text = CMD_LOAD_XML_STRING

                Case CMD_TEST_FOR_CHILD_NODES

                    Label1.Text = CMD_TEST_FOR_CHILD_NODES

                Case CMD_ITERATE_ALL_NODES

                    Label1.Text = CMD_ITERATE_ALL_NODES

                Case CMD_DETERMINE_NODE_TYPE

                    Label1.Text = CMD_DETERMINE_NODE_TYPE

                Case CMD_LIST_ALL_ELEMENT_NODES

                    Label1.Text = CMD_LIST_ALL_ELEMENT_NODES

                Case CMD_LIST_ELEMENTS_BY_TAG

                    Label1.Text = CMD_LIST_ELEMENTS_BY_TAG

                Case CMD_SELECT_NODES

                    Label1.Text = CMD_SELECT_NODES

                Case CMD_SELECT_NODE

                    Label1.Text = CMD_SELECT_NODE


                    Label1.Text = "10"

                Case CMD_RETRIEVE_ATTRIBUTES

                    Label1.Text = "11"

                Case CMD_CREATE_XML

                    Label1.Text = "12"

                Case CMD_ADD_OR_DELETE_ELEMENTS

                    Label1.Text = "13"

            End Select

        End If

    End Sub


This is a simple article .i hope u will like and enjoying this Article. If you feel any difficulty then reference the source code.because Source code is given with this Article for your proper understanding.

Add Article Comment:
Name :
Email Address :
Comments :
<< How we can Call Perform for OS Operations Using VB.Net

Disclaimer - Privacy
© 2002-2015