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. retrieving listview values

retrieving listview values

Scheduled Pinned Locked Moved C#
tutorial
8 Posts 5 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.
  • A Offline
    A Offline
    annie_bel
    wrote on last edited by
    #1

    hi! everyone!! I am using Windows application. I want to get single,single value from listview(contains two column) when I click a row. my 1st column name is 'code'and value is '123' and second column name 'desc' value 'good' If i click its return value but gives this type of value:

    listview1:{123}

    code sample:

    private void listView1_Click(object sender, EventArgs e)
    {
    ListViewItem value1 = (ListViewItem)listView1.Items[0];
    string val =Convert.ToString(value1);
    }

    please guide me, thanx and regards

    P R S 3 Replies Last reply
    0
    • A annie_bel

      hi! everyone!! I am using Windows application. I want to get single,single value from listview(contains two column) when I click a row. my 1st column name is 'code'and value is '123' and second column name 'desc' value 'good' If i click its return value but gives this type of value:

      listview1:{123}

      code sample:

      private void listView1_Click(object sender, EventArgs e)
      {
      ListViewItem value1 = (ListViewItem)listView1.Items[0];
      string val =Convert.ToString(value1);
      }

      please guide me, thanx and regards

      P Offline
      P Offline
      phil o
      wrote on last edited by
      #2

      ListViewItem item = listView1.Items[0]
      string val = item.Text;
      string desc = item.SubItems[0].Text

      A 1 Reply Last reply
      0
      • P phil o

        ListViewItem item = listView1.Items[0]
        string val = item.Text;
        string desc = item.SubItems[0].Text

        A Offline
        A Offline
        annie_bel
        wrote on last edited by
        #3

        thanx sir! but i get only code value not desc value. in desc value also contain the code value. I ask one more question. actually when i click one row its work properly. but when i click secong row it returns also previous value instead of current selected row. please guide me what can i do when i select different rows the selected rows returns value thans and best regards

        L 1 Reply Last reply
        0
        • A annie_bel

          thanx sir! but i get only code value not desc value. in desc value also contain the code value. I ask one more question. actually when i click one row its work properly. but when i click secong row it returns also previous value instead of current selected row. please guide me what can i do when i select different rows the selected rows returns value thans and best regards

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Phil pointed you to another ListView property: SubItems, which is indexable. Did you read up on it? did you perform a little experiment? BTW: when you know a column isn't text (say a number), and you want its value, then don't use Convert or ToString(), just cast! :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          1 Reply Last reply
          0
          • A annie_bel

            hi! everyone!! I am using Windows application. I want to get single,single value from listview(contains two column) when I click a row. my 1st column name is 'code'and value is '123' and second column name 'desc' value 'good' If i click its return value but gives this type of value:

            listview1:{123}

            code sample:

            private void listView1_Click(object sender, EventArgs e)
            {
            ListViewItem value1 = (ListViewItem)listView1.Items[0];
            string val =Convert.ToString(value1);
            }

            please guide me, thanx and regards

            R Offline
            R Offline
            RaviRanjanKr
            wrote on last edited by
            #5

            hey you can use given code to get value based on row on which you click.

            // Given code will get value for 1st column
            string txt = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text;

            if you need value of both second column you have to change value of SubItems to column index as

            string txt1 = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text; // For 1st column
            string txt2 = listView1.Items[listView1.FocusedItem.Index].SubItems[1].Text; // For 2nd column

            you can also use loop with SubItems for getting value.. :)

            A 1 Reply Last reply
            0
            • R RaviRanjanKr

              hey you can use given code to get value based on row on which you click.

              // Given code will get value for 1st column
              string txt = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text;

              if you need value of both second column you have to change value of SubItems to column index as

              string txt1 = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text; // For 1st column
              string txt2 = listView1.Items[listView1.FocusedItem.Index].SubItems[1].Text; // For 2nd column

              you can also use loop with SubItems for getting value.. :)

              A Offline
              A Offline
              annie_bel
              wrote on last edited by
              #6

              thank you very much! you have solved my problem.

              1 Reply Last reply
              0
              • A annie_bel

                hi! everyone!! I am using Windows application. I want to get single,single value from listview(contains two column) when I click a row. my 1st column name is 'code'and value is '123' and second column name 'desc' value 'good' If i click its return value but gives this type of value:

                listview1:{123}

                code sample:

                private void listView1_Click(object sender, EventArgs e)
                {
                ListViewItem value1 = (ListViewItem)listView1.Items[0];
                string val =Convert.ToString(value1);
                }

                please guide me, thanx and regards

                S Offline
                S Offline
                saransaki08
                wrote on last edited by
                #7

                Hi,, I have a Code in VB. Pls Convert this to c# using DeveloperFusion Website. textbox1.Text = trim(listview.SelectedItems(0).SubItems(1).Text) regards, Saran..t

                R 1 Reply Last reply
                0
                • S saransaki08

                  Hi,, I have a Code in VB. Pls Convert this to c# using DeveloperFusion Website. textbox1.Text = trim(listview.SelectedItems(0).SubItems(1).Text) regards, Saran..t

                  R Offline
                  R Offline
                  RaviRanjanKr
                  wrote on last edited by
                  #8

                  saransaki08 wrote:

                  I have a Code in VB. Pls Convert this to c# using DeveloperFusion Website.

                  I am not getting it properly I think your question is not clear. will you elaborate it for better understand for me or others. :)

                  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