Sauvegarde listBox

anubis52100 Messages postés 44 Date d'inscription vendredi 18 mars 2005 Statut Membre Dernière intervention 22 janvier 2007 - 1 avril 2005 à 10:17
cs_mayti Messages postés 36 Date d'inscription samedi 2 octobre 2004 Statut Membre Dernière intervention 11 juin 2005 - 1 avril 2005 à 15:58
slt

voile j'ai ouver un fichier txt dans une listBox.
ensuite je suprime un nom dans la listBox ( la listBox contient des nom)
MOn prb c ke je voudrai ke le nom suprimer dans ma listBox soit suprimer osi
dans mon fichier txt

Et je voudrai aussi ke se soi l'élève sélectioné ki soit suprimer.

BOOL CSupresionEleveDlg::OnInitDialog()
{
CDialog::OnInitDialog();


//m_TableauPersonnes.SetSize(0,100);


//int TabStop[] = {71,143};
// ((CListBox *)GetDlgItem(IDC_LIST1_SUPRESION_ELEVE))->SetTabStops(2,TabStop);

static char Texte[1024];
FILE * Fichier = fopen("eleve.txt", "r");
CListBox * pListBox = (CListBox *)GetDlgItem(IDC_LIST1_SUPRESION_ELEVE);


pListBox->SendMessage(IDC_LIST1_SUPRESION_ELEVE, LB_RESETCONTENT, 0);

while(fgets(Texte, 100, Fichier))
{
pListBox->SendMessage(IDC_LIST1_SUPRESION_ELEVE, LB_ADDSTRING, (LPARAM)(LPCTSTR) Texte);
pListBox->AddString(Texte);
UpdateWindow();
}
fclose(Fichier);

return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

void CSupresionEleveDlg::OnButton1SupEleve()
{
CListBox * pListBox = (CListBox *)GetDlgItem(IDC_LIST1_SUPRESION_ELEVE);
int i;
i=pListBox->GetCount( );
pListBox->DeleteString( i-1 ) ;

???????
}

merci!

2 réponses

anubis52100 Messages postés 44 Date d'inscription vendredi 18 mars 2005 Statut Membre Dernière intervention 22 janvier 2007
1 avril 2005 à 11:46
j'ai essayer une méthome mais le prb ces ke que je suprimer la premier foi un élève sa marche nikel mais apré g un 0 fin ki sajoute avant mn second nom et du coup je pe pu rien suprimer.

mon code

void CSupresionEleveDlg::OnButton1SupEleve()
{
// TODO: Add your control notification handler code here
CListBox * pListBox = (CListBox *)GetDlgItem(IDC_LIST1_SUPRESION_ELEVE);


// LPCTSTR texte;
int i;
i=pListBox->GetCount( );
pListBox->DeleteString( i-1 ) ;






CFile FichierAnnuaire;
FichierAnnuaire.Open("eleve.txt", CFile::modeReadWrite );
CArchive MonArchive(& FichierAnnuaire, CArchive::store );


m_ListePersonnes.Serialize(MonArchive);

MonArchive.Close();
FichierAnnuaire.Close();

}

///////////Cpersonne
CPersonne::CPersonne(CString strNom)
{
m_strNom = strNom;
}


CPersonne::~CPersonne()
{


}
CString CPersonne::GetNom()
{
return m_strNom;
}
void CPersonne::Serialize(CArchive & MonArchive)
{
//Protection
CObject::Serialize(MonArchive);

//si j'enregistre
if(MonArchive.IsStoring())
//Ecriture sur le disque
MonArchive <<m_strNom ;
else
//Lecture sur le disque
MonArchive >> m_strNom;
}

merci maider svp slt!
0
cs_mayti Messages postés 36 Date d'inscription samedi 2 octobre 2004 Statut Membre Dernière intervention 11 juin 2005
1 avril 2005 à 15:58
Hum sans MFC:



int DeleteListItem(HWND Hwnd, DWORD ListID)

{

int itemsel;

itemsel = GetListSelected(Hwnd,ListID);

if(itemsel >=0 )

SendDlgItemMessage(Hwnd,ListID,LB_DELETESTRING,itemsel,0);

else

MessageBox(NULL,"Error: No item selected.","Error",MB_ICONEXCLAMATION);

}



int GetListSelected(HWND Hwnd, DWORD ListID)

{

int sel=0;

sel = SendDlgItemMessage(Hwnd, ListID, LB_GETCURSEL, 0, 0);

if(sel == LB_ERR) // Rien de séléctioné.

return -1;

else

return sel;

}



---------------------------------------------------------------------------------

Sinon pour effacer aussi le nom dans le txt suffit de sauvegarder la liste dans le .txt
0
Rejoignez-nous