Skip to content

Ch 5 remove_rows: when N items in one row are selected, it removes N rows #13

@EricThomson

Description

@EricThomson

I was playing with the code for csv_editor, and noted when I tried to remove a row when I had multiple items selected in that row, it removed the same number of rows as selected items. This is because it uses len(selected) to pick how many rows to remove (instead of number of rows). I changed it to instead find out how many rows are selected (in MainWindow):

        num_rows = len(set(index.row() for index in selected))
        if selected:
            self.model.removeRows(selected[0].row(), num_rows, None)

And now remove_rows works as desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions