- Dec 8, 2013
- 1
- 0
- 0
Hello friends, i'm a new developer in Windows Phone, and i have a LongListSelector, that store data from my Azure SQL Database.
This is my C# code:
And this is my XAML:
The registers are stored in my LongListSelector - it is working fine.
Now this is my doubt: How can i read the properties for each register in my LongListSelector? For each register, i have fields such as "Id", "TypeEvent", "Hour", "Date", etc.
So, how can i read each individual value, according by the SelectedItem in LongListSelector?
For example, if i wish to see in a MessageBox the ID from a Selected Item...how can i do this in code?
I tried the following:
When i try to cast this code, this is the error i got:
*System.NullReferenceException: Object reference not set to an instance of an object. at Project.MainPage.ContextMenuRemove_Click(Object sender, EventArgs e)*
Someone can help'me, please? Thank you friends.
This is my C# code:
Code:
private async void RefreshTodoItemsToday()
{
try
{
coll = await todoTable
.Where(todoItem => todoItem.TpEvt == "today")
.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException e)
{
MessageBox.Show(e.Message, "Error loading items", MessageBoxButton.OK);
}
ListItemstoday.ItemsSource = coll;
}
And this is my XAML:
Code:
<phone:LongListSelector Name="ListItemsToday">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Name="TxtEvt" Text="{Binding Text}" TextWrapping="Wrap" Foreground="Gray" TextAlignment="Center" FontSize="30" Padding="30">
</TextBlock>
<Line X1="0" Y1="10" X2="240" Y2="10" Stroke="SkyBlue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="21"/>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
The registers are stored in my LongListSelector - it is working fine.
Now this is my doubt: How can i read the properties for each register in my LongListSelector? For each register, i have fields such as "Id", "TypeEvent", "Hour", "Date", etc.
So, how can i read each individual value, according by the SelectedItem in LongListSelector?
For example, if i wish to see in a MessageBox the ID from a Selected Item...how can i do this in code?
I tried the following:
Code:
var tmp1 = (TodoItem)ListItemsToday.SelectedItem;
var tmp2 = tmp1.Id;
MessageBox.Show(tmp2.ToString());
When i try to cast this code, this is the error i got:
*System.NullReferenceException: Object reference not set to an instance of an object. at Project.MainPage.ContextMenuRemove_Click(Object sender, EventArgs e)*
Someone can help'me, please? Thank you friends.