Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Handling Events inside a "while" clause

Handling Events inside a "while" clause

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpdatabasedotnetvisual-studiographics
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ninodago
    wrote on last edited by
    #1

    Hi to all. I have a problem with my thesis. I'm realizing an application with VS .Net 2003 for PDA in C#. I have a catalog stored into the PDA and I want to navigate into it. I've builded a database which consists of 4 important tables: three categories tables (First, Second and Third) and the "Products" table. I use a ListView object to navigate inside the categories. The code is this (I bolded the important part): using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data.SqlServerCe; using System.Data.SqlClient; using System.Data; using System.Reflection; using System.IO; namespace SmartDeviceApplication3 { /// /// Form per sfogliare il catalogo - Form to navigate inside the catalog /// public class FormSfogliaCatalogo : System.Windows.Forms.Form { private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label5; private System.Windows.Forms.PictureBox pictureBox3; private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox pictureBox4; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.ListView listViewCatalogo; public FormSfogliaCatalogo() { // // Required for Windows Form Designer support // InitializeComponent(); listViewCatalogo.Activation = ItemActivation.OneClick; listViewCatalogo.View = System.Windows.Forms.View.SmallIcon; //Declare the connection variable SqlCeConnection sqlConn1 = new SqlCeConnection(); try { // Open a connection to the database sqlConn1.ConnectionString = "Data Source =\\My Documents\\db.sdf"; sqlConn1.Open(); SqlCeCommand searchCommand = new SqlCeCommand(); searchCommand.Connection = sqlConn1; searchCommand.CommandText = "SELECT * FROM TIPOLOGIA_PRIMARIA"; // it means select * from first category // Execute and return the rows in the data reader object SqlCeDataReader dR; dR = searchCommand.ExecuteReader(CommandBehavior.CloseConnection); int nFields = dR.FieldCount; // Setup the columns in the listview using the fields in the table listViewCatalogo.Clear(); listViewCatalogo.Columns.Add("Categoria", -1, HorizontalAlignment.Left); // Fill the rows in the l

    H G 2 Replies Last reply
    0
    • N ninodago

      Hi to all. I have a problem with my thesis. I'm realizing an application with VS .Net 2003 for PDA in C#. I have a catalog stored into the PDA and I want to navigate into it. I've builded a database which consists of 4 important tables: three categories tables (First, Second and Third) and the "Products" table. I use a ListView object to navigate inside the categories. The code is this (I bolded the important part): using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data.SqlServerCe; using System.Data.SqlClient; using System.Data; using System.Reflection; using System.IO; namespace SmartDeviceApplication3 { /// /// Form per sfogliare il catalogo - Form to navigate inside the catalog /// public class FormSfogliaCatalogo : System.Windows.Forms.Form { private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label5; private System.Windows.Forms.PictureBox pictureBox3; private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox pictureBox4; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.ListView listViewCatalogo; public FormSfogliaCatalogo() { // // Required for Windows Form Designer support // InitializeComponent(); listViewCatalogo.Activation = ItemActivation.OneClick; listViewCatalogo.View = System.Windows.Forms.View.SmallIcon; //Declare the connection variable SqlCeConnection sqlConn1 = new SqlCeConnection(); try { // Open a connection to the database sqlConn1.ConnectionString = "Data Source =\\My Documents\\db.sdf"; sqlConn1.Open(); SqlCeCommand searchCommand = new SqlCeCommand(); searchCommand.Connection = sqlConn1; searchCommand.CommandText = "SELECT * FROM TIPOLOGIA_PRIMARIA"; // it means select * from first category // Execute and return the rows in the data reader object SqlCeDataReader dR; dR = searchCommand.ExecuteReader(CommandBehavior.CloseConnection); int nFields = dR.FieldCount; // Setup the columns in the listview using the fields in the table listViewCatalogo.Clear(); listViewCatalogo.Columns.Add("Categoria", -1, HorizontalAlignment.Left); // Fill the rows in the l

      H Offline
      H Offline
      HumanOsc
      wrote on last edited by
      #2

      1.) You can use the SelectedIndex Property to check if an item is selected... if(listView.SelectedIndex == -1) return; 2.) It's recommend to disabling the updateing mechanism when you are adding items... // disable updating mechanism listView.BeginUpdate(); while(...) { // adding items here } // enable updating mechanism listView.EndUpdate(); By the way you should named you variables more significant... ;)

      N 1 Reply Last reply
      0
      • N ninodago

        Hi to all. I have a problem with my thesis. I'm realizing an application with VS .Net 2003 for PDA in C#. I have a catalog stored into the PDA and I want to navigate into it. I've builded a database which consists of 4 important tables: three categories tables (First, Second and Third) and the "Products" table. I use a ListView object to navigate inside the categories. The code is this (I bolded the important part): using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data.SqlServerCe; using System.Data.SqlClient; using System.Data; using System.Reflection; using System.IO; namespace SmartDeviceApplication3 { /// /// Form per sfogliare il catalogo - Form to navigate inside the catalog /// public class FormSfogliaCatalogo : System.Windows.Forms.Form { private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label5; private System.Windows.Forms.PictureBox pictureBox3; private System.Windows.Forms.PictureBox pictureBox2; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.PictureBox pictureBox4; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.ListView listViewCatalogo; public FormSfogliaCatalogo() { // // Required for Windows Form Designer support // InitializeComponent(); listViewCatalogo.Activation = ItemActivation.OneClick; listViewCatalogo.View = System.Windows.Forms.View.SmallIcon; //Declare the connection variable SqlCeConnection sqlConn1 = new SqlCeConnection(); try { // Open a connection to the database sqlConn1.ConnectionString = "Data Source =\\My Documents\\db.sdf"; sqlConn1.Open(); SqlCeCommand searchCommand = new SqlCeCommand(); searchCommand.Connection = sqlConn1; searchCommand.CommandText = "SELECT * FROM TIPOLOGIA_PRIMARIA"; // it means select * from first category // Execute and return the rows in the data reader object SqlCeDataReader dR; dR = searchCommand.ExecuteReader(CommandBehavior.CloseConnection); int nFields = dR.FieldCount; // Setup the columns in the listview using the fields in the table listViewCatalogo.Clear(); listViewCatalogo.Columns.Add("Categoria", -1, HorizontalAlignment.Left); // Fill the rows in the l

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Show only the relevand code, and use the pre tag to make it readable. --- b { font-weight: normal; }

        N 1 Reply Last reply
        0
        • G Guffa

          Show only the relevand code, and use the pre tag to make it readable. --- b { font-weight: normal; }

          N Offline
          N Offline
          ninodago
          wrote on last edited by
          #4

          sorry, it was my first message and it was very important for me, I'll remember for the next time! thank you

          H 1 Reply Last reply
          0
          • H HumanOsc

            1.) You can use the SelectedIndex Property to check if an item is selected... if(listView.SelectedIndex == -1) return; 2.) It's recommend to disabling the updateing mechanism when you are adding items... // disable updating mechanism listView.BeginUpdate(); while(...) { // adding items here } // enable updating mechanism listView.EndUpdate(); By the way you should named you variables more significant... ;)

            N Offline
            N Offline
            ninodago
            wrote on last edited by
            #5

            HumanOsc wrote:

            1.) You can use the SelectedIndex Property to check if an item is selected... if(listView.SelectedIndex == -1) return;

            I don't have the definition SelectedIndex inside ListView. ('System.Windows.Forms.ListView' does not contain a definition for 'SelectedIndex')... I use VS .Net 2003 with CF 1.0. I used this code, but I'm not sure if it has the same effect... if (listViewCatalogo.SelectedIndices[0] == -1) return; Another question. In which point of the program should I use this code? Inside the definition of listViewCatalogo_SelectedIndexChanged event? When I deploy I have the same errors. If I declare the control inside or outside the while clause I have this message: Error: index (I mean, the variable passed to the last testing form(FormProdotto).

            1 Reply Last reply
            0
            • N ninodago

              sorry, it was my first message and it was very important for me, I'll remember for the next time! thank you

              H Offline
              H Offline
              HumanOsc
              wrote on last edited by
              #6

              Ok, sorry it was my fault... Sometimes i mix two different classes... I mean the SelectedItems Property... if(listView.SelectedItems.Count == 0) return; You should check the collection if it's contains items, before you get anyone... Well, in your app in the SelectedIndex_Changed handler... // get sure that one item is selected if(listViewCatalogo.SelectedItems.Count == 0) return; i = listViewCatalogo.SelectedIndices[0]; -- modified at 7:28 Tuesday 14th February, 2006

              N 1 Reply Last reply
              0
              • H HumanOsc

                Ok, sorry it was my fault... Sometimes i mix two different classes... I mean the SelectedItems Property... if(listView.SelectedItems.Count == 0) return; You should check the collection if it's contains items, before you get anyone... Well, in your app in the SelectedIndex_Changed handler... // get sure that one item is selected if(listViewCatalogo.SelectedItems.Count == 0) return; i = listViewCatalogo.SelectedIndices[0]; -- modified at 7:28 Tuesday 14th February, 2006

                N Offline
                N Offline
                ninodago
                wrote on last edited by
                #7

                Thanks a lot, I made the changes and now the running is quite good! Bye Nino Look Torino 2006 - - - - - FORZA ITALIA!!!

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups