Handling Events inside a "while" clause
-
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
-
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
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... ;) -
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
-
Show only the relevand code, and use the pre tag to make it readable. --- b { font-weight: normal; }
-
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... ;)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).
-
sorry, it was my first message and it was very important for me, I'll remember for the next time! thank you
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 -
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