Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a combobox, with this items :
Day
Year
Month.
How i can add the content of the combobox in a listview, but when a insert in the listview for each item to have:
1
2
3
For example, for Combobox - Day, in listview i will have: 0?

I tried this:
cb_cond.Items.Insert(0,"Day");
ListViewItem itm = new ListViewItem(cb_den.Text);
But it doesn`t work.
Posted

where to start?

First, if you could clear up what you're asking for. Are you wanting the ListView to show all of the possible day numbers (1-31) if the combobox selection is Day?

Or are you wanting something like
ComboBox ListView
Day 0
Month 1
Year 2

With your code...cb_cond.Items.Insert(0,"Day") simply adds an item of "Day" to the list with an index of 0. It doesn't equate Day with 0. It also doesn't change what is being displayed in the comboBox.

And how does changing cb_cond change anything within cb_den? because unless you've set up event handlers for an item being added to a combobox and updating cb_den, then nothing in cb_den will be changed based on cb_cond.

I think you need to start at the beginning.

What are you trying to do? What do your controls represent? What should be in those controls? How should those controls affect other controls? As it stands right now, you still haven't given us enough information to answer your question.

Also, just creating a new ListViewItem doesn't automatically add it to a ListView. You still would need to do ListView1.Items.Add(itm).
 
Share this answer
 
I have a combobox and a listview.
Combobox items :
Day
Year
Month
When i add Day, in the listview 1 must be assigned in the corresponding field of the listview.
 
Share this answer
 

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