Click here to Skip to main content
15,898,374 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to keep data available for whole project access? Pin
Muhammad Shahid Farooq25-Sep-11 4:01
professionalMuhammad Shahid Farooq25-Sep-11 4:01 
QuestionSuperMarket Inventory Database Software Pin
Ayaz Muhammad Hanif23-Sep-11 21:40
Ayaz Muhammad Hanif23-Sep-11 21:40 
AnswerRe: SuperMarket Inventory Database Software Pin
André Kraak23-Sep-11 21:52
André Kraak23-Sep-11 21:52 
AnswerRe: SuperMarket Inventory Database Software Pin
Richard MacCutchan23-Sep-11 22:52
mveRichard MacCutchan23-Sep-11 22:52 
QuestionHow to add checkbox to the title of the groupbox in C#.Net Pin
s_akram23-Sep-11 21:22
s_akram23-Sep-11 21:22 
AnswerRe: How to add checkbox to the title of the groupbox in C#.Net Pin
BillWoodruff23-Sep-11 23:13
professionalBillWoodruff23-Sep-11 23:13 
QuestionSample Data Pin
Xarzu23-Sep-11 15:44
Xarzu23-Sep-11 15:44 
AnswerRe: Sample Data Pin
BillWoodruff23-Sep-11 23:34
professionalBillWoodruff23-Sep-11 23:34 
0. 'as is' the code shown here will not work: your definition of 'GetSampleData' is supposed to return an ObservableCollection<product>, and it does not.

1. Why not make the Class 'static' as well ? As the code is now, the Class will have to be instantiated with 'new'

2. please explain more clearly exactly what you mean by "get the sample data on the fly from outside the class." You mean from a database ?

Would something like this work for you:
XML
public static class SampleData
{
  public static ObservableCollection<Product> teams = new ObservableCollection<Product>();

  public static void GetSampleData()
  {
    // code here to access a database or whatever to fill the teams<Product> collection
  }
}

In this type of access-model, once you have called 'GetSampleData,' and filled the 'teams' global static variable, you can access it from anywhere in your project by: SampleData.teams

Note: since you are using ObservableCollection, my guess is your intent is to make use of PropertyChanged and/or CollectionChanged facilties: I have not thought through the implications of making a static ObservableCollection.

There's a great new article here on CP about ObservableCollection I recommend you see: Enhanced ObservableCollection with ability to delay or disable notifications[^]

best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"

Questionhelp to deal with graph data structure Pin
Mahdi_mnj23-Sep-11 12:10
Mahdi_mnj23-Sep-11 12:10 
AnswerRe: help to deal with graph data structure Pin
SledgeHammer0123-Sep-11 13:53
SledgeHammer0123-Sep-11 13:53 
AnswerRe: help to deal with graph data structure Pin
BillWoodruff24-Sep-11 0:04
professionalBillWoodruff24-Sep-11 0:04 
AnswerRe: help to deal with graph data structure Pin
BobJanova26-Sep-11 1:33
BobJanova26-Sep-11 1:33 
GeneralRe: help to deal with graph data structure Pin
Mahdi_mnj26-Sep-11 4:32
Mahdi_mnj26-Sep-11 4:32 
GeneralRe: help to deal with graph data structure Pin
BobJanova26-Sep-11 5:54
BobJanova26-Sep-11 5:54 
GeneralRe: help to deal with graph data structure Pin
Mahdi_mnj26-Sep-11 4:50
Mahdi_mnj26-Sep-11 4:50 
QuestionVersioning the hard way Pin
lukeer23-Sep-11 4:43
lukeer23-Sep-11 4:43 
AnswerRe: Versioning the hard way Pin
André Kraak23-Sep-11 23:03
André Kraak23-Sep-11 23:03 
GeneralRe: Versioning the hard way Pin
lukeer25-Sep-11 20:40
lukeer25-Sep-11 20:40 
AnswerRe: Versioning the hard way Pin
BobJanova26-Sep-11 2:02
BobJanova26-Sep-11 2:02 
QuestionC sharp GUI help needed! Pin
memed0922-Sep-11 20:42
memed0922-Sep-11 20:42 
AnswerRe: C sharp GUI help needed! Pin
memed0922-Sep-11 20:46
memed0922-Sep-11 20:46 
AnswerRe: C sharp GUI help needed! Pin
ScottM122-Sep-11 20:57
ScottM122-Sep-11 20:57 
GeneralRe: C sharp GUI help needed! Pin
memed0922-Sep-11 21:03
memed0922-Sep-11 21:03 
AnswerRe: C sharp GUI help needed! Pin
DaveAuld22-Sep-11 21:53
professionalDaveAuld22-Sep-11 21:53 
AnswerRe: C sharp GUI help needed! Pin
BillWoodruff23-Sep-11 0:43
professionalBillWoodruff23-Sep-11 0:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.