English 中文(简体)
从另一种形式上打上bo子
原标题:Calling a combobox from another form
  • 时间:2012-05-16 13:58:24
  •  标签:
  • c#
  • combobox

我在表1上有一个浏览器箱,我需要用表2挑选用户。 请允许我举例说明如何做到这一点?

EDIT: 想解释一下什么是想做的。 我有读文本箱......a 用户点击ed了案文,但我想到的是他们想要/想到的文字在表格2被点打上正确的位置。

我有这份表格。

    public string SelectedComboValue
    {
        get { return comboBox1.SelectedItem.ToString(); }
    }

而这一法典的形式是2

    EDIT: Added Form1 form1 = null; BUT its still not returning the SelectedComboValue
    public Form2(Form1 parentForm1) : this()
    {
         form1 = parentForm1;
    }

但它给我留下了一个错误,说形式1不是在这种情况下。

最佳回答

I suppose that Form1 is the parent of Form2, so when you create the Form2 you use code like this

Form2 f = new Form2(this);

then in the Form2 class you should have a declaration like this

Form1 _parentForm = null;

表格2

public Form2(Form1 parentForm1) 
{          
    _parentForm = parentForm1;     
} 

如果情况确实如此,你可以打电话。

_parentForm.SelectedComboValue ;

to get the result required

问题回答

in c# Form 2: create a combobox here

public string strDecVal{
 set{ combobox1.text = value; }
}

in Form 1: for example you have a textbox and a button that will go to form2

将这些法典放在你 but子上

Form2 frmShow = new Form2(); //Calling the form2
frmShow.strDecVal = textbox1.text;
frmShow.ShowDialog;

在VB,自动化程度更高:

Form1: textbox and button in clicking the button in form1 put the code:

Form2.Show()

in Form2: on the Load put this code:

ComboBox1.Text = Form1.TextBox1.Text

您可以把 com贝箱作为ComboBox类的物体:

internal static ComboBox CB=comboBox1;

Then you can call it in the other form, and access all of the methods and attributes of the ComboBox class. If you want to add items to that CB, you can do it easily as you do in the parent form. It doesn t matter if it s internal or static, it s just for the example.





相关问题
WPF Datagrid, Setting the background of combox popup

I would like to change the color of the popup background when using a DatagridComboboxColumn in the WPF Toolkit datagrid. I ve edited the Template for a normal Combobox and it works great for selected ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

How do I bind a ComboBox to a one column list

I ve seen how to bind a ComboBox to a list that has columns like this: ItemsSource="{Binding Path=Entries}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=Entry}" But ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

热门标签