How do i to get the code of selected item on ListBox?
Let me mean what are happening.
In my report, I have a form where the user should find the name of your client by inserting his name for find it. (Some parts of him).
The result is showing in a list below it. So, he needs to select the appropriate result for continues showing the report.
To here, all right. But, when the user select a result in list and presses ok for continue. On report, the result isn't correct. Sometime the report shows the data from the first item of the list box, or the last.
Follows some pictures:
Fist test: Result: Second test: Result: The code of search button:
This part, i think that works, because the List Box is filled correctly.
if(!txt_Cliente.Text.Equals(String.Empty)){
Boolean c = false;
if(check_Cliente.Checked == true){
NomeCliente = "%" + txt_Cliente.Text + "%";
c = true;
}else if (check_Codigo.Checked == true){
long codteste;
if(long.TryParse(txt_Cliente.Text.Trim(), out codteste)){
CodigoCliente = codteste;
c = true;
}else{
MessageBox.Show("Código inválido.");
}
}
if(c){
PesquisaCliente.Connect();
object [] values = Stimulsoft.Report.Dictionary.StiDataColumn.GetDatasFromDataColumn(this.Dictionary, "PesquisaCliente.NOME");
Array.Sort(values);
list_Horarios.Items.Clear();
list_Horarios.Items.AddRange(values);
}
}
The code of button 'Ok':
Boolean sucess = false;
if(list_Horarios.SelectedIndex != null && list_Horarios.SelectedIndex != -1){
long codCliente;
if(long.TryParse(PesquisaCliente.GetData("CODIGO", list_Horarios.SelectedIndex).ToString(), out codCliente)){
CodigoCliente = codCliente;
Parametros = " WHERE P.pk_codPessoa = @CodigoCliente ORDER BY DATASESSAO ";
sucess = true;
}
}
if(sucess){
this.btn_Ok.DialogResult = System.Windows.Forms.DialogResult.OK;
ConsultaAgenda.Connect();
}
But, here. The code isn't right.
For instance:
The code of the selected result in ListBox, is 7 on database, but is being 299.
The Dictionary: Last:
The query is right, only the code that it receives is that wrong.
I hope that you understand.

Thanks