Jump to content

Imagelistboxcontrol Item Data Hk.


muratboy31
 Share

Recommended Posts

verileri eklemek için:

            DataTable data = new DataTable();

            data.Columns.Add("id");
            data.Columns.Add("metin");

            data.Rows.Add("1", "resim1");
            data.Rows.Add("2", "resim2");
            data.Rows.Add("3", "resim3");

            imgListBox.DisplayMember = "metin";
            imgListBox.ValueMember = "id";
            imgListBox.DataSource = data;

value'yi okumak için:

MessageBox.Show(imgListBox.SelectedValue.ToString());

Buradaki olay, datatable'ın metin sütunundaki değerleri ekrana yazdırır, id sütunundaki değerleri ise gizli olarak her satıra depolar. istediğinizde de okuyabilirsiniz. sanırım istediğiniz bu.

Link to comment
Share on other sites

Hayır çözülmedi aynı bilgiyi görüyorum nedense !

bunun bilgisi geliyor ;

r.Name + " " + r.Surname + "\r\n" + r.Title


listBox.Items.Add(r.Name + " " + r.Surname + "\r\n" + r.Title, r.Photo);
listBox.ValueMember =Convert.ToString(r.EmployeeID);


protected void listbox_Click(object sender, EventArgs e)
        {
            ImageListBoxControl listbox = sender as ImageListBoxControl;
            if (listbox != null)
            {
                MessageBox.Show(Convert.ToString(listbox.SelectedValue));
            }

        }
Link to comment
Share on other sites

datasource olarak eklemiyorum ama, aşağıdaki gibi ekliyorum ;

var result = L_Employee.Where(a => a.OfficeID == L_OfficeID);
                        foreach (var r in result)
                        {
                            listBox.Items.Add(r.Name + " " + r.Surname + "\r\n" + r.Title, r.Photo);
                            listBox.ValueMember =Convert.ToString(r.EmployeeID);
                        }


protected void listbox_Click(object sender, EventArgs e)
        {
            ImageListBoxControl listbox = sender as ImageListBoxControl;
            if (listbox != null)
            {
                MessageBox.Show(Convert.ToString(listbox.SelectedValue));
            }

        }
Link to comment
Share on other sites

kardeş sen satır sayısı kadar işlem yapıyosun, buna gerek yok. dediğim işlemi bir kere yapacaksın tamamdır.

 

listBox.ValueMember = idlerin_bulundugu_sutun_ismi

listBox.DisplayMember = goruntulenecek_metinlerin_bulundugu_sutun_ismi

listBox.DataSource = tablo

Link to comment
Share on other sites

  • Editor

Ekteki Class ı projene ekle.

 

Sonrada burdaki gibi veri ekle.

 

using kısmına bunu ekle

using ListItemWithKey;
            Item a = new Item();
            a.strText = "ali";
            a.strValue = "1";
            listBox1.Items.Add(a);

Verilere erişirkende bu şekilde erişebilirsiniz.

var lItem = listBox1.SelectedItem as Item;
            MessageBox.Show(lItem.strValue);

 

Ek olarak class içine istediğiniz kadar deger ekleyebilirsiniz. Orada sadece strText ve strValue var. başka tiplerde degerlerde saklayabilirsiniz yani.

 

Örnek olması açısından

        public string strText;
        public string strValue;
        public int strIndex;

strIndex ekledim mesela. Tek bir item de bu kadar veri girebilirsiniz.

Edited by pairs
Link to comment
Share on other sites

aşağıdaaki hatayı verdi ;

33c7qc9.jpg

 

 

 

kullandığım kod şöyle

foreach (var r in result)
                        {
                            Item a = new Item();
                            a.strText = r.Name + " " + r.Surname + "\r\n" + r.Title;
                            a.strValue = r.EmployeeID;
                            listBox.Items.Add(a, r.Photo);                          
                        }



ImageListBoxControl listBox = sender as ImageListBoxControl;
            Point pt = new Point(e.X, e.Y);
            int index = listBox.IndexFromPoint(pt);
            if (index >= 0)
            {
                var lItem = listBox.SelectedItem as Item;
                MessageBox.Show(Convert.ToString(lItem.strText));              
            }
Link to comment
Share on other sites

  • Editor

Problem şundan kaynak point kullanıp index i alıyorsunuz fakat. benm yazdıgım kodu direk yapıştırdıgınz için. selected ıtem dakini almaa çalışıyor program. Doğal olarak öle bi veri olmadıgı için null birşeyden ben stringe çeviremem diye uyarı veriyor. 

Link to comment
Share on other sites

anladım doğru söylüyorsun, ancak ben onu point olarak yapıyorum çünkü listbox ta boş bir alana tıklandığından seçilmiş gibi gösteriyor selected item olduğunda, point olarak nasıl yaparım senin kodunu ?

 

 

aşağıdaki gibi de hata verdi aynı hatayı !

private void listBox_MouseClick(object sender, MouseEventArgs e)
        { 
            ImageListBoxControl listBox = sender as ImageListBoxControl;
            var lItem = listBox.SelectedItem as Item;
            MessageBox.Show(Convert.ToString(lItem.strValue));       
        }
Edited by muratboy31
Link to comment
Share on other sites

Null referans hatası bende niye devam ediyor anlmış değilim !

Halbuki listbox a bilgileri getiriyor ancak listbox tan birine tıkladığımda null referans hatası veriyor ...

 

bu şekilde baktığımda messagebox ta veriler geliyor

foreach (var r in result)
                        {
                            Item a = new Item();
                            a.strText = r.Name + " " + r.Surname + "\r\n" + r.Title;
                            a.strValue = r.EmployeeID;
                            listBox.Items.Add(a, r.Photo);

                            MessageBox.Show(Convert.ToString(a.strValue));                          
                        }

ancak mouse click olayında null oluyor ;

private void listBox_MouseClick(object sender, MouseEventArgs e)
        { 
            ImageListBoxControl listBox = sender as ImageListBoxControl;
            if (listBox.SelectedIndex != -1)
            {
                var lItem = listBox.SelectedItem as Item;
                MessageBox.Show(Convert.ToString(lItem.strValue));
            }
        }
Edited by muratboy31
Link to comment
Share on other sites

İndirdim kurdum ancak yine null değer dönüyor !!!

Bir türlü olmuyor;

foreach (var r in result)
                        {
                            ImageListBoxItem item = new ImageListBoxItem();
                            item.Value = r.Name + " " + r.Surname + "\r\n" + r.Title;
                            item.Tag = r.EmployeeID;

                            listBox.Items.Add(item, r.Photo);
                        }


private void listBox_MouseClick(object sender, MouseEventArgs e)
        { 
            ImageListBoxControl listBox = sender as ImageListBoxControl;
            if (listBox.SelectedIndex != -1)
            {
                string selectedTag = ((ImageListBoxItem)listBox.SelectedItem).Tag.ToString();
                MessageBox.Show(selectedTag);
            }
        }
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...