'Given the selected row in the left-hand box, fill in the grid with
the books that contain that data.'

def fill_in_books_box(self, selected_item):

    if selected_item.startswith('.'):
        sv = ('.' + selected_item)
    else:
        sv = selected_item
    sv = (((self.current_key + ':"=') + sv.replace('"', '\\"')) + '"')
    if gprefs['qv_respects_vls']:
        books = self.db.search(sv, return_matches=True, sort_results=False)
    else:
        books = self.db.new_api.search(sv)
    self.books_table.setRowCount(len(books))
    label_text = _('&Books    with    selected    item    "{0}":    {1}')
    if self.is_pane:
        label_text = label_text.replace('&', '')
    self.books_label.setText(label_text.format(selected_item, len(books)))
    select_item = None
    self.books_table.setSortingEnabled(False)
    self.books_table.blockSignals(True)
    tt = (('<p>' + _('Double    click    on    a    book    to    change    the    selection    in    the    library    view    or    change    the    column    shown    in    the    left-hand    pane.    Shift-    or    Control-    double    click    to    edit    the    metadata    of    a    book,    which    also    changes    the    selected    book.')) + '</p>')
    for (row, b) in enumerate(books):
        mi = self.db.get_metadata(b, index_is_id=True, get_user_categories=False)
        for col in self.column_order:
            try:
                if (col == 'title'):
                    a = TableItem(mi.title, mi.title_sort)
                    if (b == self.current_book_id):
                        select_item = a
                elif (col == 'authors'):
                    a = TableItem('    &    '.join(mi.authors), mi.author_sort)
                elif (col == 'series'):
                    series = mi.format_field('series')[1]
                    if (series is None):
                        a = TableItem('', '', 0)
                    else:
                        a = TableItem(series, mi.series, mi.series_index)
                elif (self.fm[col]['datatype'] == 'series'):
                    v = mi.format_field(col)[1]
                    a = TableItem(v, mi.get(col), mi.get((col + '_index')))
                elif (self.fm[col]['datatype'] == 'datetime'):
                    v = mi.format_field(col)[1]
                    d = mi.get(col)
                    if (d is None):
                        d = UNDEFINED_DATE
                    a = TableItem(v, timestampfromdt(d))
                elif (self.fm[col]['datatype'] in ('float', 'int')):
                    v = mi.format_field(col)[1]
                    sv = mi.get(col)
                    a = TableItem(v, sv)
                else:
                    v = mi.format_field(col)[1]
                    a = TableItem(v, v)
            except:
                traceback.print_exc()
                a = TableItem(_('Something    went    wrong    while    filling    in    the    table'), '')
            a.setData(Qt.UserRole, b)
            a.setToolTip(tt)
            self.books_table.setItem(row, self.key_to_table_widget_column(col), a)
            self.books_table.setRowHeight(row, self.books_table_row_height)
    self.books_table.blockSignals(False)
    self.books_table.setSortingEnabled(True)
    if (select_item is not None):
        self.books_table.setCurrentItem(select_item)
        self.books_table.scrollToItem(select_item, QAbstractItemView.PositionAtCenter)
    self.set_search_text(sv)
