15,884,821 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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));
}
}
}
}