Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

c# - Remove focuse from listview items

[es] :: .NET :: c# - Remove focuse from listview items

[ Pregleda: 1390 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Cal Lightman

Član broj: 317851
Poruke: 88
*.dynamic.sbb.rs.



+13 Profil

icon c# - Remove focuse from listview items22.11.2013. u 01:22 - pre 125 meseci
Pozdrav svima.

Stvar je sledeća:



1) Kada se u txtSearch ukuca neki kontakt, u ovom slučaju 4 i stisne dugme (lupa) pored, izvršava se sledeće:

Code (csharp):
private void toolStripButton1_Click_1(object sender, System.EventArgs e)
        {
            txtSearch_TextChanged();
        }
 

... gde je txtSearch_TextChanged():

Code (csharp):
void txtSearch_TextChanged()
        {
            foreach (ListViewItem item in listView1.Items)
            {
                //Selected = true, won't show until the listview has focus, but setting it to true puts it in the
                //SelectedItems collection.
                if (item.Text.ToLower().StartsWith(txtSearch.Text.ToLower()))
                {
                    item.Selected = true;
                    item.BackColor = Color.CornflowerBlue;
                    item.ForeColor = Color.White;
                }
                else
                {
                    item.Selected = false;
                    item.BackColor = Color.White;
                    item.ForeColor = Color.Black;
                }

            }
            //When the selection is narrowed to one the user can stop typing
            if (listView1.SelectedItems.Count == 1)
            {
                listView1.Focus();                  
            }

        }
 

Dakle, problem je što taj koji je pronađen ostaje selektovan, tj. fokusiran (?)

Probao sam na razne načine da skinem focus, između ostalog i ovako, ali nikako ne uspevam:

Code (csharp):
void Unfocus()
        {
            if (listView1.SelectedItems.Count != 0)
            {
                listView1.SelectedItems[0].Selected = false;
            }
            if (listView1.FocusedItem != null)
            {
                listView1.FocusedItem.Focused = false;
            }
        }
 


2) Takođe, hteo bih da kada nađe kontakt(e) ostavi samo njih u listi, znači u ovom slučaju da bude ovako:



da ne kačim sad silne neuspešne pokušaje da to napravim... zapeo sam kod

Code (csharp):
listView1.Clear();

Ne znam kako da posle dodam u ListView taj Item koji je bio tražen, tj. fokusiran.
 
Odgovor na temu

Cal Lightman

Član broj: 317851
Poruke: 88
*.dynamic.sbb.rs.



+13 Profil

icon Re: c# - Remove focuse from listview items23.11.2013. u 23:55 - pre 125 meseci
1) Rešeno - problem je bio u tome što se zametnula linija koja kaže da se selektovani kontakt oboji drugom bojom.

2) Anyone?
 
Odgovor na temu

Burgos
Nemanja Borić
Amazon Web Services
Berlin

Član broj: 12484
Poruke: 1947
212.178.232.*

Sajt: stackoverflow.com/users/1..


+480 Profil

icon Re: c# - Remove focuse from listview items24.11.2013. u 09:17 - pre 125 meseci
Nemoj sve da ih brišeš, već obriši one prilikom pretrage - ovo moraš da uradiš jer ne pretražuješ bazu podataka, već listu.

Code:
foreach (ListViewItem item in listView1.Items)
            {
                //Selected = true, won't show until the listview has focus, but setting it to true puts it in the 
                //SelectedItems collection.
                if (item.Text.ToLower().StartsWith(txtSearch.Text.ToLower()))
                {
                    item.Selected = true;
                    item.BackColor = Color.CornflowerBlue;
                    item.ForeColor = Color.White;
                }
                else
                {
                    listView1.Items.Remove(item);
                }

            }
 
Odgovor na temu

Cal Lightman

Član broj: 317851
Poruke: 88
*.dynamic.sbb.rs.



+13 Profil

icon Re: c# - Remove focuse from listview items24.11.2013. u 15:47 - pre 125 meseci
@Burgos:

Hvala ti mnogo, uspeo sam.
 
Odgovor na temu

[es] :: .NET :: c# - Remove focuse from listview items

[ Pregleda: 1390 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.