简体   繁体   English

C# WPF ComboBox - 排除绑定数据的最后一行(或空格)(从 Microsoft Access 绑定)

[英]C# WPF ComboBox - Exclude last row (or Blank Space) of Binding Data (binding from Microsoft Access)

Currently I am using Microsoft Access to keep the data and it will bind to WPF combobox.目前我正在使用 Microsoft Access 来保留数据,它将绑定到 WPF 组合框。 Below code was working almost fine.下面的代码几乎可以正常工作。

oleDBCommand.CommandText =

"SELECT "
    + "table.[Col1] & ' - ' & table.[Col2] As COl1_Col2, table.[Col3] " +

"FROM "
    + "table_1 " +

"WHERE "
        + "(table_1.[col3] = '" + comboboxSelection.Text + "' OR table.[col3] = 'All') "; 

The problem that I have is the combobox shows empty space in it.我遇到的问题是组合框在其中显示空白。 May I know how to remove it?我可以知道如何删除它吗? Is it through Access Query or ComboBox Property?是通过 Access Query 还是 ComboBox 属性?

在此处输入图片说明

尝试在 ComboBox 上设置 ScrollViewer.CanContentScroll="False"。

The combobox will only show the objects you give it, take a closer look at the data coming out of your query.组合框只会显示您提供的对象,请仔细查看查询中的数据。 You may need to add an additional filter in the where clause to exclude rows with empty values.您可能需要在 where 子句中添加额外的过滤器以排除具有空值的行。

This might be an old thread but I had the same issue with ComboBox.这可能是一个旧线程,但我在 ComboBox 上遇到了同样的问题。 The thing is ComboBox align items to the TOP so it's not an extra item or line.问题是 ComboBox 将项目与 TOP 对齐,因此它不是额外的项目或行。 It's just the space left after publishing your items.这只是发布您的项目后剩余的空间。 So let's say if your combobox height is 37 px and height of each item is 10px then you will see that last space of 7 px.因此,假设您的组合框高度为 37 像素,每个项目的高度为 10 像素,那么您将看到最后一个 7 像素的空间。 Try keeping the height of combobox same as that of its individual elements.尝试保持组合框的高度与其单个元素的高度相同。

 <ComboBox Width="200"
       Height="50"
       ItemsSource="{Binding MyList}">
    <ComboBox.ItemContainerStyle>
        <Style TargetType="ComboBoxItem">
            <Setter Property="Height" Value="50" />
            <Setter Property="Width" Value="50" />
        </Style>
    </ComboBox.ItemContainerStyle>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM