Click here to Skip to main content
15,886,004 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friends,

I need relative directory and relative on my combobox. Look...

string myDir = @"c:\";
Directory.GetDirectories(myDir);

cboDocumento.SelectedItem = a.GetRelativePath();
cboDocumento.SelectedValue = a.GetAbsolutePath();
cboDocumento.DataSource = a;

how to ?
Posted
Comments
BillWoodruff 6-Oct-14 15:46pm    
Where does the value of 'a come from ... are you missing an assignment statement ?
Sergey Alexandrovich Kryukov 6-Oct-14 15:54pm    
Despite of the bad formulation, there is a deep sense in this problem. Please see my answer.
—SA
ZurdoDev 6-Oct-14 15:53pm    
What exactly is your question?
Sergey Alexandrovich Kryukov 6-Oct-14 15:54pm    
Despite of the bad formulation, there is a deep sense in this problem. Please see my answer.
—SA
Pedro Brasil 6-Oct-14 15:54pm    
GetRelativePath() and GetAbsolutePath() no exists on my code...
I need know how make this.

1 solution

You usually need to put more information to list boxes, combo boxes, etc. Not only in this case. Moreover, the data shown as strings presented in the list items should not be considered as good input data.

You should use the simple fact: the items don't have to be strings. In your case, they should not be. You need to develop a comprehensive data type used to represent the elements of the list. How? Please see my past answers:
combobox.selectedvalue shows {} in winform[^],
Windows Form ListBox Selections[^].

Also note that working with strings representing data instead of data itself is a big fallacy of many beginners these days. Try to avoid it.

—SA
 
Share this answer
 
v2
Comments
Pedro Brasil 6-Oct-14 16:00pm    
Hey,

I need bind folders of directory ... only this.
Sergey Alexandrovich Kryukov 6-Oct-14 16:11pm    
Didn't I explain the technique, how to embed any data you want? What's the problem?
—SA
CPallini 6-Oct-14 16:29pm    
5.
Sergey Alexandrovich Kryukov 6-Oct-14 16:44pm    
Thank you, Carlo.
—SA

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