Click here to Skip to main content
15,905,682 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# read of xls file works on Vista home preium but not XP Pro, Vista Business or 2003 server. Pin
MickCurley16-Feb-09 8:04
MickCurley16-Feb-09 8:04 
GeneralRe: C# read of xls file works on Vista home preium but not XP Pro, Vista Business or 2003 server. Pin
mid_life_crisis16-Feb-09 10:37
mid_life_crisis16-Feb-09 10:37 
GeneralRe: C# read of xls file works on Vista home preium but not XP Pro, Vista Business or 2003 server. Pin
mid_life_crisis16-Feb-09 10:48
mid_life_crisis16-Feb-09 10:48 
GeneralRe: C# read of xls file works on Vista home preium but not XP Pro, Vista Business or 2003 server. Pin
MickCurley16-Feb-09 12:48
MickCurley16-Feb-09 12:48 
GeneralRe: C# read of xls file works on Vista home preium but not XP Pro, Vista Business or 2003 server. Pin
mid_life_crisis16-Feb-09 16:14
mid_life_crisis16-Feb-09 16:14 
GeneralRe: C# read of xls file works on Vista home preium but not XP Pro, Vista Business or 2003 server. Pin
MickCurley16-Feb-09 21:16
MickCurley16-Feb-09 21:16 
GeneralRe: C# read of xls file works on Vista home preium but not XP Pro, Vista Business or 2003 server. Pin
mid_life_crisis17-Feb-09 2:26
mid_life_crisis17-Feb-09 2:26 
QuestionListBox Control - using DisplayMember and ValueMember Pin
divinyl16-Feb-09 5:34
divinyl16-Feb-09 5:34 
Hi all

I'm a dev newbie and am struggling to get my listbox to work they way i want it to. Basically, i want to be able to store the results of my stored procedure within a listbox control - so for example, if my sproc returns ServerID (primarykey) and ServerName (text column), i want this bound to my listbox control.

In my app i have created a datareader which contains the results of my query. As i loop through the datareader, i want to bind my ServerID and ServerName values to the listbox.

At the moment, I can get ServerName to display in my listbox by implementing the following:

listbox.items.add(System.Convert.ToString(reader[1]));


I then assume i need the following code to assign my query results to the displaymember and valuemember properties:

lbServerList.DisplayMember = reader[1].ToString();
lbServerList.ValueMember = reader[0].ToString();


Now i want to be able to select a server from my drop down list, and get the associated serverid. So for testing purposes, i've created a button and when i click the button, i want the serverid corresponding to the selected servername in my listbox, to be written to a textbox:

if (lbServerList.ValueMember != null)
{
     textBox.Text = listbox.ValueMember;
}


A number is indeed written to the textbox but it is a random number which doesn't link to the selected servername, and the number doesn't change no matter what server i select.

Can someone please help fill the gaps in my understanding???
I need to know first whether i'm populating the listbox correctly, and then secondly how to retrieve my serverid from it.

Thanks!

Di Confused | :confused:
AnswerRe: ListBox Control - using DisplayMember and ValueMember Pin
Xmen Real 16-Feb-09 7:45
professional Xmen Real 16-Feb-09 7:45 
QuestionDrag&Drop over RichTextBox showing wrong DropEffect Pin
mav.northwind16-Feb-09 5:18
mav.northwind16-Feb-09 5:18 
AnswerRe: Drag&Drop over RichTextBox showing wrong DropEffect Pin
Xmen Real 16-Feb-09 7:54
professional Xmen Real 16-Feb-09 7:54 
GeneralRe: Drag&Drop over RichTextBox showing wrong DropEffect Pin
mav.northwind16-Feb-09 8:41
mav.northwind16-Feb-09 8:41 
GeneralRe: Drag&Drop over RichTextBox showing wrong DropEffect Pin
Xmen Real 16-Feb-09 13:44
professional Xmen Real 16-Feb-09 13:44 
QuestionSee the execution path of my program Pin
anderslundsgard16-Feb-09 5:17
anderslundsgard16-Feb-09 5:17 
AnswerRe: See the execution path of my program Pin
Eddy Vluggen16-Feb-09 7:36
professionalEddy Vluggen16-Feb-09 7:36 
QuestionShow Repeating Data Pin
Terick16-Feb-09 4:44
Terick16-Feb-09 4:44 
QuestionDesigning Menu/tool bar system takes action depending on control displayed Pin
SilimSayo16-Feb-09 4:38
SilimSayo16-Feb-09 4:38 
QuestionTreeView-Error Pin
Udayaraju16-Feb-09 3:33
Udayaraju16-Feb-09 3:33 
AnswerRe: TreeView-Error Pin
Xmen Real 16-Feb-09 7:34
professional Xmen Real 16-Feb-09 7:34 
GeneralRe: TreeView-Error Pin
Udayaraju16-Feb-09 8:06
Udayaraju16-Feb-09 8:06 
GeneralRe: TreeView-Error Pin
Xmen Real 16-Feb-09 8:08
professional Xmen Real 16-Feb-09 8:08 
QuestionDataGridView doesn't display anything. Pin
AxiliuM16-Feb-09 3:04
AxiliuM16-Feb-09 3:04 
AnswerRe: DataGridView doesn't display anything. Pin
Calin Tatar16-Feb-09 7:21
Calin Tatar16-Feb-09 7:21 
GeneralRe: DataGridView doesn't display anything. Pin
AxiliuM16-Feb-09 10:22
AxiliuM16-Feb-09 10:22 
GeneralRe: DataGridView doesn't display anything. Pin
Calin Tatar16-Feb-09 22:05
Calin Tatar16-Feb-09 22:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.