views:

38

answers:

1

I am using VS2010 for c#. I have some data there in a table

Scores(team1,team2,battingteam,bowlingteam,score) I am using bindingSource to bind it with my listBox. The problem is that i can show only one member in DisplayMember property of listbox (e.g. team1 or team2 only). I want to do something like

team1 + " vs " + team2 + ": " + battingteam +" Score: " + score

how to do that?

+1  A: 

I don't know in which data type you have your data ... but for example if you have them in DataTable returned from db you can create List<string> object and iterate datatable rows and create items in list object with formatting data as you want and by end bind list object to your listbox directly as below

    List<string> teams = new List<string>();
    foreach (DataRow dataRow in teamsDataTable.Rows)
    {
        teams.Add(dataRow["team1"].ToString() + " vs " + dataRow["team2"].ToString() + ": " + dataRow["battingteam"].ToString() + " Score: " + dataRow["score"].ToString());
    }
listBox1.DataSource = teams;
Space Cracker
The data is in DataSet that contains many DataTables. Each dataTable has a tableAdapter that i use to get and fill data
LifeH2O
I am going to try that method
LifeH2O
you can use the above method but by replacing teamsDataTable.Rows by dataset.Table[X].Rows
Space Cracker