Results 1 to 6 of 6

Thread: Rows of data

  1. #1
    Addicted Member
    Join Date
    Apr 12
    Posts
    151

    Rows of data

    I have a database which will display many rows of personal info on students. For each student I need to select a single preference (primary language) and I can only select 1 preference.

    I thought about adding a datagrid and using the check box column.

    1. How can I ensure only 1 column is ticked per row?
    2. Is there another way of doing this?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,781

    Re: Rows of data

    You wouldn't use a check box column for that. As with all check boxes, that would indicate that some value was either True or False for each row. You would certainly not add a column for each language. This is a job for a combo box column. there is a student row and, for each student, you select one language from the drop-down list of many. For an example, follow the CodeBank link in my signature and check out my thread on the subject of a ComboBox Column In A DataGridView.

  3. #3
    Addicted Member
    Join Date
    Apr 12
    Posts
    151

    Re: Rows of data

    Yes, I had considered this option. When I have 300 students to update with different settings this approach can take a while and errors can occur with the wrong tabbing and arrowing.


    I get a list of Frence speakers, then German then something else. So I need to go up and down the list a lot.

    Are there any other avenues to explore?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,781

    Re: Rows of data

    If you want to see, for example, just the French speakers, then you can simply filter the list, which is even easier if you use a combo box column. You can have a regular ComboBox outside the grid that also displays the languages. When the user selects a language in there you use the SelectedValue to set the Filter of BindingSource that is bound between the table of students and the grid, e.g.
    Code:
    studentsBindingSource.Filter = "LanguageID = " & languageComboBox.SelectedValue.ToString()
    That will filter the data to show only those student records where the language selected in the combo box in that row is the same as the language selected in the standalone ComboBox control.

  5. #5
    Addicted Member
    Join Date
    Apr 12
    Posts
    151

    Re: Rows of data

    I don't want to display just french speakers, I want to display all students and select those who speak French then German so I may need to update 30 with French, another 15 German and maybe 55 Korean for example.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,781

    Re: Rows of data

    I'm afraid that I don't see the issue. How does having check boxes mean that would have to go up and down the list any less that combo boxes? You still have the same number of rows, one for each student, so you won't be going up and down the list any less.

    Also, if you want to be able to set the language for multiple records at a time then why not add a function to do just that? Select all the rows you want to change and then display a dialogue with a ComboBox containing all the languages. When you click OK then loop through the SelectedRows and update each one from the dialogue, e.g.
    Code:
    Using dialogue As New LanguageSelectionDialogue
        If dialogue.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim languageID = dialogue.LanguageID
    
            For Each gridRow As DataGridViewRow In studentGrid.SelectedRows
                Dim studentRow = DirectCast(gridRow.DataBoundItem, DataRowView)
    
                studentRow("LanguageID") = languageID
            Next
        End If
    End Using

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •