简体   繁体   中英

Want to add image in first two columns in ListView

I am trying to add image for first two columns in ListView. But I could not add image for second column. My code is..

            foreach ( DataRow row in _dtCategories.Rows )
            {
                ListViewItem item = new ListViewItem ( );
                for ( int i = 1 ; i < _dtCategories.Columns.Count ; i++ )
                {
                    item.ImageIndex = 0;
                    item.SubItems.Add ( " " );
                    item.ImageIndex = 1;                        
                    item.SubItems.Add ( row [ "Category" ].ToString ( ) );     
                }
                lvCategories.Items.Add ( item );
            }

So my output is.. 在此处输入图片说明

But I want to add image in first two columns.

Help me..

Try ItemTemplate:

  <!--ListView-->
        <ListView x:Name="lb_Users">
          <ListView.ItemTemplate>
            <DataTemplate>
               <Grid Width="150">
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="25"/>
                     <ColumnDefinition Width="25"/>
                     <ColumnDefinition Width="100"/>
                     <!-- other columns-->
                  </Grid.ColumnDefinitions>
                 <Image Source="mypic.png"/>
                 <Image Source="mypic2.png"/>
                 <TextBlock  Text="{Binding ....}" />
                     <!-- other columns-->
                 </Grid>
             </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM