ComboBox

Signaler
Messages postés
2
Date d'inscription
mardi 27 avril 2004
Statut
Membre
Dernière intervention
23 décembre 2004
-
Messages postés
6351
Date d'inscription
samedi 1 juin 2002
Statut
Modérateur
Dernière intervention
2 août 2014
-
j'en perd mon latin:

j'ai un form avec une série de comboBox.
le comboBox_selectedIndexChanged permet l'alimentation spécifique du second comboBox etc...
le premier test étant
if (this.comboBoxCodec.SelectedIndex != -1)
Hors en point d'arret je m'apperçois que SelectedIndex est toujours = -1.
Afin de vérifié que je ne m'étais pas trompé j'ai fait un mini projet avec un comboBox et un TexBox . sur l'évenement selectedIndexChanged j'alimentes le TextBox avec le selectedItem .
Tout marche bien.

Mais dans la fenêtre de l'application que je veux faire évoluer impossible d'obtenir un selectedindex différent de -1.

Y a t il une propriété quelconque de la form ou du control qui puisse expliquer que la selection d'un item dans le comboBox provoque bien l'évenement mais remonte toujours un selectedIndex = -1.

Merci de vos conseils et remarque...

L'union fait la force

4 réponses

Messages postés
5487
Date d'inscription
dimanche 4 août 2002
Statut
Modérateur
Dernière intervention
20 juin 2013
54
Euh, j'ai rapidement essayé, ça semble marcher chez moi.
Le mieux, c'est que tu postes ton code, "on" pourra mieux t'aider ! non??
Messages postés
6351
Date d'inscription
samedi 1 juin 2002
Statut
Modérateur
Dernière intervention
2 août 2014
92
je n'ai jamais rencontré ce probleme, ni entendu parler d'ailleurs
le mieux est effectivement que tu nous montre du code

Cocoricoooooooo !!!!
coq
MVP Visual C#
Messages postés
2
Date d'inscription
mardi 27 avril 2004
Statut
Membre
Dernière intervention
23 décembre 2004

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Manager;
using System.Data;
using System.Data.Odbc;

