Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a listbox1 with items ,

HelloWorld,1
HelloCode,2
HelloOlla,3

I want to do

Button1
when i will click on button1


HelloWorld will show on label1
and 1 will show on label2

I means comma will separate these two string to two labels.

How can i do it ? any suggestion pls ?

What I have tried:

C#
DataTable dataTable = new DataTable();
            dataTable.Columns.Add("Hello");
            dataTable.Columns.Add("Number");
            //dataTable.Columns.Add("Age");
            string filePath = "D:\\codepro.txt";
            StreamReader streamReader = new StreamReader(filePath);
            string[] totalData = new string[File.ReadAllLines(filePath).Length];
            totalData = streamReader.ReadLine().Split(',');
            while (!streamReader.EndOfStream)
            {
                totalData = streamReader.ReadLine().Split(',');
                dataTable.Rows.Add(totalData[0], totalData[1]);
            }


i used this code to do this on datagrid1...
Posted
Comments
[no name] 5-Nov-16 13:33pm    
Where is the code where you are splitting the text and assigning to the labels?
HeavenXodist 5-Nov-16 13:44pm    
i did it to -
1.load csv file to datagrid view (code i provided)
2.and then when i click on datagrid cell
i use this code :

label1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
label2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();

but i want to do it directly from listbox1 where my listbox data will,

HelloWorld,1
HelloWorld,2

etc and etc....

[no name] 5-Nov-16 14:30pm    
Okay so do that. That doesn't answer the question.
Karthik_Mahalingam 8-Nov-16 4:24am    
you mean selected value to be displayed ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900