Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 18-12-2017
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.
Cita:
Empezado por aguml Ver Mensaje
Código PHP:
lb1->OnVerticalScroll ListBoxVScroll
Esa funcion no aparece por ningun sitio en tu codigo último por lo que pienso que puede ser por eso pero se me
¡ Mil disculpas ! no copié la función que en el ejemplo le había asignado al evento OnVerticalScroll , era esta:
Código PHP:
void __fastcall TForm1::ListBoxVScroll(TObject *Sender)
{
  
TMyListBox *lb static_cast<TMyListBox*>(Sender);
  
lb->Selected[lb->CurrentIndex] = true;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #2  
Antiguo 18-12-2017
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola de nuevo.

Me quedé pensando que si deseas que la selección del item se realize dentro de la misma clase, podes prescindir del evento _vScroll, por lo que podría quedar así:
Código PHP:
class TMyListBox : public TListBox
{
private:
  
TWndMethod _oldWndProc;

protected:
  
virtual void __fastcall WndProc(TMessage &msg);

public:
  
__fastcall TMyListBox(TComponent *Owner);
  
__fastcall ~TMyListBox();
};

//...

__fastcall TMyListBox::TMyListBox(TComponent *Owner) : TListBox(Owner)
{
    
_oldWndProc WindowProc;
}

void __fastcall TMyListBox:: WndProc(TMessage &msg)
{
  if( 
msg.Msg == WM_VSCROLL )
    
Selected[GetScrollPos(HandleSB_VERT)]= true// seleccionar
  
TListBox::WndProc(msg);
}

__fastcall TMyListBox::~TMyListBox()
{
  
WindowProc _oldWndProc;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 18-12-2017 a las 13:40:46.
Responder Con Cita
  #3  
Antiguo 18-12-2017
Avatar de aguml
aguml aguml is offline
Miembro
 
Registrado: may 2013
Posts: 885
Poder: 14
aguml Va por buen camino
Bueno, esa parte ya la tenia solucionada viendo como se hacia en el codigo anterior que pusiste pero ahora estaba con el tema del evento OnChange el cual he solucionado asi:
ListBoxAutoSelect.h:
Código PHP:
//---------------------------------------------------------------------------

#ifndef ListBoxAutoSelectH
#define ListBoxAutoSelectH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TListBoxAutoSelect : public TListBox
{
private:
    
int _index,_LastItemIndex;
    
TWndMethod _oldWndProc;
    
TNotifyEvent _vScroll;
    
TNotifyEvent _OnChange;
protected:
    
virtual void __fastcall WndProc(TMessage &msg) {
        if (
msg.Msg == WM_VSCROLL) {
            
_index GetScrollPos(this->HandleSB_VERT);
            
Selected[_index] = true;
            
            if(
_vScroll){
                
_vScroll(this);
            }
            if(
_LastItemIndex != ItemIndex){
                
_LastItemIndex ItemIndex;
                if(
_OnChange){
                    
_OnChange(this);
                }
            }
        }else if (
msg.Msg == CN_COMMAND){
            if(
reinterpret_cast<TWMCommand&>(msg).NotifyCode == LBN_SELCHANGE){
                if(
_LastItemIndex != ItemIndex){
                    
_LastItemIndex ItemIndex;
                    if(
_OnChange){
                        
_OnChange(this);
                    }
                }
            }
        }
        
TListBox::WndProc(msg);
    }
public:
    
__property TNotifyEvent OnVerticalScroll = {read _vScrollwrite _vScroll};
    
__property TNotifyEvent OnChange = {read _OnChangewrite _OnChange};
    
__property int CurrentIndex = {read _index};
    
__fastcall TListBoxAutoSelect(TComponentOwner);
    
__fastcall ~TListBoxAutoSelect();

__published:
};
//---------------------------------------------------------------------------
#endif 
ListBoxAutoSelect.cpp:
Código PHP:
//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "ListBoxAutoSelect.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(TListBoxAutoSelect *)
{
    new 
TListBoxAutoSelect(NULL);
}
//---------------------------------------------------------------------------

__fastcall TListBoxAutoSelect::TListBoxAutoSelect(TComponentOwner)
    : 
TListBox(Owner)
{
    
_oldWndProc this->WindowProc;
    
_LastItemIndex=-1;
}
//---------------------------------------------------------------------------

__fastcall TListBoxAutoSelect::~TListBoxAutoSelect() {
    
this->WindowProc _oldWndProc;
}
//---------------------------------------------------------------------------

namespace Listboxautoselect
{
    
void __fastcall PACKAGE Register()
    {
         
TComponentClass classes[1] = {__classid(TListBoxAutoSelect)};
         
RegisterComponents("Mis Componentes"classes0);
    }
}
//--------------------------------------------------------------------------- 
Tengo 18 ListBoxAutoSelect con lo que hago esto:
Código PHP:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    ...
    
//Asigno mi funcion al evento OnVerticalScroll de los TListBoxAutoSelect
    
TListBoxAutoSelect *LB;
    for(
int i=1;i<10;i++){
        
LB=(TListBoxAutoSelect*)GroupBoxInventarioChris->FindChildControl("ListBoxCatArmaChris" IntToStr(i));
        
LB->OnChange=OnChange;
    }
    for(
int i=1;i<10;i++){
        
LB=(TListBoxAutoSelect*)GroupBoxInventarioSheva->FindChildControl("ListBoxCatArmaSheva" IntToStr(i));
        
LB->OnChange=OnChange;
    }
    ...
}

//---------------------------------------------------------------------------

void __fastcall TForm1::OnChange(TObject *Sender)
{
    
AnsiString nombre;
    
TComboBox *CB;
    
TListBoxAutoSelect *LB;
    
TGroupBox *GB;
    
LB=static_cast<TListBoxAutoSelect*>(Sender);
    
//Como tengo 2 GroupBox (uno para cada personaje) y el contenido es igual para ambos excepto en los nombres...
    //Dependiendo del nombre del personaje uso un GroupBox o el otro
    
if(LB->Name.SubString(15,5)=="Chris")
        
GB=GroupBoxInventarioChris;
    else  if(
LB->Name.SubString(15,5)=="Sheva")
        
GB=GroupBoxInventarioSheva;

    
//Obtengo el nombre del ComboBox y obtengo un puntero a el para poder usarlo
    
nombre "ComboBox" LB->Name.SubString(11,LB->Name.Length());
    
CB=(TComboBox*)GB->FindChildControl(nombre);

    
//Relleno el ComboBox que corresponde al TListBox que cambia y asigno su Hint
    
RellenarCombo(CB,LB->ItemIndex);
    
CB->Hint CB->Items->Strings[CB->ItemIndex];
}
//--------------------------------------------------------------------------- 
Funciona perfecto pero me gustaria que me ayudaran a corregir posibles fallos que pueda tener y yo no veo debido a mi poca experiencia.
Mil gracias amigos.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Seleccion de item en combobox da error list index out of bonds jafera OOP 18 09-05-2013 10:21:54
Pregunta Combobox, selección del item sin hacer click NPIdea OOP 2 15-01-2010 07:42:14
ListBox - Scroll Kreyser Varios 2 08-06-2005 13:27:24
Scroll en un listbox kakesoft OOP 0 06-04-2005 02:40:25
Selección automática item combobox neon OOP 0 24-02-2005 13:59:22


La franja horaria es GMT +2. Ahora son las 12:29:49.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi