Click here to Skip to main content
15,905,136 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Questioninstallation problem Pin
united1814-Feb-06 3:28
united1814-Feb-06 3:28 
AnswerRe: installation problem Pin
KreativeKai16-Feb-06 4:28
professionalKreativeKai16-Feb-06 4:28 
QuestionRun atlas under 1.1 .net framework Pin
RUDOLFYAN13-Feb-06 18:43
RUDOLFYAN13-Feb-06 18:43 
AnswerRe: Run atlas under 1.1 .net framework Pin
Kevin McFarlane14-Feb-06 10:19
Kevin McFarlane14-Feb-06 10:19 
QuestionCompact Framework toolbar Pin
Federico Milano13-Feb-06 9:27
Federico Milano13-Feb-06 9:27 
Question"Automation Server can't create object" Pin
Jader8913-Feb-06 6:28
Jader8913-Feb-06 6:28 
QuestionICustomFormatter and IFormattable Pin
Jason McBurney13-Feb-06 5:33
Jason McBurney13-Feb-06 5:33 
QuestionHandling Events inside a "while" clause Pin
ninodago13-Feb-06 5:05
ninodago13-Feb-06 5:05 
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 listview using the data in the rows

int nRow = 0;


while (dR.Read())

{

// Create an array of subitems for quick insertion

// The subitems will be all fields in the row except for

// the first field

String [] subitems = new String[nFields];

subitems[0] = dR[3].ToString();

// Insert a new item into the listview, and add the subitems at

// the same time. The item will be the first field in the row

ListViewItem item = new ListViewItem(subitems);

listViewCatalogo.Items.Add(item);

ImageList imageListSmall = new ImageList();

imageListSmall.ImageSize = new Size(30,30);

imageListSmall.Images.Add(LoadImage("Dir.bmp"));

listViewCatalogo.SmallImageList = imageListSmall;

listViewCatalogo.Items[nRow].ImageIndex = 0;

++nRow;

}


dR.Close();

}

catch (Exception ex)

{

// If an error occured alert the user

MessageBox.Show("Error: " + ex.Message);

}

finally

{

// Close the connection if necessary

if (sqlConn1.State == System.Data.ConnectionState.Open)

sqlConn1.Close();

}

//

// TODO: Add any constructor code after InitializeComponent call

//

}

///

/// Clean up any resources being used.

///


protected override void Dispose( bool disposing )

{

base.Dispose( disposing );

}

#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///


private void InitializeComponent()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormSfogliaCatalogo));

this.listViewCatalogo = new System.Windows.Forms.ListView();

this.panel1 = new System.Windows.Forms.Panel();

this.label8 = new System.Windows.Forms.Label();

this.label7 = new System.Windows.Forms.Label();

this.label6 = new System.Windows.Forms.Label();

this.label5 = new System.Windows.Forms.Label();

this.pictureBox3 = new System.Windows.Forms.PictureBox();

this.pictureBox2 = new System.Windows.Forms.PictureBox();

this.pictureBox1 = new System.Windows.Forms.PictureBox();

this.pictureBox4 = new System.Windows.Forms.PictureBox();

this.mainMenu1 = new System.Windows.Forms.MainMenu();

//

// listViewCatalogo

//

this.listViewCatalogo.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;

this.listViewCatalogo.Location = new System.Drawing.Point(0, 56);

this.listViewCatalogo.Size = new System.Drawing.Size(256, 216);

this.listViewCatalogo.SelectedIndexChanged += new EventHandler(this.listViewCatalogo_SelectedIndexChanged);

this.Controls.Add(listViewCatalogo);

//

// panel1

//

this.panel1.BackColor = System.Drawing.Color.Gainsboro;

this.panel1.Controls.Add(this.label8);

this.panel1.Controls.Add(this.label7);

this.panel1.Controls.Add(this.label6);

this.panel1.Controls.Add(this.label5);

this.panel1.Controls.Add(this.pictureBox3);

this.panel1.Controls.Add(this.pictureBox2);

this.panel1.Controls.Add(this.pictureBox1);

this.panel1.Controls.Add(this.pictureBox4);

this.panel1.Size = new System.Drawing.Size(256, 56);

//

// label8

//

this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.25F, System.Drawing.FontStyle.Regular);

this.label8.ForeColor = System.Drawing.Color.Blue;

this.label8.Location = new System.Drawing.Point(136, 32);

this.label8.Text = "Offerte e promozioni";

//

// label7

//

this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.25F, System.Drawing.FontStyle.Regular);

this.label7.ForeColor = System.Drawing.Color.Blue;

this.label7.Location = new System.Drawing.Point(32, 32);

this.label7.Size = new System.Drawing.Size(80, 20);

this.label7.Text = "Cerca prodotto";

//

// label6

//

this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.25F, System.Drawing.FontStyle.Regular);

this.label6.ForeColor = System.Drawing.Color.Blue;

this.label6.Location = new System.Drawing.Point(136, 8);

