Opt In (Do Not Edit Here)

Showing posts with label ListView. Show all posts
Showing posts with label ListView. Show all posts

Sep 2, 2012

Enlist Printer(s) on the System


Description:

About Classes used -

#1: An object of PrintDocument class, allow for setting the properties that describe how to print, and call the Print method to start the printing process.

#2:  PrinterSettings class, Specifies information about how a document is printed, including
     the printer that prints it, when printing from a Windows Forms application.

Namespace Required - System.Drawing.Printing


Controls used:
1.    ListView Control (lvPrinters)
2.    Button Control (btnGetPrinter & btnExit)

Here I implemented the Code for enlisting the printer(s) installed on the system.

           
The Code: (do necessary changes)
1. Variables Declaration.
                        Boolean value = true;
                        String Default = "";

Listing 1


2. Search for Default Printer.
                   // Determine Default Printer Exist or Not
                   if ((new PrintDocument()).PrinterSettings.IsDefaultPrinter == value)
            {
            // if Exist Fetch the Printer’s Name
                  ListViewItem item = new ListViewItem(Default =
                            (new PrintDocument()).PrinterSettings.PrinterName);
                  item.SubItems.Add(value.ToString());              

                  // Add the Default Printer's Name to ListView
                  lvPrinters.Items.Add(item);                
                 
            value = false; // Reset Boolean Value to False
            }
Listing 2


3. Search for Other Printer(s)
                   //Fetch All Installed Printer's Name
                   foreach (object var in PrinterSettings.InstalledPrinters)
            {
                  // Compare Installed Printer(s) Name with Default Printer
                  if (Default != var.ToString())
                  {
                        ListViewItem item = new ListViewItem(var.ToString());
                        item.SubItems.Add(value.ToString());

                        // Add Remaining Printer's Name to ListView
                        lvPrinters.Items.Add(item);
                  }
            }
Listing 3
   

4. Now execute the Application and see the result (Figure 1).


         
Intended Result:


Figure 1


Summary:

          In this piece of writing, using C# environment, we have seen how to retrieve printer(s) name installed on the system.

Retrieve Properties of Running Processes



Description:

About Classes used -

            #1: Process class, provides an access to local & remote processes, also enable to start & stop  
local system processes. Using the Process component, we can obtain a list of the
processes that are running, or can start a new process.

Namespace Required - System. Diagnostics


Here I implemented the Code for enlisting the properties of running processes of the local system.

           
The Code: (do necessary changes)

1. Access the Running Processes (ProcessID & ProcessName) (code for “Refresh” Button).
            //Look for Currently Running Processes
            foreach (Process var in Process.GetProcesses())
                   {
                  try
                  {
                     ListViewItem item = new ListViewItem(var.MainModule.ModuleName);
                     item.SubItems.Add(var.Id.ToString());

                     lvProcesses.Items.Add(item); //Add Process Name & ID to ListView
                  }catch (Exception) { //Add code for Exception (if any) }
            }
Listing 1


2. Display the Properties of Selected Process (code for “Show” Button)
            // Get ProcessID of Selected Process From Listview
            Process P = Process.GetProcessById(Convert.ToInt16(“SelectedProcess”);
                   try
            {
                lblDescription.Text = "File Description : " +
                                     P.MainModule.FileVersionInfo.FileDescription;

          lblCompany.Text = "Company Name : " +
                                    P.MainModule.FileVersionInfo.CompanyName;

                lblVersion.Text = "Version : " +  
                                          P.MainModule.FileVersionInfo.ProductVersion;

                lblCopyright.Text = "Copyright : " +
                                          P.MainModule.FileVersionInfo.LegalCopyright;

                lblTrademark.Text = "Internal Name : " +
                                          P.MainModule.FileVersionInfo.InternalName;

                lblLanguge.Text = "Language : " +
                                          P.MainModule.FileVersionInfo.Language;

                txtPath.Text = P.MainModule.FileVersionInfo.FileName;

            } catch (Exception) { //Add code for Exception (if any)  }
Listing 2


3. Now execute the Application and see the result (Figure 1).


         
Intended Result:


Figure 1


Summary:

          In this piece of writing, using C# environment, we have seen how to access the properties of running properties on the local system.

Aug 3, 2011

Transference of ListView Data

Transferring Data of ListView Control on Same

windows form or at another windows form


Ingredients:

n One or More Windows Forms

n One or More ListView Controls

n Two Button Controls

Description:

The Blog shows transferring or passing a whole row from one ListView Control to another on Same Windows Form or at another Windows Form. This may also be helpful to do similar activities such as Transference of Full Column or a particular Cell value.

Justification:

  1. Here I used an XML File for Accessing Data, you can also use another Data Source as replacement for an XML File

  1. While working with as GridView or ListView Control we have to first trace the Cell/Row/Column Number to know what the data is being manipulated.

  1. Figure 1 & Figure 2 shows the intended result

Figure 1

Figure 2

Conclude:

In this session, we have seen the ListView operation for shifting row(s) from one ListView Control to other.

All Rights Reserved. 2014 Copyright SIMPLITONA

Powered By Blogger | Published By Gooyaabi Templates Designed By : BloggerMotion

Top