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. ListView Add Data

ListView Add Data

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 3 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.
  • M Offline
    M Offline
    mfcuser
    wrote on last edited by
    #1

    I have my listview where I plot some data. I want to show the data to a table, so I am using listview. I do have problem using the subitem function. I can show my x data to the fist column, however I am having problem to show the y data to the next column here is my code private void button1_Click(object sender, System.EventArgs e) { double[] dData = new double[200]; double[] dData2 = new double[200]; for(int i=0;i<200;i++) { dData[i] = Math.Sin(0.09*i); dData2[i] = Math.Cos(0.1*i); listView1.Items.Add(i.ToString()); //show the x data to the fist colunm however I couldn't find a way to show the sine and the cosine to the next colunm } waveformPlot1.PlotY(dData); waveformPlot2.PlotY(dData2); } so my output looks like that col 1 col 2 col 3 0 blank blakk 1 blank blank show how can I show subitem in the listview

    A 1 Reply Last reply
    0
    • M mfcuser

      I have my listview where I plot some data. I want to show the data to a table, so I am using listview. I do have problem using the subitem function. I can show my x data to the fist column, however I am having problem to show the y data to the next column here is my code private void button1_Click(object sender, System.EventArgs e) { double[] dData = new double[200]; double[] dData2 = new double[200]; for(int i=0;i<200;i++) { dData[i] = Math.Sin(0.09*i); dData2[i] = Math.Cos(0.1*i); listView1.Items.Add(i.ToString()); //show the x data to the fist colunm however I couldn't find a way to show the sine and the cosine to the next colunm } waveformPlot1.PlotY(dData); waveformPlot2.PlotY(dData2); } so my output looks like that col 1 col 2 col 3 0 blank blakk 1 blank blank show how can I show subitem in the listview

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      You have to use ListViewItem Class. First you need to add the columns to ListViewItem and add the ListViewItem to the ListView Control.
      Try this...
      private void button1_Click(object sender, System.EventArgs e)
      {
      double[] dData = new double[200];
      double[] dData2 = new double[200];
      ListViewItem newItem = null;
      for(int i=0;i<200;i++)
      {
      dData[i] = Math.Sin(0.09*i);
      dData2[i] = Math.Cos(0.1*i);
      newItem= new ListViewItem();
      newItem.SubItems.Add(i.ToString());
      newItem.SubItems.Add(dData[i].ToString());
      newItem.SubItems.Add(dData2[i].ToString());
      this.listView1.Items.Add(newItem);
      } Cheers, jagan

      M 1 Reply Last reply
      0
      • A Anonymous

        You have to use ListViewItem Class. First you need to add the columns to ListViewItem and add the ListViewItem to the ListView Control.
        Try this...
        private void button1_Click(object sender, System.EventArgs e)
        {
        double[] dData = new double[200];
        double[] dData2 = new double[200];
        ListViewItem newItem = null;
        for(int i=0;i<200;i++)
        {
        dData[i] = Math.Sin(0.09*i);
        dData2[i] = Math.Cos(0.1*i);
        newItem= new ListViewItem();
        newItem.SubItems.Add(i.ToString());
        newItem.SubItems.Add(dData[i].ToString());
        newItem.SubItems.Add(dData2[i].ToString());
        this.listView1.Items.Add(newItem);
        } Cheers, jagan

        M Offline
        M Offline
        mfcuser
        wrote on last edited by
        #3

        I have tried it over and got it right; this was the only line that I missed this.listView1.Items.Add(newItem);

        M 1 Reply Last reply
        0
        • M mfcuser

          I have tried it over and got it right; this was the only line that I missed this.listView1.Items.Add(newItem);

          M Offline
          M Offline
          mfcuser
          wrote on last edited by
          #4

          also the first column is blank. The index which is i doesn't show on the fist column

          J 1 Reply Last reply
          0
          • M mfcuser

            also the first column is blank. The index which is i doesn't show on the fist column

            J Offline
            J Offline
            jagan79
            wrote on last edited by
            #5

            Hmmmm thats interesting... Anyway this is not right way but try this.. private void button1_Click(object sender, System.EventArgs e) { double[] dData = new double[200]; double[] dData2 = new double[200]; ListViewItem newItem = null; for(int i=0;i<200;i++) { dData[i] = Math.Sin(0.09*i); dData2[i] = Math.Cos(0.1*i); newItem= new ListViewItem(i.ToString()); newItem.SubItems[1].Text = dData[i].ToString(); newItem.SubItems[2].Text = dData2[i].ToString(); newItem.SubItems.Add(dData[i].ToString()); newItem.SubItems.Add(dData2[i].ToString()); this.listView1.Items.Add(newItem); } Cheers, Jagan

            M 1 Reply Last reply
            0
            • J jagan79

              Hmmmm thats interesting... Anyway this is not right way but try this.. private void button1_Click(object sender, System.EventArgs e) { double[] dData = new double[200]; double[] dData2 = new double[200]; ListViewItem newItem = null; for(int i=0;i<200;i++) { dData[i] = Math.Sin(0.09*i); dData2[i] = Math.Cos(0.1*i); newItem= new ListViewItem(i.ToString()); newItem.SubItems[1].Text = dData[i].ToString(); newItem.SubItems[2].Text = dData2[i].ToString(); newItem.SubItems.Add(dData[i].ToString()); newItem.SubItems.Add(dData2[i].ToString()); this.listView1.Items.Add(newItem); } Cheers, Jagan

              M Offline
              M Offline
              mfcuser
              wrote on last edited by
              #6

              I received the following error on that line newItem.SubItems[1].Text = dData[i].ToString(); An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll Additional information: Specified argument was out of the range of valid values.

              M 1 Reply Last reply
              0
              • M mfcuser

                I received the following error on that line newItem.SubItems[1].Text = dData[i].ToString(); An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll Additional information: Specified argument was out of the range of valid values.

                M Offline
                M Offline
                mfcuser
                wrote on last edited by
                #7

                However by removing the two lines, the rest of the code works fine. This is the one that works private void button1_Click(object sender, System.EventArgs e) { double[] dData = new double[200]; double[] dData2 = new double[200]; ListViewItem newItem = null; for(int i=0;i<200;i++) { dData[i] = Math.Sin(0.09*i); dData2[i] = Math.Cos(0.1*i); newItem= new ListViewItem(i.ToString()); newItem.SubItems.Add(dData[i].ToString()); newItem.SubItems.Add(dData2[i].ToString()); this.listView1.Items.Add(newItem); } waveformPlot1.PlotY(dData); waveformPlot2.PlotY(dData2); }

                J 1 Reply Last reply
                0
                • M mfcuser

                  However by removing the two lines, the rest of the code works fine. This is the one that works private void button1_Click(object sender, System.EventArgs e) { double[] dData = new double[200]; double[] dData2 = new double[200]; ListViewItem newItem = null; for(int i=0;i<200;i++) { dData[i] = Math.Sin(0.09*i); dData2[i] = Math.Cos(0.1*i); newItem= new ListViewItem(i.ToString()); newItem.SubItems.Add(dData[i].ToString()); newItem.SubItems.Add(dData2[i].ToString()); this.listView1.Items.Add(newItem); } waveformPlot1.PlotY(dData); waveformPlot2.PlotY(dData2); }

                  J Offline
                  J Offline
                  jagan79
                  wrote on last edited by
                  #8

                  Actually i had commented those two lines . However while posting i had mistakenly uncommented those :doh:. Sorry for the confusion.:(

                  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