Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ JAVA and C# _ Windows Presentation Foundation Question - Linq

Posted by: ConorS May 12 2014, 08:29 AM

Hi
Here is my question
On load of a new WPF window i have the following code:
C# Code
...
using (BlueApp.MyLinqToDataDataContext db = new MyLinqToDataDataContext())
{
var allTitles = from t in db.PN_Projects
select new { t.PN_ProjectID, t.PN_ProjectTitle };
CGrid.ItemsSource = allTitles;
}
...
XAML:
<DataGrid AutoGenerateColumns="false" Name="CGrid">
<DataGrid.Columns>
<DataGridTextColumn Header="ProjectID" Binding="{Binding Path=PN_ProjectID}" Width="200"/>
<DataGridTextColumn Header="ProjectTitle" Binding="{Binding Path=PN_ProjectTitle}" Width="200"/>
</DataGrid.Columns>
</DataGrid>
Using Linq, this piece of code pushes a data into a datagrid called "CGrid".
When I run the application, the data displays fine.
Next move, the user clicks, sorrys selects a record, i want to get at the variable "PN_ProjectId" at its value.
When i use the code :
private void CGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
MessageBox.Show(CGrid.SelectedItem.ToString());
}
It spits up on screen the following:
"{ PN_ProjectID = 1, PN_ProjectTitle = My Title1"
How do i get at the individual variables? Reference them I mean.
I want to get just the "PN_ProjectID". How do i reference it?
I'm new to this.
Thanks in advance!
Regards
Conor

Posted by: ConorS May 14 2014, 05:55 AM

its ok, i was able to get an answer for this.