c listboxt how to display the contents of the database

Updated on technology 2024-02-27
3 answers
  1. Anonymous users2024-02-06

    using system;

    using ;

    using ;

    using ;

    using ;

    using ;

    using ;

    namespace mywindows

    public partial class form5 : form

    public form5()

    initializecomponent();

    loadlistbox();

    Load the listbox

    private void loadlistbox()

    ilistlist = getdata();

    if ( 0) ;If the collection data is greater than 0, clear the original listbox entry.

    foreach (student s in list)

    Although the addition here is an entity object, we have rewritten the tostring method, so the name is still displayed.

    Get the data, here simulates getting the data from the database.

    private ilistgetdata()

    ilistlist = new list();

    student s1 = new student(1, "Zhang San", true);

    student s2 = new student(2, "Li Si", true);

    student s3 = new student(3, "Wang V", false);

    student s4 = new student(4, "Zhao Liu", true);

    student s5 = new student(5, "Hou Qi", false);

    ;;return list;

    public class student

    student id, private int id;

    public int id

    get set

    Student's name.

    private string name;

    public string name

    get set

    Gender of the student.

    private bool gender;

    public bool gender

    get set

    public student(int id, string name, bool gender)

    id; name;

    gender;

    Rewrite the tostring method to return the student's name.

    public override string tostring()

    return name;

    The advantage of this is that when you are selected, you actually get the entity object itself.

    data sources; This can also be loaded, but not as flexible.

    Understand for yourself. Hope it works for you.

  2. Anonymous users2024-02-05

    Roughly the same as list, you specify a data source (datasource) and then bind the data source (databind).

  3. Anonymous users2024-02-04

    SQL Permissions Table: ID Int Auto Number(Auto Increment) Userid Int User Number Permission Field Comp Nvarchar(max).

    When you click Save, read all the data in the listbox on the right, with symbols','Separate strings e.g. string strcomp="Log back in and add your income and expenses";This saves the user's permissions.

    When you need to read user permissions, read the user permissions comp field and put the permissions into an array of strings, for example: string comp="comp"].tostring().split(',');

    In this way, all the user's permissions are put into the array comp, which is added to the listbox control on the right by looping, which is used to display the user's permissions.

Related questions
13 answers2024-02-27

Let's say the textbox is named textbox and the string of numbers to be displayed is strfloat: >>>More

4 answers2024-02-27

It works fine but the NA is displayed because the excell cell is not formatted correctly. >>>More

35 answers2024-02-27

In order to avoid the subsequent impact on your electricity consumption and billing, please reflect to the owner of the meter in a timely manner, if you belong to the electricity customer of Guangdong Power Grid, please call the 24-hour power supply service **95598, and the power supply company will arrange staff to follow up. >>>More

5 answers2024-02-27

Check it with GPU Z or look at it in the bottom left corner of the graphics card control panel. >>>More

14 answers2024-02-27

Mine is also GTS-5830 Mine only has a charging display even on the computer, and my phone sometimes messes into the program by itself. Tragedy.