Click here to Skip to main content
15,884,821 members

Comments by Juhi saf (Top 4 by date)

Juhi saf 28-Dec-12 3:36am View    
But, I want to bind it in the listbox.
Juhi saf 26-Dec-12 0:36am View    
I've to do it by using observable collection.
Juhi saf 26-Dec-12 0:34am View    
Thank you. But the FindString() method is not working here.
Juhi saf 26-Dec-12 0:32am View    
No, I've to use an observablecollection and bind it to the listbox. But still its not working correctly. I'll attatch the modified code here.
namespace WpfApplication1
{
public class Class1 : INotifyPropertyChanged
{

private ObservableCollection<book> b1 = new ObservableCollection<book>();
public ObservableCollection<book> B1
{
get
{
return b1;
}
set
{
b1 = value;
OnPropertyChanged("B1");
}
}


public Class1()
{
LoadBookList();

}
private void LoadBookList()
{
try
{
SqlConnection con1 = new SqlConnection("Data Source=.; Initial Catalog= test; User ID= sa; Password=nest123@!;");
con1.Open();
SqlCommand cmd1 = new SqlCommand("select Books from authorinfo where Id=(select max(Id) from authorinfo)", con1);
SqlDataReader myReader = cmd1.ExecuteReader();
while (myReader.Read())
{
string str1 = myReader["Books"].ToString();
string[] arr = str1.Split(',');
foreach (string word in arr)
{
b1.Add(new Book(word));
}
}
myReader.Close();
myReader.Dispose();
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex.Message);
}
}


public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyname)
{

if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
}
}
}
public class Book: INotifyPropertyChanged
{
private string item;
public string ITEM
{
get
{
return item;
}
set
{
item = value;
OnPropertyChanged("ITEM");
}
}

public Book(string x)
{
item = x;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyname)
{

if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
}
}
}
}