Question

I am developing a desktop application in which I want to get information from user. If user selects particular radio button then I am opening a new form in popup in which I have placed checked list box. After selecting values from check box I want to access selected value in the previous form. Below are images that can clear idea.

enter image description here

When user click on radio button in "Enable conent type" (as highlighted in the screen) a new form in popup is open to select values from checked list box. After selecting desired value , press "Select" button from Select Content Type form.

Now the form will be hidden but I want to get the selected values in the form "Create Lists".

My code for Radio Button event is:

private void rdbEnableCtypeYes_CheckedChanged(object sender, EventArgs e)
{
    if (rdbEnableCtypeYes.Checked)
    {
        lblSelectContentType.Visible = true;
        frmSelectContentType selectContentType = new frmSelectContentType();
        selectContentType.rootWebUrl = rootWebUrl;
        selectContentType.MdiParent = this.MdiParent;
        selectContentType.StartPosition = FormStartPosition.CenterScreen;
        selectContentType.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        selectContentType.Show();
    }
    else
    {
        lblSelectContentType.Visible = false;
        cmbContentType.Visible = false;
    }
} 

My code for form of Select content type is:

public string rootWebUrl = string.Empty;
XDocument contentTypeFile = XDocument.Load(FilePaths.ContentTypesFilePath);
private void frmSelectContentType_Load(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(rootWebUrl))
    {
        if (contentTypeFile != null)
        {
            XElement xSiteCollection = contentTypeFile.Descendants(XmlElements.SiteCollection).Where(x => x.Attribute(XmlAttributes.Url).Value.Equals(rootWebUrl)).FirstOrDefault();
            if (xSiteCollection != null)
            {
                IEnumerable<XElement> xContentTypes = xSiteCollection.Descendants(XmlElements.ContentType);
                if (xContentTypes.OfType<XElement>().Count() > 0)
                {
                    foreach (XElement xContentType in xContentTypes)
                    {
                        ComboboxItem item = new ComboboxItem();
                        item.Text = xContentType.Attribute(XmlAttributes.Name).Value;
                        item.Value = xContentType.Attribute(XmlAttributes.Id).Value;
                        lstContenType.Items.Add(item);                                
                    }
                }
            }
        }
    }
}

What should I do?

Was it helpful?

Solution

Try This.

Select Content Type Form

private List<string> _selectedItems = new List<String>();
public List<string> SelectedItem
{
    get {return _selectedItems;}
}

private void btnSelect_Click(object sender, EventArgs e)
{
    for(int i=0; i<lst.Items.Count;i++)
    {
        if (lstContenType.GetItemCheckState(i) == CheckState.Checked)
            _selectedItems.Add(lst.Items[i].ToString());
    }
    this.Close();
}

Create List Form

private void rdoEnableCntType_Checked(object sender, EventArgs e)
{
    if (rdoEnableCntType.Checked = true)
    {
        FrmConentType frm = new FrmConentType();        
        frm.ShowDialog();
        List<string> list = frm.SelectedItems;
        //Place your code to use selected items
    }
}

OTHER TIPS

You can pass data in the Constructor of FormB. For example:

//Default Constructor
public FormB()
{
         InitializeComponent();
}

// Overloaded Constructor
public  FormB(string parameter1, string parameter2, string parameter3)
{
         InitializeComponent();
}

For example:

public FormB(bool RbuttonChecked)
{
    InitializeComponent();
    if(RbuttonChecked)
    {
        //Code
    }
}

Invoke FormB from FormA like:

FormB obj=new FormB(Rbtn.checked); //Invoking the overloaded constructor
obj.Show();

You can defined a list in the main form to store items user selected in "Select Content Type" windows. When user have finished the window "Select Content Type", you add selected items to the variable.

In Form "Create List" class:

public List<ContentType> selectedContentTypes = new List<ContentType>();

When user press "Select" button in form "Select Content Type", add items to the variable:

// For each selected items in the listbxo {
    frmCreateList.selectedContentTypes.Items.Add(itemId);
// }

If you can post your source code, it would be easier to help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top