muratboy31 Posted October 9, 2015 Share Posted October 9, 2015 Merhaba, Veri tabnından çektiğim bir ID yi listbox item de bir yere görünmicek şekilde koymam lazım, listbox item ile ilgili güncelleme yapıldığında veritabanında o ID yi bulup kullanmak için, nasıl bir yol izlemeliyim acaba ? Teşekkürler Quote Link to comment Share on other sites More sharing options...
KintaRo Posted October 9, 2015 Share Posted October 9, 2015 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. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 9, 2015 Author Share Posted October 9, 2015 Evet aslında bu ancak şu şekilde denediğimde aynı bilgileri alıyorum ; listBox.Items.Add(r.Name + " " + r.Surname + "\r\n" + r.Title, r.Photo); listBox.ValueMember = Convert.ToString(r.EmployeeID); Quote Link to comment Share on other sites More sharing options...
KintaRo Posted October 9, 2015 Share Posted October 9, 2015 yani sorun çözüldü mü çözülmedi mi? anlayamadım. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 9, 2015 Author Share Posted October 9, 2015 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)); } } Quote Link to comment Share on other sites More sharing options...
KintaRo Posted October 9, 2015 Share Posted October 9, 2015 imgListBox.DisplayMember = "metin"; imgListBox.ValueMember = "id"; imgListBox.DataSource = data; bu şekilde doğru sütunları atayıp, datasource olarak tablonuzu belirttiniz mi Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 9, 2015 Author Share Posted October 9, 2015 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)); } } Quote Link to comment Share on other sites More sharing options...
KintaRo Posted October 9, 2015 Share Posted October 9, 2015 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 Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 9, 2015 Author Share Posted October 9, 2015 metnin yanında icon var itemlerde, datasource kullandığımda bunu ekleyemedim. Quote Link to comment Share on other sites More sharing options...
KintaRo Posted October 9, 2015 Share Posted October 9, 2015 valla itemlerde Tag gibi ekstra bir alan olmadığı için başka bir çözüm gelmiyor aklıma. Imageleri listeyi yazdırdıktan sonra bir for döngüsü ile ekletebilirsiniz bence. Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 9, 2015 Editor Share Posted October 9, 2015 (edited) 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 October 9, 2015 by pairs Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 9, 2015 Author Share Posted October 9, 2015 aşağıdaaki hatayı verdi ; 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)); } Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 9, 2015 Editor Share Posted October 9, 2015 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. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 9, 2015 Author Share Posted October 9, 2015 (edited) 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 October 9, 2015 by muratboy31 Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 9, 2015 Editor Share Posted October 9, 2015 if (listboxname.SelectedIndex == -1) Bu şekilde eğer dogru bir seçim yapmadıysa uyarı verdirebilirsiniz. Yani point ile almak zoruna değilsiniz. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 9, 2015 Author Share Posted October 9, 2015 (edited) 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 October 9, 2015 by muratboy31 Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 9, 2015 Editor Share Posted October 9, 2015 Proje dosyanızı atarmısınız. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 9, 2015 Author Share Posted October 9, 2015 team versem daha kolay olurmu, veri tabanı tablolarıda hazırda çünkü bende... Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 9, 2015 Editor Share Posted October 9, 2015 Yarın bağlanayım o zaman. Yada siz gönderin özelden team ID ve şifreyi. Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 10, 2015 Editor Share Posted October 10, 2015 Devexpress in son sürümünü kurdum test etmek için. Sanırım yeni sürümlerde tag ve description özelliği getirmişler. Eski sürümleri bilmiorum. http://prntscr.com/8pqtat bu resimdeki gibi özellik gelmiş ve istediğiniz işinizi çözecektir. Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 10, 2015 Author Share Posted October 10, 2015 Tam olarak hangi versiyon sende kurulu olan ? Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 10, 2015 Editor Share Posted October 10, 2015 15.1.7 var şuan az önce sitesinden indirdim zaten trial Quote Link to comment Share on other sites More sharing options...
muratboy31 Posted October 12, 2015 Author Share Posted October 12, 2015 İ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); } } Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted October 12, 2015 Editor Share Posted October 12, 2015 Bağlantı atarsanız baglanayım. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.