Click here to Skip to main content
15,917,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,I have a wpf application and inside that i have a listview . I used a for loop to generate the items of my listview but my problem is whereas my item.count is 17,I just can get value for rows 0 1 2 and other rows are null,I have to mention that I can display information for all rows inside my listview in design mode(names,photos,...) but in code behind i get null for rows 3 and after,can someone guide me what is my problem where I am wrong?thank you so much.
Posted

Your code is broken. Hard to say more without seeing it.
 
Share this answer
 
Tanx Christian for your reply.let me post some parts of my code:

//here is the part when i fill up my listview:
DataSet da = new DataSet();
connRead.Fill(da);
listView.DataContext = da.Tables[0];

//this part is for when i want to get my items value:
ListViewItem container = null;
for (int i = 0; i < listView.Items.Count;i++ )
{

container = listView.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem;

if (container != null)//here for i = 3 and onward i get null value
{
...
}


this is my xaml part:

XML
<ListView x:Name="listView" Height="202" ItemsSource="{Binding}"  SelectionChanged="listView_SelectionChanged"  HorizontalAlignment="Left" Margin="20,84,0,0" VerticalAlignment="Top" Width="435" IsSynchronizedWithCurrentItem="{x:Null}" DataContext="{Binding}">
               <ListView.ItemTemplate>
               <DataTemplate>
                <Grid x:Name="grid">
               <Grid.RowDefinitions>
                   <RowDefinition Height="Auto"/>
                   <RowDefinition Height="Auto"/>
                   <RowDefinition Height="50"/>
                   <RowDefinition Height="Auto"/>
                   <RowDefinition Height="Auto"/>
               </Grid.RowDefinitions>
               <Grid.ColumnDefinitions>
                   <ColumnDefinition/>
                   <ColumnDefinition/>
                   <ColumnDefinition/>
                   <ColumnDefinition/>
               </Grid.ColumnDefinitions>
                     <Image x:Name="image1" Width="70" Height="110" Grid.Row="1" Grid.Column="1"  Source="{Binding PhotoName}"></Image>
                     <Label x:Name="email" Grid.Row="0" Grid.Column="2"  Content="{Binding Email}"></Label>
                     <Label x:Name="name" Grid.Row="1" Grid.Column="2" Content="{Binding Name}"></Label>
                     <CheckBox x:Name="chB" Grid.Row="0" Grid.Column="0" ></CheckBox>
                </Grid>
               </DataTemplate>
           </ListView.ItemTemplate>
       </ListView>
 
Share this answer
 
v2
Comments
Christian Graus 1-Sep-10 1:56am    
please don't push 'answer' to post questions.

container = listView.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem;

This is very convoluted. How about 'foreach(ListViewItem item in listView.Items) ?
BaharDev 1-Sep-10 2:16am    
sorry for my improper posting because this is my first time that im posting a question.I tried it out but this error was generated : Unable to cast object of type 'System.Data.DataRowView' to type 'System.Windows.Controls.ListViewItem'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900