this.label6.Text = "Sfoglia catalogo";

//

// label5

//

this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.25F, System.Drawing.FontStyle.Regular);

this.label5.ForeColor = System.Drawing.Color.Blue;

this.label5.Location = new System.Drawing.Point(32, 8);

this.label5.Size = new System.Drawing.Size(80, 20);

this.label5.Text = "Aggiornamento";

//

// pictureBox3

//

this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image")));

this.pictureBox3.Location = new System.Drawing.Point(112, 8);

this.pictureBox3.Size = new System.Drawing.Size(20, 20);

this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;

//

// pictureBox2

//

this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));

this.pictureBox2.Location = new System.Drawing.Point(8, 32);

this.pictureBox2.Size = new System.Drawing.Size(20, 20);

this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;

//

// pictureBox1

//

this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));

this.pictureBox1.Location = new System.Drawing.Point(8, 8);

this.pictureBox1.Size = new System.Drawing.Size(20, 20);

this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;

//

// pictureBox4

//

this.pictureBox4.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox4.Image")));

this.pictureBox4.Location = new System.Drawing.Point(112, 32);

this.pictureBox4.Size = new System.Drawing.Size(20, 20);

this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;

//

// FormSfogliaCatalogo

//

this.ClientSize = new System.Drawing.Size(258, 270);

this.Controls.Add(this.panel1);

this.Controls.Add(this.listViewCatalogo);

this.Menu = this.mainMenu1;

this.Text = "Catalogo";

}

#endregion



public void listViewCatalogo_SelectedIndexChanged(object sender, System.EventArgs e)

{


int sum = listViewCatalogo.SelectedIndices.Count;

int i;

i = listViewCatalogo.SelectedIndices[0];

if(listViewCatalogo.Items[i].Selected == true)

{

//to test the program


FormProdotto frm = new FormProdotto(i);

frm.Show();

return;

}

}

...



}

}



There are some problems:



1. If I deploy, I have no errors, but in executing phase I have error because the initialization of the listViewCatalogo.SelectedIndexChanged event is not correct, because it needs the items of the listview which are created dynamically (inside the "while dR.Read" clause);

2. If I put the eventhandler inside the "while clause", I have the problem that, for each row the listview creates dynamically, there is a call to my event (so I have X calls while I should have just one call, corresponding to the single item clicking).

I don't know where to initializes my event. Does anyone have a suggest?

Thank you.

Greetings from Italy

Nino

PS: Sorry for my bad English....
AnswerRe: Handling Events inside a "while" clause Pin
HumanOsc13-Feb-06 5:49
HumanOsc13-Feb-06 5:49 
GeneralRe: Handling Events inside a "while" clause Pin
ninodago14-Feb-06 1:00
ninodago14-Feb-06 1:00 
GeneralRe: Handling Events inside a "while" clause Pin
Guffa13-Feb-06 6:03
Guffa13-Feb-06 6:03 
GeneralRe: Handling Events inside a "while" clause Pin
ninodago13-Feb-06 22:55
ninodago13-Feb-06 22:55 
GeneralRe: Handling Events inside a "while" clause Pin
HumanOsc14-Feb-06 1:27
HumanOsc14-Feb-06 1:27 
GeneralRe: Handling Events inside a "while" clause Pin
ninodago14-Feb-06 6:02
ninodago14-Feb-06 6:02 
Questionreading third party Snap-in information in MMC programatically Pin
krompo13-Feb-06 4:36
krompo13-Feb-06 4:36 
QuestionSocket Exception Delay?? Pin
ckaneAV10-Feb-06 9:04
ckaneAV10-Feb-06 9:04 
Questionactivex .ocx with c# and visual studio .net Pin
kopi_b10-Feb-06 3:14
kopi_b10-Feb-06 3:14 
AnswerRe: activex .ocx with c# and visual studio .net Pin
Dave Kreskowiak10-Feb-06 5:56
mveDave Kreskowiak10-Feb-06 5:56 
Question.Net Framework Security Pin
Indu Mahadevan9-Feb-06 19:03
Indu Mahadevan9-Feb-06 19:03 
QuestionFramework version issue Pin
Lisana9-Feb-06 11:01
Lisana9-Feb-06 11:01 
AnswerRe: Framework version issue Pin
Dave Kreskowiak10-Feb-06 6:06
mveDave Kreskowiak10-Feb-06 6:06 
GeneralRe: Framework version issue Pin
Lisana10-Feb-06 6:16
Lisana10-Feb-06 6:16 
GeneralRe: Framework version issue Pin
Dave Kreskowiak10-Feb-06 9:19
mveDave Kreskowiak10-Feb-06 9:19 
GeneralRe: Framework version issue Pin
Lisana10-Feb-06 10:14
Lisana10-Feb-06 10:14 
GeneralRe: Framework version issue Pin
Dave Kreskowiak10-Feb-06 14:07
mveDave Kreskowiak10-Feb-06 14:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.