日期:2014-05-18  浏览次数:20943 次

读取listbox的值的问题
C# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CsvToDB
{
    public partial class CsvDataForm : Form
    {
        public CsvDataForm()
        {
            InitializeComponent();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.FileName = "";
            openFileDialog1.Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                foreach (string s in openFileDialog1.FileNames)
                {
                    listBox1.Items.Add(s);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strText;
            string strValue;
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                strText = listBox1.Items[i].text;
                strValue = listBox1.Items[i].value;
            }
            
        }
    }
}   



我上面的代码strText = listBox1.Items[i].text;为什么Items[i]点不出来text,同理下面的那个点不出来value。

------解决方案--------------------
for (int i = 0; i < listBox1.Items.Count; i++)
{
strText = listBox1.Items[i].
}
不就可以了吗?

------解决方案--------------------
this.listBox1.Items[0].ToString()
或者
this.listBox1.GetItemText(this.listBox1.Items[0].ToString());
------解决方案--------------------
C# code

foreah(dataitems di in listbox1.items) 
{ 
    strText=di.tostring(); 
}