Click here to Skip to main content
15,921,382 members
Home / Discussions / C#
   

C#

 
QuestionParse text file and load data to text boxes Pin
Saamir10-Jun-06 4:57
Saamir10-Jun-06 4:57 
AnswerRe: Parse text file and load data to text boxes Pin
Nafiseh Salmani10-Jun-06 22:39
Nafiseh Salmani10-Jun-06 22:39 
GeneralRe: Parse text file and load data to text boxes [modified] Pin
Saamir11-Jun-06 4:35
Saamir11-Jun-06 4:35 
Questiontray application pocket pc Pin
NikoTanghe10-Jun-06 3:58
NikoTanghe10-Jun-06 3:58 
QuestionDataGridView.SelectedRows Pin
peshawarcoder10-Jun-06 3:38
peshawarcoder10-Jun-06 3:38 
QuestionDining Philosopher Problem Pin
jazi-b10-Jun-06 3:26
jazi-b10-Jun-06 3:26 
QuestionListBox and DrawItem event Pin
Nafiseh Salmani10-Jun-06 2:43
Nafiseh Salmani10-Jun-06 2:43 
AnswerRe: ListBox and DrawItem event Pin
Ed.Poore10-Jun-06 3:30
Ed.Poore10-Jun-06 3:30 
nafiseh_salmani wrote:
e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(),


This is the problem, you're getting the ToString of the DataRow class.  If you want to draw the DisplayMember then you'll need to use reflection to get the value of the property given in DisplayMember, you can then use that as the string.

If DisplayMember will always be a the value from a column of the row then you can use that as the key for the columns.  I.e. cast the ListBox.Items[e.Index] to a DataRow and then retrieve the value from the columns.

So if DisplayName is the column name:
ListBox tempListBox = (ListBox)sender;
DataRow dataRow = (DataRow)tempListBox.Items[e.Index];
e.Graphics.DrawString(dataRow.Columns[tempListBox.DisplayMember].Value, ...);
I'd suggest optimising the code as well because even you're snippet has a lot of boxing and unboxing going on and if the list contains more than a few items then you're going to take some serious performance penalties.



You know you're a Land Rover owner when the best route from point A to point B is through the mud.

Ed
QuestionRe: ListBox and DrawItem event Pin
Nafiseh Salmani10-Jun-06 22:18
Nafiseh Salmani10-Jun-06 22:18 
AnswerRe: ListBox and DrawItem event Pin
Ed.Poore10-Jun-06 23:21
Ed.Poore10-Jun-06 23:21 
QuestionPDA start up page Pin
AhsanS10-Jun-06 1:13
AhsanS10-Jun-06 1:13 
Questionhow to select all table names Pin
cellardoor071610-Jun-06 0:32
cellardoor071610-Jun-06 0:32 
AnswerRe: how to select all table names Pin
albCode10-Jun-06 0:46
albCode10-Jun-06 0:46 
GeneralRe: how to select all table names Pin
cellardoor071610-Jun-06 0:49
cellardoor071610-Jun-06 0:49 
GeneralRe: how to select all table names Pin
albCode10-Jun-06 0:52
albCode10-Jun-06 0:52 
QuestioncomboBox Pin
andrei_dalcu10-Jun-06 0:02
andrei_dalcu10-Jun-06 0:02 
AnswerRe: comboBox Pin
albCode10-Jun-06 0:14
albCode10-Jun-06 0:14 
AnswerRe: comboBox Pin
Nafiseh Salmani10-Jun-06 22:49
Nafiseh Salmani10-Jun-06 22:49 
QuestionOpen/Save word documen in the server Pin
Member 22716559-Jun-06 22:08
Member 22716559-Jun-06 22:08 
AnswerRe: Open/Save word documen in the server Pin
Guffa9-Jun-06 23:22
Guffa9-Jun-06 23:22 
Questionradio button in windows form..urgt plzz.. Pin
r_e_h_a_n9-Jun-06 20:09
r_e_h_a_n9-Jun-06 20:09 
AnswerRe: radio button in windows form..urgt plzz.. Pin
Christian Graus9-Jun-06 20:36
protectorChristian Graus9-Jun-06 20:36 
AnswerRe: radio button in windows form..urgt plzz.. Pin
malikjhangirahmed@hotmail.com10-Jun-06 8:53
malikjhangirahmed@hotmail.com10-Jun-06 8:53 
QuestionSmall Question about Remoting Pin
Alexandr Sergeevich Ilyin9-Jun-06 19:49
Alexandr Sergeevich Ilyin9-Jun-06 19:49 
QuestionIssue with ClickOnce and publishing to a http site Pin
Raffi Basmajian9-Jun-06 19:18
Raffi Basmajian9-Jun-06 19:18 

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.