Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:28:24+00:00 2026-06-12T22:28:24+00:00

in my app there is gridview of my custom class. I am using custom

  • 0

in my app there is gridview of my custom class. I am using custom data template and values are bound from SQLite. Now when user launch the app, the certain items (NOT SINGLE) should be pre-selected in gridview/listview. Gridview/listview allows multiple selection. How can I achieve this with SelectedItem property ?

UPDATE : I have followed this, it doesn’t work for me. Returns 0 selections.

UPDATE 2 : I have posted the code

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    using (var db = new SQLite.SQLiteConnection(dbpath))
    {
        lvTags.ItemsSource = db.Table<Database.Tag>();  //lvTags is listview

        if (MyList.Count > 0) //MyList is the static list of class "Database.Tag"
        {
            foreach (var item in MyList)
                foreach (var lvitem in lvTags.Items)
                    if (lvitem.Equals(item))
                        lvTags.SelectedItems.Add(lvitem);
        }
    }
}

UPDATE 3:

public override bool Equals(object obj)
{
    Tag tag = obj as Tag;
    if (this.TagID == tag.TagID && this.TagName == tag.TagName)
        return true;
    else
        return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:28:26+00:00Added an answer on June 12, 2026 at 10:28 pm

    Finally got answer from MSDN. Thanks ForInfo

    XAML page

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <ListView x:Name="listView" SelectionMode="Multiple">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBox Text="{Binding ID}" Margin="0,0,5,0"/>
                        <TextBox Text="{Binding Title}"/>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
    

    C#

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            LoadData();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        ObservableCollection<KiwiItem> sourceColl;
        IList<KiwiItem> selectionList;
        public void LoadData()
        {
            var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
    
            // Exec (1)
            using (var db = new SQLite.SQLiteConnection(dbPath))
            {
                db.DropTable<KiwiItem>();
                db.CreateTable<KiwiItem>();
                db.RunInTransaction(() =>
                {
                    db.Insert(new KiwiItem() { ID = 1, Title = "MyTitle1" });
                    db.Insert(new KiwiItem() { ID = 2, Title = "MyTitle2" });
                    db.Insert(new KiwiItem() { ID = 3, Title = "MyTitle3" });
                    db.Insert(new KiwiItem() { ID = 4, Title = "MyTitle4" });
                });
                this.sourceColl = new ObservableCollection<KiwiItem>();
                this.selectionList = new List<KiwiItem>();
                // Query the db. In practice, fill the sourceColl according to your business scenario
                foreach (KiwiItem item in db.Table<KiwiItem>())
                {
                    this.sourceColl.Add(item);
                    if (item.ID == 2 || item.ID == 4)
                        this.selectionList.Add(item);
                }
            }
    
            // Exec (2)
            this.listView.ItemsSource = this.sourceColl;
            foreach (KiwiItem item in this.selectionList)
                this.listView.SelectedItems.Add(item);
        }
    }
    public class KiwiItem
    {
        [SQLite.AutoIncrement, SQLite.PrimaryKey]
        public int ID { get; set; }
        public string Title { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app there is a button, user just click it then the latest
Hello i am using SocializeActionBar for my app there i have multiple links. I
When hosting WPF user controls within a WinForms MDI app there is a drawing
There is a small advancement in my app, developing using ASP.Net and C# on
I've built an ASP.NET web app to view data from the Windows Event Log
I have developed an app in which I display data in Gridview . All
In every iOS app there is an App Delegate class, meaning one of the
In my app there is a webview with an advertising html page in it.
In my app there is requirement that..I have 6 buttons in a nib, when
In my app there is the view says googleBtn. If i press on it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.