Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear users, I am new to C#. I have a project on pathology where i have been asked to add diagnostics tests programatically into somewhere (like listbox, datagridview or Listview) & based on the test choosed I need to print it on A4 paper (the A4 paper has header & footer added already on page). I have added text boxes, drop-down menus to my form ( I choosed listbox1). The problem is that when I add "Doctor name" & "Patient name" in a single line in listbox, the patient name shifts at extreme corner (if doctor name is long enough) & does not remain at the position where I ask it to sit. Hence I googled it to find if we can insert text in listbox using X or Y coordinates but no to avail. I am frustated now. I also tried to use other controls like datagridview or Listview but they need to get specific columns names which does not meet my project requirements. Please help me. The sample code is as below.
C#
private void btn_patient_add_Click(object sender, EventArgs e)
{
listBox1.Items.Add(lbl_patient_name.Text + " " + comboBox1.Text + " " + txtbox_patient.Text + "                                                                                " + lbl_age.Text+" "+cbox_age.Text+"/"+cbox_sex.Text);
listBox1.Items.Add("\n");
listBox1.Items.Add(lbl_ref.Text+" "+cbox_ref.Text+ " "+txtbox_date.Text);
listBox1.Items.Add("\n");
listBox1.Items.Add("__________________________________________________________________________________________________");
//listBox1.Items.Insert(10, "First");
}
Posted
Updated 13-Mar-15 22:20pm
v2

1 solution

 
Share this answer
 
v2
Comments
Member 11160992 14-Mar-15 5:03am    
Thanks man! Do you know how to define "how many columns am I going to have" ? I found the below syntax but it's not working.

THISFORM.lst1.ColumnCount = 3

I am using visual studio 2005
OriginalGriff 14-Mar-15 5:15am    
What the heck is THISFORM?
Member 11160992 14-Mar-15 5:31am    
this.listbox1.ColumnCount=3
I can find "coulmn width" property but cannot find "Column count" property. When I am trying to add it programmatically, its giving me error.
OriginalGriff 14-Mar-15 5:37am    
Answer updated.

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