我正在尝试根据另一个组合框的选择来填充组合框。如果我使用更新按钮来更新组合框#1 选择,我就可以做到这一点。但是,我想动态进行更新。
我附上了一个简单的代码示例,除了一个问题之外,该代码似乎按预期工作。您必须选择组合框 #1 两次才能更新组合框 #2。如果有人对两个如何解决这个问题有任何想法,我们将不胜感激。因为我是通过示例学习的,所以请您提供一个代码示例。
预先感谢您:begez
from tkinter import *
import tkinter.ttk,csv
global CategoryCombo
def getUpdateData():
cat = CategoryCombo.get()
if cat == 'car':
AccountCombo = tkinter.ttk.Combobox( width = 15,value = car)
AccountCombo.grid(row = 5,column = 1,pady = 25,sticky = E)
elif cat == 'home':
AccountCombo = tkinter.ttk.Combobox( width = 15,value = home)
AccountCombo.grid(row = 5,column = 1,pady = 25,sticky = E)
elif cat == 'rv':
AccountCombo = tkinter.ttk.Combobox( width = 15,value = rv)
AccountCombo.grid(row = 5,column = 1,pady = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 linq 创建一个新对象并将其添加到我的数据库中。类别和供应商的值是从组合框中选择的。组合框数据源来自数据库(我使用了 linq),DisplayMember 和 Valuemember 也是如此。我无法获取所选组合框的值(valueMember)来使用它来创建新对象。我不明白有什么问题。
这是我的代码:
DataClasses1DataContext db = new DataClasses1DataContext();
bool lo;
public Form2()
{
InitializeComponent();
lo = false;
var category = from Category in db.Categories
select new
{
categorytName = Category.CategoryName,
categoryID = Category.CategoryID
};
comboBox1.DataSource = category;
comboBox1.DisplayMember = "categorytName";
comboBox1.ValueMember = "categoryID";
var supplier = from Supplier in db.Suppliers
select new
{
suppliertName = Supplier.CompanyName,
supplierID = Supplier.SupplierID
};
comboBox2.DataSource = supplier;
comboBox2.DisplayMember = "suppliertName";
comboBox2.ValueMember = "supplierID";
lo = true;
}
private void …
Run Code Online (Sandbox Code Playgroud) 我想制作一个按钮,单击时必须复制所有项目 ComboBox1
并将它们放入ComboBox2
另一个Form
. 我确信循环遍历ComboBox
项目是可行的,但是我不知道该怎么做。任何帮助将不胜感激。
感谢致敬
我正在尝试使用已经有一些列的数据表将项目添加到组合框,但我只想将其中一个值添加到组合框中。我正在做的是这样的:
cbReviewers.DataSource = Reviewers_table.Columns[1];
Run Code Online (Sandbox Code Playgroud)
但不起作用,你知道我该怎么做吗?
我正在开发一个程序,其中组合框的选项依赖于另一个组合框的选定选项.第一个组合框中的所选项目选择第二个组合框中的哪些选项.有谁知道如何做到这一点?
这是将信息添加到第一个组合框的按钮
try
{
CustomerAccount aCustomerAccount = new CustomerAccount(txtAccountNumber.Text, txtCustomerName.Text,
txtCustomerAddress.Text, txtPhoneNumber.Text);
account.Add(aCustomerAccount);
cboClients.Items.Add(aCustomerAccount.GetCustomerName());
ClearText();
}
catch (Exception)
{
MessageBox.Show("Make sure every text box is filled in!", "Error", MessageBoxButtons.OK);
}
Run Code Online (Sandbox Code Playgroud)
这是第一个组合框的selectedIndex.
private void cboClients_SelectedIndexChanged(object sender, EventArgs e)
{
CustomerAccount custAccount = account[cboClients.SelectedIndex] as CustomerAccount;
if (custAccount != null)
{
txtAccountNumberTab2.Text = custAccount.GetAccountNumber();
txtCustomerNameTab2.Text = custAccount.GetCustomerName();
txtCustomerAddressTab2.Text = custAccount.GetCustomerAddress();
txtCustomerPhoneNumberTab2.Text = custAccount.GetCustomerPhoneNo();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个Combobox默认3项,我想保存这样的项目:
Item1 //don't save
Item2 //Don't save
Items3 //save
//save all futur items added
Run Code Online (Sandbox Code Playgroud)
为什么我的代码不起作用?
if Combobox1.ItemIndex > 2 then // i used 2 for test and it's no work
Combobox1.Items.SaveToFile('util.conf');
end;
Run Code Online (Sandbox Code Playgroud)
如果我删除如果Combobox1.ItemIndex> 2然后保存所有项目...
如何解决这个问题呢?
这是一个展示我遇到问题的行为的示例。我有一个数据网格,它绑定到视图模型中的可观察记录集合。在数据网格中,我有一个 DataGridTemplateColumn 包含一个组合框,该组合框是从视图模型中的列表填充的。数据网格还包含文本列。窗口底部有一些文本框来显示记录内容。
<Window x:Class="Customer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Customer"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:SelectedRowConverter x:Key="selectedRowConverter"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="8*"/>
<RowDefinition Height="3*"/>
</Grid.RowDefinitions>
<DataGrid x:Name="dgCustomers" AutoGenerateColumns="False"
ItemsSource="{Binding customers}" SelectedItem="{Binding SelectedRow,
Converter={StaticResource selectedRowConverter}, Mode=TwoWay}"
CanUserAddRows="True" Grid.Row="0" >
<DataGrid.Columns>
<DataGridTemplateColumn Width="Auto" Header="Country">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="cmbCountry" ItemsSource="{Binding DataContext.countries,
RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
DisplayMemberPath="name" SelectedValuePath="name" Margin="5"
SelectedItem="{Binding DataContext.SelectedCountry,
RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" SelectionChanged="cmbCountry_SelectionChanged" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Name" Binding="{Binding name}" Width="1*"/>
<DataGridTextColumn Header="Phone" Binding="{Binding phone}" Width="1*"/>
</DataGrid.Columns>
</DataGrid>
<Grid x:Name="grdDisplay" DataContext="{Binding ElementName=dgCustomers}" Grid.Row="1"> …
Run Code Online (Sandbox Code Playgroud) 我有ComboBox
如下:
<ComboBox IsEditable="True"
Width="200"
Height="25"
IsTextSearchEnabled="False"
x:Name="cb"
PreviewTextInput="Cb_OnPreviewTextInput"
ItemsSource="{Binding ItemList}"
Text="{Binding SearchTextText}">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
什么时候Cb_OnPreviewTextInput
叫我定IsDropdownOpen = true
。在第一次尝试中(输入第一个字母后),选择了列表中的第一项,我可以使用相关箭头上下移动,插入符号仍然在TextBox
.
当我继续打字时,我无法再上下导航(一次 1 项);此时,整个 ScrollViewer 获得焦点,我只能转到底部或顶部,但不能一一对应。我必须关闭弹出窗口,例如按 Escape 键,然后通过键入 1 个字符重新打开才能向上移动/再次下降。
我还注意到,按 PageUp 后,第一个项目也会被选中,所以我尝试在代码中模仿,但没有成功。
有谁知道在这里该怎么做才能顺利向上/向下导航和打字?
我无处可寻.似乎每个人都试图在列表的第一个位置获得null,但我想要相反.我不想在我的组合框列表中选择null作为选项.我该如何摆脱它.
foreach (String item in comboFieldList)
{
fieldBox1.Items.Add(item);
}
Run Code Online (Sandbox Code Playgroud)
请帮忙.提前致谢.
我在组合框中有10个项目,当我删除其中一个项目时,组合框不会自动显示下一个显示空白区域的项目.我想在范围内显示下一个项目.
我正常删除它们
cmbsomename.Items.Remove(cmbsomename.SelectedItem);
怎么做?
我正在处理动态填充的 Excel 组合框(嵌入在工作表中)
但有时当我更新里面的列表时它已经“下拉/展开”,显示会变得疯狂。
当我填写并检查列表时,我使用这些:
调整可见行数
If .ListCount > 14 Then
.ListRows = 15
Else
.ListRows = .ListCount + 1
End If
Run Code Online (Sandbox Code Playgroud)显示/展开列表(anyCB 是我的 Sub 中的 Object 参数)
anyCB.DropDown
Run Code Online (Sandbox Code Playgroud)但有时,仍然有 15 条可见的行,但在大 (15) 行内有一个小滑块,可以在一个行中滚动所有行...:/
所以我想知道在更改可见行数之前是否有任何方法可以关闭/展开/收回列表。关于您可以建议的任何其他解决方法(失去焦点,...);)
应该在常规组合框上重现什么:
For i = 0 To 100
anyCB.AddItem (i)
Next i
With anyCB
If .ListCount > 14 Then
.ListRows = 15
Else
.ListRows = .ListCount + 1
End If
End With
anyCB.DropDown
If .ListCount > 0 Then
For i = .ListCount - …
Run Code Online (Sandbox Code Playgroud) combobox.Items.Add(object item)
,为什么我们可以使用combobox.Items.Add("Some text")
,虽然"有些文字"是字符串,而不是对象?