namespace serveur
{
/// <summary>
/// Description résumée de FormAdmRecordedVideo.
/// </summary>
public class FormAdmRecordedVideo : System.Windows.Forms.Form
{
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;
private Tools.executesql exe;
private Manager.Tools myTools;
private Manager.AlarmManager myalarme;
private Manager.DescManager Desc;
private Manager.VideoRecorder VideoRec;
private UserContext mycontext;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Data.Odbc.OdbcConnection OdbcVW;
protected System.Windows.Forms.TextBox textBoxHost;
private System.Windows.Forms.TextBox textBoxDB;
private System.Windows.Forms.Button buttonconnecter;
private System.Windows.Forms.Label label3;
private string host;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
public System.Windows.Forms.ComboBox comboBoxCodec;
private System.Windows.Forms.ComboBox comboBoxFps;
private System.Windows.Forms.ComboBox comboBoxMaxSpace;
private System.Windows.Forms.ComboBox comboBoxMaxTime;
private System.Windows.Forms.ComboBox comboBoxDiskSpace;
private System.Windows.Forms.TextBox textBox1;
private string bd;

public FormAdmRecordedVideo(ref Manager.Tools a_mytools,ref Tools.executesql a_exe,String a_title,ref Manager.VideoRecorder a_VideoRec,ref Manager.DescManager a_Desc ,UserContext a_mycontext):base()
{

this.exe=a_exe;
this.Text=a_title;
this.VideoRec = a_VideoRec;
this.Desc = a_Desc;
myTools=a_mytools;
InitializeComponent();
this.Visible=true;
mycontext=a_mycontext;

//DSN=ConfCentraliseVW;DESCRIPTION=Serveur de conf centralisée VW;
//PROTOCOL=2;VERSION=6;OPTIONS=256;DIALECT=3;
//SERVER=pc41347;
//DATABASE=C:\Program Files\VisioWave\Central Configuration\DB\CONFIG.DB;UID=php
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();

//
// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
//
}

/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.textBoxHost = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBoxDB = new System.Windows.Forms.TextBox();
this.OdbcVW = new System.Data.Odbc.OdbcConnection();
this.buttonconnecter = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.comboBoxCodec = new System.Windows.Forms.ComboBox();
this.comboBoxDiskSpace = new System.Windows.Forms.ComboBox();
this.comboBoxFps = new System.Windows.Forms.ComboBox();
this.comboBoxMaxSpace = new System.Windows.Forms.ComboBox();
this.comboBoxMaxTime = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBoxHost
//
this.textBoxHost.AcceptsReturn = true;
this.textBoxHost.AcceptsTab = true;
this.textBoxHost.AutoSize = false;
this.textBoxHost.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.textBoxHost.Location = new System.Drawing.Point(264, 56);
this.textBoxHost.Name = "textBoxHost";
this.textBoxHost.Size = new System.Drawing.Size(160, 20);
this.textBoxHost.TabIndex = 2;
this.textBoxHost.Text = "pc41347";
this.textBoxHost.Validated += new System.EventHandler(this.textBoxHost_Validated);
this.textBoxHost.TextChanged += new System.EventHandler(this.textBoxHost_TextChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 23);
this.label1.TabIndex = 3;
this.label1.Text = "Machine de la conf centralisée";
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 96);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(352, 16);
this.label2.TabIndex = 4;
this.label2.Text = "Répertoire et nom du fichier de configuration sur cette machine";
//
// textBoxDB
//
this.textBoxDB.Location = new System.Drawing.Point(40, 128);
this.textBoxDB.Name = "textBoxDB";
this.textBoxDB.Size = new System.Drawing.Size(440, 20);
this.textBoxDB.TabIndex = 5;
this.textBoxDB.Text = "C:/Program Files/VisioWave/Central Configuration/DB/CONFIG.DB;UID=php";
this.textBoxDB.Validated += new System.EventHandler(this.textBoxDB_Validated);
//
// OdbcVW
//
this.OdbcVW.ConnectionString = "DSN=ConfCentraliseVW;DESCRIPTION=Serveur de conf centralisée VW;PROTOCOL=2;VERSIO" +
"N=6;OPTIONS=256;DIALECT=3;SERVER=pc41347;DATABASE=C:\\Program Files\\VisioWave\\Cen" +
"tral Configuration\\DB\\CONFIG.DB;UID=php";
this.OdbcVW.InfoMessage += new System.Data.Odbc.OdbcInfoMessageEventHandler(this.OdbcVW_InfoMessage);
//
// buttonconnecter
//
this.buttonconnecter.Location = new System.Drawing.Point(120, 176);
this.buttonconnecter.Name = "buttonconnecter";
this.buttonconnecter.Size = new System.Drawing.Size(296, 23);
this.buttonconnecter.TabIndex = 6;
this.buttonconnecter.Text = "Lancer l\'intégration des données";
this.buttonconnecter.Click += new System.EventHandler(this.button2_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(48, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(128, 16);
this.label3.TabIndex = 7;
this.label3.Text = "DSN=ConfCentraliseVW";
//
// label4
//
this.label4.Location = new System.Drawing.Point(56, 224);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(256, 24);
this.label4.TabIndex = 8;
this.label4.Text = "Paramètres d\'enregistrement centralisé";
//
// label5
//
this.label5.Location = new System.Drawing.Point(72, 248);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(256, 23);
this.label5.TabIndex = 9;
this.label5.Text = "Codec effectuant l\'enregistrement centralisé:";
//
// label6
//
this.label6.Location = new System.Drawing.Point(72, 272);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(232, 23);
this.label6.TabIndex = 11;
this.label6.Text = "Espaces de Stockage:";
//
// label7
//
this.label7.Location = new System.Drawing.Point(72, 296);
this.label7.Name = "label7";
this.label7.TabIndex = 13;
this.label7.Text = "Nombre de Fps:";
//
// label8
//
this.label8.Location = new System.Drawing.Point(72, 320);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(168, 23);
this.label8.TabIndex = 14;
this.label8.Text = "Durée unitaire de stockage:";
//
// label9
//
this.label9.Location = new System.Drawing.Point(72, 344);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(224, 23);
this.label9.TabIndex = 15;
this.label9.Text = "Temps de préservation de l\'enregistrement:";
//
// comboBoxCodec
//
this.comboBoxCodec.AllowDrop = true;
this.comboBoxCodec.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxCodec.Location = new System.Drawing.Point(360, 248);
this.comboBoxCodec.Name = "comboBoxCodec";
this.comboBoxCodec.Size = new System.Drawing.Size(121, 21);
this.comboBoxCodec.TabIndex = 16;
this.comboBoxCodec.SelectedIndexChanged += new System.EventHandler(this.comboBoxCodec_SelectedIndexChanged);
//
// comboBoxDiskSpace
//
this.comboBoxDiskSpace.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxDiskSpace.Items.AddRange(new object[] {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0"});
this.comboBoxDiskSpace.Location = new System.Drawing.Point(360, 272);
this.comboBoxDiskSpace.Name = "comboBoxDiskSpace";
this.comboBoxDiskSpace.Size = new System.Drawing.Size(121, 21);
this.comboBoxDiskSpace.TabIndex = 17;
this.comboBoxDiskSpace.SelectedIndexChanged += new System.EventHandler(this.comboBoxDiskSpace_SelectedIndexChanged);
//
// comboBoxFps
//
this.comboBoxFps.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxFps.Location = new System.Drawing.Point(360, 296);
this.comboBoxFps.Name = "comboBoxFps";
this.comboBoxFps.Size = new System.Drawing.Size(121, 21);
this.comboBoxFps.TabIndex = 18;
//
// comboBoxMaxSpace
//
this.comboBoxMaxSpace.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxMaxSpace.Location = new System.Drawing.Point(360, 320);
this.comboBoxMaxSpace.Name = "comboBoxMaxSpace";
this.comboBoxMaxSpace.Size = new System.Drawing.Size(121, 21);
this.comboBoxMaxSpace.TabIndex = 19;
//
// comboBoxMaxTime
//
this.comboBoxMaxTime.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxMaxTime.Location = new System.Drawing.Point(360, 344);
this.comboBoxMaxTime.Name = "comboBoxMaxTime";
this.comboBoxMaxTime.Size = new System.Drawing.Size(121, 21);
this.comboBoxMaxTime.TabIndex = 20;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(520, 248);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 21;
this.textBox1.Text = "textBox1";
//
// FormAdmRecordedVideo
//
this.AcceptButton = this.buttonconnecter;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(672, 377);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.comboBoxMaxTime);
this.Controls.Add(this.comboBoxMaxSpace);
this.Controls.Add(this.comboBoxFps);
this.Controls.Add(this.comboBoxDiskSpace);
this.Controls.Add(this.comboBoxCodec);
this.Controls.Add(this.label9);
this.Controls.Add(this.label8);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.buttonconnecter);
this.Controls.Add(this.textBoxDB);
this.Controls.Add(this.textBoxHost);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.KeyPreview = true;
this.Name = "FormAdmRecordedVideo";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Gestion des Enregistrements Vidéo";
this.Load += new System.EventHandler(this.FormAdmRecordedVideo_Load);
this.ResumeLayout(false);

}
#endregion

private void FormAdmRecordedVideo_Load(object sender, System.EventArgs e)
{

host=textBoxHost.Text;
bd=textBoxDB.Text;
RecordParamInit();

}
private void RecordParamInit()
{
Device[] codecList;

codecList = Desc.getCodecList(mycontext,0);
this.comboBoxCodec.BeginUpdate();
foreach (Device codec in codecList)
{
this.comboBoxCodec.Items.Add(codec);

}
this.comboBoxCodec.EndUpdate();

int test = comboBoxCodec.Items.Count;

}

private void button2_Click(object sender, System.EventArgs e)
{

if (OdbcVW.State==System.Data.ConnectionState.Open)
{
OdbcVW.Close();
}
this.Validate();

OdbcVW.ConnectionString="DSN=ConfCentraliseVW;DESCRIPTION=Serveur de conf centralisée VW;";
OdbcVW.ConnectionString+=" PROTOCOL=2;VERSION=6;OPTIONS=256;DIALECT=3;";
OdbcVW.ConnectionString+="SERVER="+host;
OdbcVW.ConnectionString+=";DATABASE="+bd;

//OdbcVW.ConnectionString+="SERVER=pc41347;DATABASE=C:/Program Files/VisioWave/Central Configuration/DB/CONFIG.DB;UID=php";

try
{
if (OdbcVW.State!=System.Data.ConnectionState.Open)
{
OdbcVW.Open();
}
}
catch(Exception a)
{
MessageBox.Show(this," Vérifiez vos paramètres de connexion ou de chemin du fichier de confcentralisée "+a.Message+" "+OdbcVW.ConnectionString," Erreur de connection à la conf centralisée visiowave ");
return;
}

try
{

string req;
System.Data.Odbc.OdbcDataReader myreader;

req=" SELECT A.ADDRESS,C.VIDEO_PORT_ID,D.TCP_PORT,E.ADDRESS ,C.SKIP ";
req+=" FROM VW_CFG_HOSTS A, VW_CFG_STORAGE_SPACES B,";
req+=" VW_CFG_STORAGES C, VW_CFG_VIDEO_PORTS D,VW_CFG_HOSTS E";
req+=" WHERE A.ID=B.HOST_ID AND C.STORAGE_SPACE_ID=B.ID ";
req+=" AND C.VIDEO_PORT_ID=D.ID AND E.ID=D.HOST_ID ";
req+=" ORDER BY A.ADDRESS,C.VIDEO_PORT_ID,D.TCP_PORT";

OdbcCommand com=new System.Data.Odbc.OdbcCommand(req,OdbcVW,OdbcVW.BeginTransaction());

//On récupère tous les flux stockés de la conf centralisée
//adresse de machine de stockage, nom du flux, port tcp de
//la camera, adresse machine sur laquelle la camera est branchée

myreader=com.ExecuteReader();
DataSet tempcam,tempcodec;
exe(" delete from RecordedFlux ");

while (myreader.Read())
{
System.Console.WriteLine(myreader.GetString(0).Trim()+" - "+myreader.GetString(1).Trim()+" - "+myreader.GetInt32(2)+" - "+myreader.GetString(3)+" - "+myreader.GetString(4));
//pour chaque ligne on va donc chercher le no de la camera enregistrée et le codec sur le quel le flux est enregistré

string camrequest,codecrequest;
camrequest=" SELECT a.id FROM Device a ,Device b, SubDevice c ";
camrequest+=" WHERE UPPER(LTRIM(RTRIM(b.adresseip))) = '"+myreader.GetString(3).Trim().ToUpper()+"' ";
camrequest+=" and b.id =c.containerdevice and c.containeddevice=a.id and a.porttcp="+myreader.GetInt32(2).ToString().Trim();
tempcam=exe(camrequest);
System.Console.WriteLine(camrequest);
System.Console.WriteLine(tempcam.Tables[0].Rows.Count);

codecrequest=" SELECT b.id FROM Device b ";
codecrequest+=" WHERE UPPER(LTRIM(RTRIM(b.adresseip)))='"+myreader.GetString(0).Trim().ToUpper()+"' ";
tempcodec=exe(codecrequest);
System.Console.WriteLine(tempcodec.Tables[0].Rows.Count);

foreach(DataRow r1 in tempcam.Tables[0].Rows)
{
foreach(DataRow r2 in tempcodec.Tables[0].Rows)
{
decimal camid,codecid;
System.Console.WriteLine(" cam "+((decimal)r1[0]).ToString()+" codec enreg : "+((decimal)r2[0]).ToString()+" flux "+myreader.GetString(1).Trim()+ " skip "+myreader.GetString(4));
exe("sp_ins_rec_camera "+((decimal)r1[0]).ToString()+","+((decimal)r2[0]).ToString()+",'"+myreader.GetString(1).Trim()+"',"+myreader.GetString(4));

}
}

}
myreader.Close();
}
catch(Exception z)
{
System.Console.WriteLine(z.Message+" "+z.Source);
}

OdbcVW.Close();

}

private void textBoxHost_TextChanged(object sender, System.EventArgs e)
{
//sender.

}

private void OdbcVW_InfoMessage(object sender, System.Data.Odbc.OdbcInfoMessageEventArgs e)
{

}

private void textBoxHost_Validated(object sender, System.EventArgs e)
{
host=((TextBox) sender).Text;

}

private void textBoxDB_Validated(object sender, System.EventArgs e)
{
bd=((TextBox) sender).Text;
}

private void comboBoxCodec_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.textBox1.Text = this.comboBoxCodec.SelectedIndex.ToString();
if (this.comboBoxCodec.SelectedIndex != -1)
{
Device Codec;
Codec = (Manager.Device)this.comboBoxCodec.SelectedItem;
// Codec = (Device)this.comboBoxCodec.Items[this.comboBoxCodec.SelectedIndex];

if ( this.comboBoxCodec.SelectedItem.GetType().FullName == "Manager.DeviceVW" )
{
if(VideoRec.connect((DeviceVW)this.comboBoxCodec.SelectedItem))
{
StorageDiskSpace[] StorageDSInfo = VideoRec.GetDiskSpaceInfoOf((DeviceVW) this.comboBoxCodec.SelectedItem);
foreach (StorageDiskSpace SDS in StorageDSInfo)
{
this.comboBoxDiskSpace.Items.Add(SDS.name);
}
VideoRec.Disconnect();
}
else
{

}

}

}

}

private void comboBoxDiskSpace_SelectedIndexChanged(object sender, System.EventArgs e)
{
int i = this.comboBoxDiskSpace.SelectedIndex;
object o = this.comboBoxDiskSpace.SelectedItem;

}

}
}

L'union fait la force
Messages postés
6351
Date d'inscription
samedi 1 juin 2002
Statut
Modérateur
Dernière intervention
2 août 2014
92
bon, j'ai trouver qqch qui se rapproche de ce pb
essaie de faire ce qui est dit à cette page : http://www.codeproject.com/cs/combobox/csautocomplete.asp?msg=596855#xx612021xx

à savoir :

To get around this (another fundamental flaw in the .NET data binding mechanism), you will need to configure an event handler for the auto complete combobox's Validating event from your parent control (or form).

ie:

public class Form1 : System.Windows.Forms.Form
{

public Form1()
{
InitializeComponent();

comboBox.Validating += new System.CancelEventHandler(comboBox_Validating);
}

private void comboBox_Validating(object sender, CancelEventArgs e)
{
this.OnValidating(e);
}
}



Cocoricoooooooo !!!!
coq
MVP Visual C#