I was looking through my grammars book by Daniel I.A.Cohem "Introduction to Computer Theory". Chapter 16 goes into depth on Pushdown Automata Theory with Chomsky Normal Form.
Theorem 21
If L is a context-free language generated by a Context -free Grammar that includes A-productions, then there is a different context=free grammar that has no A-productions that generates either the whole language L or else generates the language of all the words in L that are not A.
If you never took grammars and after reading this were like what the..? A few pages later in the end of the proof, the author throws this great metaphor to help you understand the rules. I read it again and couldn't help laughing ...and enjoying:
Those never born need never die.
First statistician:
" With all the trouble in this world, it would be better if we were never born in the first place."
Second statistician:
"Yes, but how many are so lucky? Maybe one in ten thousand."
7/16/10
7/13/10
WPF listbox.SelectedItems.Add doesn't select the items?
D'oh, I guess it's binding or ref 101, make sure you iterate through correct items list, which in this case - the bound items.
lets pretend to bind the listBox to some list of states:
listBox.ItemSource = somelistOfStates;
at some point you need to select some states programmatically that come from some other list of states (you get it from some event, for example):
foreach(var state in _statesIWantToSelect)
listBox.SelectedItems.Add (state);
Looks right, but doesn't work (does not select the states in the listBox).
Well, the reason why is that SeletedItems list does not find the state you want it to select in its list.You have to find the corresponding listbox item first then operate on that item not on some other object that doesn't have the same reference:
foreach(var state in _statesIWantToSelect)
foreach(var item in listBox.Items)
if(((State)item == state)
listBox.SelectedItems.Add(item)
12/1/09
getting started with Silverlight consuming ADO.NET Data Service
Start new Silverlight project (I am using Silverlight 3 here)
Give it a name, click OK.
Then “New Silverlight Application” host comes up.
Click OK. This will create SilverlightApplication and SilverlightApplication.Web projects in your solution.
Add Add ADO.NET Entity Data Model to your SilverlightApplication.Web project
Entry Data Model Wizard will show, select Generate from Database, choose or create your database connection, your database objects.
Note your entities name, you'll use it later in when adding it to the WebDataService as your data service type (I named mine MyDbEntities)
Add WebDataService to your SilverlightApplication.Web
In WebDataService.svc.cs add your Entity
public class WebDataService : DataService< /* TODO: put your data source class name here */ >
public class WebDataService : DataService<MYDBEntities >
also in the same file there config rights, for now to get things going I’d put “*” in both…
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
Build the SilverlightApplication.Web (so that you can reference the service in your SilverlightApplication project)
Add a Service Reference to SilverlightApplication project (click Discover if need to)
Finally, done with the setup. Lets add little code:
In SilverlightApplication project, the MainPage.xaml the page already has a Grid x:Name=”LayoutRoot”
Add a grid to it:
<data:DataGrid x:Name="dataGrid"/>
In MainPAge.xaml.cs:
Create a private field "entities", instanciate it, query, then set the dataGrid.ItemSource to what you got back…
Notes about the code below:
that's it, run it, and you should see some data in the grid.
In SilverlightApplication project, the MainPage.xaml the page already has a Grid x:Name=”LayoutRoot”
Add a grid to it:
<data:DataGrid x:Name="dataGrid"/>
In MainPAge.xaml.cs:
Create a private field "entities", instanciate it, query, then set the dataGrid.ItemSource to what you got back…
Notes about the code below:
1. entities = new MYDBEntities(new Uri("http://localhost:3431/WebDataService.svc", UriKind.RelativeOrAbsolute));
if not sure about the Uri, then right-click on WebDataService.svc > View in Browser, to copy the link …also the port number is just a random port being assigned. If you add your service to IIS, then you can use relative url.
2. if IntelliSence doesn’t come up, or you're not sure what the name of your entities are (mine is MYDBEntities), open Model.Designer.cs and look for a class that derives from ObjectContext.
3. var query = entities.users; //users is just a table in my db… user yours
Here's the code...
Here's the code...
public partial class MainPage
{
private MYDBEntities entities;
public MainPage()
{
InitializeComponent();
entities = new MYDBEntities(
new Uri("http://localhost:3431/WebDataService.svc",
UriKind.RelativeOrAbsolute));
var query = entities.users;
try
{
query.BeginExecute(c =>
{
dataGrid.ItemsSource = query.EndExecute(c).ToList();
}, query);
}
catch (Exception exception)
{
private MYDBEntities entities;
public MainPage()
{
InitializeComponent();
entities = new MYDBEntities(
new Uri("http://localhost:3431/WebDataService.svc",
UriKind.RelativeOrAbsolute));
var query = entities.users;
try
{
query.BeginExecute(c =>
{
dataGrid.ItemsSource = query.EndExecute(c).ToList();
}, query);
}
catch (Exception exception)
{
MessageBox.Show(exception.ToString());
}
}
}
}
}
}
that's it, run it, and you should see some data in the grid.
Subscribe to:
Posts (Atom)






