我有一个ComboBox/LookupComboBox的问题,这是一个非常白痴但我不知道如何通过谷歌搜索它来解决它.我在我的数据库上有一个表,用于保存记录的"Y/N"以指示它是活动(Y)还是非活动(N).但在我的应用程序中,我想向用户显示"是/否"而不只是一个单词,任何人都可以帮助我吗?
谢谢!
win表格上有一个组合框和一个按钮.如何通过单击按钮来激活comboBox selectedIndexChanged.
我有一个几乎默认的WPF ComboBox:
例如,在组合框输入和/或下拉中将项目对齐的最简单方法是什么?
我环顾四周,发现只有弄乱控制模板的解决方案,在我看来这对于这么简单的事情来说太长了.我无法相信我们可以做的更简单的解决方案来调整项目.
更新:我稍微重新阐述了这个问题,以涵盖更多读者可能会在这个主题上遇到的更广泛的案例,因为事实证明这要归功于dkozl的答案.
此外,它应该防止一些人试图将此问题作为副本关闭.
我的目标是让我的按钮灵活,取决于我的组合框的当前值,但问题是当我在该特定事件上运行我的程序它冻结,我的语法有问题或我的电脑只是慢?
private void cmbOperation_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = (string)cmbOperation.SelectedItem;
while (selected == "ADD")
{
txtID.ReadOnly = true;
txtLName.ReadOnly = false;
txtFName.ReadOnly = false;
txtMI.ReadOnly = false;
txtGender.ReadOnly = false;
txtAge.ReadOnly = false;
txtContact.ReadOnly = false;
btnOperate.Text = "ADD CLIENT";
}
}
private void btnOperation_Clicked(object sender, EventArgs e)
{
if (cmbOperation.SelectedItem.Equals("ADD"))
{
string constring = "datasource=localhost;port3306;username=root";
string Query = "insert into mybusiness.client_list (LastName,FirstName,MI,Gender,Age,Contact) values('" + this.txtLName.Text + "','" + this.txtFName.Text + "','" + this.txtMI.Text + "','" + this.txtGender.Text …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个组合框.我添加了一些项目作为字符串.物品已经对齐.我想要正确的对齐方式.我搜索了很多,但我找不到任何东西.谢谢.
with TdmBCElections.Create(Self) do
begin
with dmBCElections, qryParties do
begin
SQL.Clear;
if rgpParty.ItemIndex = 0 then
SQL.Text := 'SELECT StrConv(P_Surname, 3), StrConv(P_Names, 3) ' +
'FROM Parties WHERE P_Type = "HEAD"'
else
SQL.Text := 'SELECT StrConv(P_Surname, 3), StrConv(P_Names, 3) ' +
'FROM Parties WHERE P_Type = "TEACHER"';
Open;
while not Eof do
begin
cmbDetails.Items.Add(qryParties['StrConv(P_Surname, 3)'] + ', ' +
qryParties['StrConv(P_Names, 3)']);
Next;
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了以下错误消息:
当StrConv应用于它们时,如何调用表字段?
我正在用WPF项目编写C#代码.我有一个ComboBox1下拉列表,用户从我的计算机上的Microsoft Access数据库中选择一个项目.在用户选择某些内容之后,我想从用户刚刚选择进入文本块的同一行中检索某个值.
我得到3个完全相同的错误并说" 当前上下文中不存在名称'connect'." 我不知道如何解决这个问题.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;
using System.ComponentModel;
namespace bundlecalc
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MainWindow_Load();
}
private void MainWindow_Load()
{
OleDbConnection connect = new OleDbConnection();
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Projects\Database.accdb;
Persist Security Info = False; ";
connect.Open();
OleDbCommand command …Run Code Online (Sandbox Code Playgroud) 有没有更短的方法将1-100中的所有数字添加到c#中的组合框中?目前我所知道的方法是手动添加1比1,这会消耗时间.有更快的方法吗?
PS我是c#的新手,所以如果你能向我解释你的代码会非常有帮助.:d
我正试图让一个下拉组合框(CBS_DROPDOWN或CBS_DROPDOWNLIST)工作.问题是,无论何时打开组合框,整个窗口都"冻结"(它不响应任何东西,甚至不能关闭它,它会忽略点击)."解冻"的唯一方法是按"esc"键.
当窗口被"冻结"时,组合框不会收到任何消息,也不会移动鼠标,点击等.
这是我用来创建组合框的代码:
case WM_CREATE:
hComboBox = CreateWindow("COMBOBOX", nullptr,
WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | CBS_DROPDOWNLIST,
25, 25, 150, 280, hwnd, (HMENU)12345, GetModuleHandle(nullptr), nullptr);
populate_cb();
break;
Run Code Online (Sandbox Code Playgroud)
"populate_cb()"函数只是在组合框中添加了一些字符串并设置了一个初始元素:
void populate_cb() {
SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)"Item 1");
SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)"Item 2");
SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)"Item 3");
SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)"Item 4");
SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)"Item 5");
SendMessage(hComboBox, CB_SETCURSEL, (WPARAM)2, 0);
}
Run Code Online (Sandbox Code Playgroud)
但是,simple(CBS_SIMPLE)组合框可以工作.
这是完整的代码:
#include <Windows.h>
HWND hComboBox;
void populate_cb() {
SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)"Item 1"); …Run Code Online (Sandbox Code Playgroud) 我试图用列表填充wpf组合框。我有两个问题。
这是我的组合框XAML:
<Label Target="{Binding ElementName=State}" Grid.Row="10" Grid.Column="0">State:</Label>
<ComboBox x:Name="State" Margin="10,0,0,10" Grid.Column="1" Grid.Row="10" ItemsSource="{Binding Path=States, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.Error="Validation_Error" SelectedValue="{Binding Path=FamilyMember.State}"/>
<TextBlock Grid.Column="2" Grid.Row="10" Style="{StaticResource TextBlockStyle}" Text="{Binding (Validation.Errors)[0].ErrorContent, ElementName=State}" Margin="10,0,0,10"/>
Run Code Online (Sandbox Code Playgroud)
这是我声明和填充“状态”对象的局部视图模型。
ViewModel中的属性
public ObservableCollection<string> States;
Run Code Online (Sandbox Code Playgroud)
构造函数:
States = new ObservableCollection<string>();
States.Add("One");
States.Add("Two");
States.Add("Three");
States.Add("Four");
States.Add("Five");
Run Code Online (Sandbox Code Playgroud)
它适用于其他领域,没有任何问题,如下所示: