开发者

How to Hidden column in winform list box?

I am doing Student Attendance project for college in win form with MySQL(C#).

see the below picture,. this is my form. In that i add three listbox with single column.(student no.)

In that My Client want Student name only and student no they do not want to display.

but i want to save the record based on the Student no. So is it possible Hidden Column in Listbox?.

My Code is

 MySqlConnection connection = new MySqlConnection(MyConString);
                MySqlCommand command = connection.CreateCommand();
                MySqlDataReader Reader;
                command.CommandText = "select admin_no from student_admision_master where course='" + course_code + "' AND year='" + year_code + "' AND sem='" + semester_code + "' AND batch='开发者_如何学Go" + batch_code + "'";
                connection.Open();
                Reader = command.ExecuteReader();
                while (Reader.Read())
                {
                    listBox1.Items.Add(Reader[0].ToString());
                }
                connection.Close();

student_admision_master datatable have all the detail of student. name, father name, address etc...

Please Give an idea to do this!....

How to Hidden column in winform list box?


How do you add the items to your ListBoxes? Please show some us some code.

You have a property called DisplayMember on your ListBox. Try to set your student name property as DisplayMember on your ListBox.


Add the entire Student object to each listbox. Then either set the DisplayMember property to the property of the student object that contains the string you want to display, or simply override the ToString method of the Student class to give an appropriate string for displaying.


Create a class like this pseudocode:

public class Student {
   public string Property1{get;set;}
   public string Property2{get;set;}
}

Add to your listbox a colleciton of Student objects and assign DisplayMember,as suggests @Mariusz to the property name you want to display, cause it's not very clear from post what you want to hide and what you want to show.

Regards.


Just set the column width property to zero. Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