Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. using listview control in smart device

using listview control in smart device

Scheduled Pinned Locked Moved C#
question
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bacem smari
    wrote on last edited by
    #1

    hi everybody, I am trying to create a multicolumn listview knowing that it is not possible to do with a listbox I have 2 questions: the first is how can i display the header of the columns? the second is how can i get data from a data base .sdf and display it on the colomuns of my listview? Thank you in advance

    W 1 Reply Last reply
    0
    • B bacem smari

      hi everybody, I am trying to create a multicolumn listview knowing that it is not possible to do with a listbox I have 2 questions: the first is how can i display the header of the columns? the second is how can i get data from a data base .sdf and display it on the colomuns of my listview? Thank you in advance

      W Offline
      W Offline
      William Winner
      wrote on last edited by
      #2

      bacem smari wrote:

      the first is how can i display the header of the columns?

      just set the ListView's View to details.

      bacem smari wrote:

      the second is how can i get data from a data base .sdf and display it on the colomuns of my listview?

      Well, you could use dataBindings (see here: Data binding a ListView[^] not sure if it will help, but it looks like it might) or you can just populate the Items yourself.

      B 2 Replies Last reply
      0
      • W William Winner

        bacem smari wrote:

        the first is how can i display the header of the columns?

        just set the ListView's View to details.

        bacem smari wrote:

        the second is how can i get data from a data base .sdf and display it on the colomuns of my listview?

        Well, you could use dataBindings (see here: Data binding a ListView[^] not sure if it will help, but it looks like it might) or you can just populate the Items yourself.

        B Offline
        B Offline
        bacem smari
        wrote on last edited by
        #3

        hi, thank you but i am trying to fill the listview with the result of a querry. Can you help me?

        1 Reply Last reply
        0
        • W William Winner

          bacem smari wrote:

          the first is how can i display the header of the columns?

          just set the ListView's View to details.

          bacem smari wrote:

          the second is how can i get data from a data base .sdf and display it on the colomuns of my listview?

          Well, you could use dataBindings (see here: Data binding a ListView[^] not sure if it will help, but it looks like it might) or you can just populate the Items yourself.

          B Offline
          B Offline
          bacem smari
          wrote on last edited by
          #4

          Hi , This is the code that i am using. It indicates no errors but my listview isn't filled with the result of the querry. Can you help me.

          private void button1_Click(object sender, EventArgs e)
          {
          string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
          SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
          SqlCeCommand command = sqlceconn.CreateCommand();
          command.CommandText = "SELECT [ID],[Magasin],[qtyonhand] from stocks where ID like @txt";
          SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
          SqlCeParameter txt = new SqlCeParameter("@txt", SqlDbType.NVarChar);
          txt.Value = textBox1.Text;
          command.Parameters.Add(txt);
          DataSet ds = new DataSet();
          adapter.Fill(ds);
          string[] str = new string[ds.Tables[0].Columns.Count];
          foreach (DataRow dr in ds.Tables[0].Rows)
          {
          for (int col = 0; col <= ds.Tables[0].Columns.Count-1; col++)
          {
          //filling the array of string
          str[col] = dr[col].ToString();
          }
          ListViewItem ii;
          ii = new ListViewItem(str);
          this.listView1.Items.Add(ii);
          }

              }
          
          W 1 Reply Last reply
          0
          • B bacem smari

            Hi , This is the code that i am using. It indicates no errors but my listview isn't filled with the result of the querry. Can you help me.

            private void button1_Click(object sender, EventArgs e)
            {
            string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
            SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
            SqlCeCommand command = sqlceconn.CreateCommand();
            command.CommandText = "SELECT [ID],[Magasin],[qtyonhand] from stocks where ID like @txt";
            SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
            SqlCeParameter txt = new SqlCeParameter("@txt", SqlDbType.NVarChar);
            txt.Value = textBox1.Text;
            command.Parameters.Add(txt);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            string[] str = new string[ds.Tables[0].Columns.Count];
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
            for (int col = 0; col <= ds.Tables[0].Columns.Count-1; col++)
            {
            //filling the array of string
            str[col] = dr[col].ToString();
            }
            ListViewItem ii;
            ii = new ListViewItem(str);
            this.listView1.Items.Add(ii);
            }

                }
            
            W Offline
            W Offline
            William Winner
            wrote on last edited by
            #5

            Well, first, glad to see that you figured out how to write the SELECT statement properly...or at least more so. But the problem is still with the SELECT...or at least that's one problem. You said, WHERE ID Like @txt. That will only return values where ID is equal to @txt. You need to add back in the '%'. Try:

            txt.Value = "%" + textBox1.Text + "%";

            If that doesn't work, then you would need to check the db. Also, you do realize that you're selecting exactly 3 columns, right? You don't need to ask the table how many columns there are because there will always be three.

            B 1 Reply Last reply
            0
            • W William Winner

              Well, first, glad to see that you figured out how to write the SELECT statement properly...or at least more so. But the problem is still with the SELECT...or at least that's one problem. You said, WHERE ID Like @txt. That will only return values where ID is equal to @txt. You need to add back in the '%'. Try:

              txt.Value = "%" + textBox1.Text + "%";

              If that doesn't work, then you would need to check the db. Also, you do realize that you're selecting exactly 3 columns, right? You don't need to ask the table how many columns there are because there will always be three.

              B Offline
              B Offline
              bacem smari
              wrote on last edited by
              #6

              thank you for the information. I think that you didn't understand my code very well. it's the datatable that i am getting the columns form. every column must appear on the listview. Can you help me? thank you.

              W 1 Reply Last reply
              0
              • B bacem smari

                thank you for the information. I think that you didn't understand my code very well. it's the datatable that i am getting the columns form. every column must appear on the listview. Can you help me? thank you.

                W Offline
                W Offline
                William Winner
                wrote on last edited by
                #7

                All that I was saying was that your SELECT statement only specified 3 columns,

                SELECT [ID],[Magasin],[qtyonhand] from stocks where ID like @txt

                If there are more columns and you want them all, then, it should just be

                SELECT * FROM ...

                B 1 Reply Last reply
                0
                • W William Winner

                  All that I was saying was that your SELECT statement only specified 3 columns,

                  SELECT [ID],[Magasin],[qtyonhand] from stocks where ID like @txt

                  If there are more columns and you want them all, then, it should just be

                  SELECT * FROM ...

                  B Offline
                  B Offline
                  bacem smari
                  wrote on last edited by
                  #8

                  thank you. I know the command. I just want these 3 columns.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups