不知道我在这里做错了什么
//update controls from main form Tshape
form2.cbxShape.ItemIndex:= ord(Shape1.Shape);
form2.cbxColor.Selected:= Shape1.Brush.Color;
form2.cbxStyle.ItemIndex:= Ord(Shape1.Brush.Style);
if form2.ShowModal = mrOK then
begin
//update main form Tshape from controls
Shape1.Shape:= TShapeType(form2.cbxShape.ItemIndex);
Shape1.Brush.Color:= form2.cbxColor.Selected;
Shape1.Brush.Style:= TBrushStyle(form2.cbxStyle.ItemIndex);
end;
Run Code Online (Sandbox Code Playgroud)
我没有得到正确的形状或画笔样式(颜色工作正常)
列表框项目如下:
Circle
Ellipse
Rectangle
RoundRect
RoundSquare
Square
Run Code Online (Sandbox Code Playgroud)
和
BDiagonal
Clear
Cross
DiagCross
FDiagonal
Horizontal
Solid
Run Code Online (Sandbox Code Playgroud) 我希望我的组合框下拉并在用户键入组合框时提供建议.
例如,如果用户键入"R",则应建议以"R"开头的所有项目(例如Roshan,Rohan,Rishan等).
我可以从数据库中获取数据,但问题是如何下载组合框?
我想从我的数据库中获取包含2个字段的结果集.
rs=Con.sqlQueryTable("Select id_prov, name_prov from prov");
Run Code Online (Sandbox Code Playgroud)
然后我想在comboBox中显示名为"name_prov"的字段(作为项目).但我也希望将我的"id_prov"作为ID(PRIMARY KEY)作为此项的值.这用于仅通过使用组合框将(在这种情况下的提供者)名称与其ID相关联.
这是我正在使用的JComboBox事件FocusGained的代码.
try {
//CBProv is the Combobox
CBProv.removeAllItems();
rs=Con.sqlQueryTable("Select id_prov, name_prov from prov");
while(rs.next())
{
CBProvedores.addItem(rs.getString("name_prov"));
//Here should be the Value related to the item I am creating
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error" + e );
}
Run Code Online (Sandbox Code Playgroud)
无论如何我能做到这一点吗?
当用户在组合框中按Enter键时,我想要捕获事件.怎么抓住你 例如:我在组合框中键入"Nguyen Phong Sac".按Enter键后,会显示一条消息:"Nguyen Phong Sac".谢谢你的帮助,
现在,当我在第一个组合框中选择项目时,第二个模拟选择.我希望能够单独选择每个组合框.谢谢.
List<W6AdminUIs2.DictionaryObject> taskStatuses = W6AdminUIs2.GlobalFunctions.GetDictionaryItems("TaskStatus");
// Init the binding source of the statuses.
BindingSource bsFromStatuses = new BindingSource();
bsFromStatuses.DataSource = taskStatuses;
//Bind the "From" combo box to binding source.
cBoxFrom.DataSource = bsFromStatuses.DataSource;
cBoxFrom.DisplayMember = "Name";
cBoxFrom.ValueMember = "Key";
// Init the binding source of the statuses.
BindingSource bsToStatuses = new BindingSource();
bsToStatuses.DataSource = taskStatuses;
//Bind the "From" combo box to binding source.
cBoxTo.DataSource = bsToStatuses.DataSource;
cBoxTo.DisplayMember = "Name";
cBoxTo.ValueMember = "Key";
Run Code Online (Sandbox Code Playgroud) 我是否有更有效的方法来编写此用户表单代码?
Private Sub Userform_Initialize()
'do stuff
With Item1_DropDown
.AddItem "Monday"
.AddItem "Tuesday"
.AddItem "Wednesday"
End With
With Item2_DropDown
.AddItem "Monday"
.AddItem "Tuesday"
.AddItem "Wednesday"
End With
With Item3_DropDown
.AddItem "Monday"
.AddItem "Tuesday"
.AddItem "Wednesday"
End With
'and so on, and so on. (I have about fifty of these 'With/End With' blocks)
End Sub
Run Code Online (Sandbox Code Playgroud)
基本上,我希望能够停止写这么多'With/End With'块.现在,我在四个类似构造的用户表单中有这种类型的代码.它占用了太多的文本空间,似乎是一种浪费.有一个更好的方法吗?
请知道我从未写过课程模块.所以,如果解决方案需要它,我将需要被其中的宝宝所吸引.
谢谢,
埃利亚斯
下面是我开始调试时导致错误的代码.当我从combobox1或combobox2选择选项时,我收到一条消息:Index超出了数组的范围.我该怎么解决这个问题?
谢谢你的时间阅读.:)
public Form1()
{
InitializeComponent();
String[] arr1 = new String[2];
arr1[0] = "SG";
arr1[1] = "MY";
comboBox1.Items.AddRange(arr1);
comboBox2.Items.AddRange(arr1);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
double[,] arr = new double[2, 2];
for(int i = 0; i <2; i++)
{
arr[0, 0] = 1;
arr[0, 1] = 1.24;
arr[1, 0] = 0.80;
arr[1, 1] = 1;
label1.Text =
arr[comboBox1.SelectedIndex,
comboBox2.SelectedIndex].ToString();//Index was outside the bounds of the array.
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
double[,] arr = …Run Code Online (Sandbox Code Playgroud) 在这段代码中:
unit MSEC;
interface
uses
Winapi.Windows, Vcl.Dialogs, Vcl.ExtCtrls, System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls;
type
TMSEC = class(TWinControl)
private
FOpr :TComboBox;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
const
DEF_OPERATIONS :array[0..3] of Char = ('+', '-', '*', '/');
constructor TMSEC.Create(AOwner: TComponent);
var i :Integer;
begin
inherited;
FOpr:= TComboBox.Create(Self);
with FOpr do begin
Parent:= Self;
Align:= alLeft;
Width:= DEF_OPERATIONS_WIDTH;
Style:= csDropDownList;
//error in next lines :
Items.Clear;
for i := Low(DEF_OPERATIONS) to High(DEF_OPERATIONS) do Items.Add(DEF_OPERATIONS[i]);
ItemIndex:= 0;
end;
end;
end.
Run Code Online (Sandbox Code Playgroud)
当我更改ComboBox项目时,程序会中断消息:
'Control'没有父项.
如何修复此错误或以其他方式初始化ComboBox项?
我正在开发一个ASP .Net C#项目,我是网络编程的初学者.我在运行时得到以下错误:
你调用的对象是空的.
以下是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
txtUsername.Focus();
if (cmbThemes.SelectedItem.Text=="Red")
{
pnlSignin.Border.BorderColor = Color.Orange;
}
}
Run Code Online (Sandbox Code Playgroud)
cmbThemes是一个ComboBox.
提前致谢.
我如何在一个声明中这样做?我尝试通过删除;和添加一个+inbetween而在一个语句中创建它们但它不起作用.sName并且sRealname是字符串.
comboBox1.Items.Add(sName);
comboBox1.Items.Add(sRealname);
Run Code Online (Sandbox Code Playgroud)
编辑:抱歉混乱.我需要comboBox上的文本显示在sName和sRealname的1行中,但是我需要为每个字符串分隔代码,因为如果不是代码中断