ISCL is a Intelligent Information Consulting System. Based on our knowledgebase, using AI tools such as CHATGPT, Customers could customize the information according to their needs, So as to achieve

How to Disable a Column in a GridView by Role

9
    • 1). Click on the Visual Studio 2010 Express icon to launch the program. Once it has loaded the home page, click on the link in the upper-right corner labeled "New Project..." A "New Project" window will appear.

    • 2). Select "C#" in the left-hand column of the "New Project" window. Select "Windows Form" in the right-hand column of the "New Project" window. Click on the "OK" button to create the new project. A source code file appears in the main editor window.

    • 3). Locate the "Toolbox," which by default is on the lower-right side of the main editor window. The "Toolbox" contains all of the GUI objects you can use on your Windows Form.

    • 4). Find "DataGridView" in the "Toolbox" and click-drag it onto your form. Release your mouse button to set the object on the Form.

    • 5). Click on the tiny black arrow located in the upper-right hand corner of the "DataGridView." A menu opens.

    • 6). Click on "Add Column" to open the "Add Column" window.

    • 7). Type "Student Name" in the field marked "Header Text" and press the "Add" button. A new column with the text "Student Name" appears in the "DataGridView."

    • 8). Type "Social Security Number" in the field marked "Header Text" and press the "Add" button. Another column appears next to the first column.

    • 9). Press the "Close" button to close the "Add Column" window.

    • 10

      Click on "View" at the top of the Visual Studio 2010 software and select "Code" from the menu that pops up. The main editor window now displays source code instead of a Windows Form.

    • 11

      Locate the statement "InitializeComponent();" in the source code file. It is towards the bottom of the file. All of your source code must immediately follow this statement.

    • 12

      Write a statement that defines a string variable. This string holds the type of user (e.g. administrator, student, teacher). For now, set the string to "admin" like this:

      string userType = "admin";

    • 13

      Write a statement that checks to see if the "userType" is anything except "admin" (students and teachers). For these users, the Social Security Number column shouldn't be visible. To make that column invisible, write the following code:

      if (userType != "admin")

      { Column2.Visible = false; }

    • 14

      Write an else statement that occurs when the "userType" is equal to "admin," and set the visibility of the column to "true," like this:

      else

      { Column2.Visible = true; }

    • 15

      Execute the program by pressing the green "Play" button located at the top of the Visual Studio software. A Windows Form appears and it features a table with two columns: "Student Name" and "Social Security Number." Close the application.

    • 16

      Change the string "userType" to "student" and run the software. The table now has only one column: "Student Name."

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.