Click here to Skip to main content
15,885,909 members
Home / Discussions / C#
   

C#

 
Questionc# Play Video Fullscreen Pin
Member 416962813-Aug-14 5:20
Member 416962813-Aug-14 5:20 
AnswerRe: c# Play Video Fullscreen Pin
Simon_Whale13-Aug-14 5:41
Simon_Whale13-Aug-14 5:41 
GeneralRe: c# Play Video Fullscreen Pin
Member 416962813-Aug-14 5:53
Member 416962813-Aug-14 5:53 
GeneralRe: c# Play Video Fullscreen Pin
Dave Kreskowiak13-Aug-14 6:05
mveDave Kreskowiak13-Aug-14 6:05 
GeneralRe: c# Play Video Fullscreen Pin
Member 416962813-Aug-14 8:42
Member 416962813-Aug-14 8:42 
GeneralRe: c# Play Video Fullscreen Pin
Dave Kreskowiak13-Aug-14 12:27
mveDave Kreskowiak13-Aug-14 12:27 
GeneralRe: c# Play Video Fullscreen Pin
Bernhard Hiller13-Aug-14 21:48
Bernhard Hiller13-Aug-14 21:48 
Question[CheckBox ComboBox] Strange problem with ComboBox.CheckBoxItems[].Checked = true Pin
Member 1062093513-Aug-14 4:17
Member 1062093513-Aug-14 4:17 
Hi,

i have a very strange problem with CheckBox ComboBox Extending the ComboBox Class and Its Items[^]

First, i have two of them on my form. When I check a Item in one of them, i call a method that reloads the entries of the second ComboBox consider which Item was selected in the first ComboBox, after that the method checks the Items which was checked before the entries of the second ComboBox were reload. This should work in two ways.

It works fine when I Select one Item in the first ComboBox and one item in the second ComboBox (My Method checks the "earlier checked Items of the other ComboBox") but when I select two or more Items in the second ComboBox the method dont checks the "earlier checked Items". I hope it was unterstandable, my english isn't the best...please ask when you have any questions.

Here is my Code.

1. ComboBox (cbArticle) CheckBoxCheckedChanged Event:
C#
private void cbArticle_CheckBoxCheckedChanged(object sender, EventArgs e)
{
    //If minimum ONE GroupCode is selected
    if (cbArticle.Text != "Artikel auswählen")
    {
        cbArticle.ForeColor = SystemColors.WindowText;

        GetQueryType(gbTimespan.Controls.OfType<RadioButton>().FirstOrDefault(n => n.Checked));

        //Gets all selected Methods, necessary for Checking the "Old selected Methods" after the Methods ComboBox Itemlist has realoaded
        string[] arrMethods = cbMethod.Text.Split(',');
        //Clear and reload the Methods
        cbMethod.Items.Clear();
        FillMethods();

        //Checks the "Old selected Methods"
        cbMethod.CheckBoxCheckedChanged -= cbMethod_CheckBoxCheckedChanged;
        for (int i = 0; i < arrMethods.Length; i++)
        {
            try
            {
                cbMethod.CheckBoxItems[arrMethods[i].Trim()].Checked = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        cbMethod.CheckBoxCheckedChanged += cbMethod_CheckBoxCheckedChanged;
    }
    //If NO GroupCode was selected --> startup initializing
    else
    {
        cbArticle.ForeColor = SystemColors.GrayText;
        FillMethods();

        if (finished)
        {
            GetQueryType(gbTimespan.Controls.OfType<RadioButton>().FirstOrDefault(n => n.Checked));
        }
    }
}



2. ComboBox (cbMethod) CheckBoxCheckedChanged Event:
C#
private void cbMethod_CheckBoxCheckedChanged(object sender, EventArgs e)
{
    //If minimum ONE Method was selected
    if (cbMethod.Text != "Methode(n) auswählen")
    {
        cbMethod.ForeColor = SystemColors.WindowText;

        GetQueryType(gbTimespan.Controls.OfType<RadioButton>().FirstOrDefault(n => n.Checked));

        //Gets all selected GroupCodes, necessary for Checking the "Old selected GroupCodes" after the Article ComboBox Itemlist has realoaded
        string[] arrArticles = cbArticle.Text.Split(',');
        ////Clear and reload the GroupCodes
        cbArticle.Items.Clear();
        FillGroupCodes();

        //Checks the "Old selected GroupCodes"
        cbArticle.CheckBoxCheckedChanged -= cbArticle_CheckBoxCheckedChanged;
        for (int i = 0; i < arrArticles.Length; i++)
        {
            try
            {
                cbArticle.CheckBoxItems[arrArticles[i].Trim()].Checked = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        cbArticle.CheckBoxCheckedChanged += cbArticle_CheckBoxCheckedChanged;
    }
    else
    {
        cbMethod.ForeColor = SystemColors.GrayText;
        FillGroupCodes();

        if (finished)
        {
            GetQueryType(gbTimespan.Controls.OfType<RadioButton>().FirstOrDefault(n => n.Checked));
        }
    }
}


When I debug the Code it works fine every time. I can see that the checkbox CheckedStatus is checked. But when the Method has ended and my Application switches back to the UI the CheckBoxes aren't checked... I call no other Methods (checked in debugger) but I can see that the CheckBoxComboBox.cs opens in Visual Studio it jumps in the following Code Blocks.

C#
public partial class CheckBoxComboBox : PopupComboBox
{
    #region EVENTS & EVENT HANDLERS

    public event EventHandler CheckBoxCheckedChanged;

    private void Items_CheckBoxCheckedChanged(object sender, EventArgs e)
    {
        OnCheckBoxCheckedChanged(sender, e);
    }

    #endregion

    #region EVENT CALLERS and OVERRIDES e.g. OnResize()

    protected void OnCheckBoxCheckedChanged(object sender, EventArgs e)
    {
        string ListText = GetCSVText(true);
        // The DropDownList style seems to require that the text
        // part of the "textbox" should match a single item.
        if (DropDownStyle != ComboBoxStyle.DropDownList)
            Text = ListText;
        // This refreshes the Text of the first item (which is not visible)
        else if (DataSource == null)
        {
            Items[0] = ListText;
            // Keep the hidden item and first checkbox item in
            // sync in order to ensure the Synchronise process
            // can match the items.
            CheckBoxItems[0].ComboBoxItem = ListText;
        }

        EventHandler handler = CheckBoxCheckedChanged;
        if (handler != null)
            handler(sender, e);
    }
...
}


C#
/// <summary>
/// The CheckBox items displayed in the Popup of the ComboBox.
/// </summary>
[ToolboxItem(false)]
public class CheckBoxComboBoxItem : CheckBox
{
    #region PROTECTED MEMBERS

    protected override void OnCheckedChanged(EventArgs e)
    {
        // Found that when this event is raised, the bool value of the binded item is not yet updated.
        if (_CheckBoxComboBox.DataSource != null)
        {
            PropertyInfo PI = ComboBoxItem.GetType().GetProperty(_CheckBoxComboBox.ValueMember);
            PI.SetValue(ComboBoxItem, Checked, null);
        }
        base.OnCheckedChanged(e);
        // Forces a refresh of the Text displayed in the main TextBox of the ComboBox,
        // since that Text will most probably represent a concatenation of selected values.
        // Also see DisplayMemberSingleItem on the CheckBoxComboBox for more information.
        if (_CheckBoxComboBox.DataSource != null)
        {
            string OldDisplayMember = _CheckBoxComboBox.DisplayMember;
            _CheckBoxComboBox.DisplayMember = null;
            _CheckBoxComboBox.DisplayMember = OldDisplayMember;
        }
    }

    #endregion


Please help me...I am totally frustrated after sitting 2-3 days on this issue...
SuggestionRe: [CheckBox ComboBox] Strange problem with ComboBox.CheckBoxItems[].Checked = true Pin
Richard Deeming13-Aug-14 4:57
mveRichard Deeming13-Aug-14 4:57 
GeneralRe: [CheckBox ComboBox] Strange problem with ComboBox.CheckBoxItems[].Checked = true Pin
Member 1062093513-Aug-14 20:02
Member 1062093513-Aug-14 20:02 
QuestionRegarding the usage of generic in real life Pin
Tridip Bhattacharjee12-Aug-14 21:20
professionalTridip Bhattacharjee12-Aug-14 21:20 
AnswerRe: Regarding the usage of generic in real life Pin
Manfred Rudolf Bihy12-Aug-14 21:51
professionalManfred Rudolf Bihy12-Aug-14 21:51 
GeneralRe: Regarding the usage of generic in real life Pin
Tridip Bhattacharjee12-Aug-14 23:18
professionalTridip Bhattacharjee12-Aug-14 23:18 
GeneralRe: Regarding the usage of generic in real life Pin
Debabrata TPX12-Aug-14 23:49
Debabrata TPX12-Aug-14 23:49 
GeneralRe: Regarding the usage of generic in real life Pin
Tridip Bhattacharjee13-Aug-14 21:25
professionalTridip Bhattacharjee13-Aug-14 21:25 
GeneralRe: Regarding the usage of generic in real life Pin
Pete O'Hanlon13-Aug-14 21:46
mvePete O'Hanlon13-Aug-14 21:46 
GeneralRe: Regarding the usage of generic in real life Pin
Pete O'Hanlon12-Aug-14 23:50
mvePete O'Hanlon12-Aug-14 23:50 
QuestionHow to remove escape sequece from string while telnet to HP procurve devices Pin
superselector12-Aug-14 19:17
superselector12-Aug-14 19:17 
AnswerRe: How to remove escape sequece from string while telnet to HP procurve devices Pin
OriginalGriff12-Aug-14 20:57
mveOriginalGriff12-Aug-14 20:57 
AnswerRe: How to remove escape sequece from string while telnet to HP procurve devices Pin
OriginalGriff13-Aug-14 1:25
mveOriginalGriff13-Aug-14 1:25 
GeneralRe: How to remove escape sequece from string while telnet to HP procurve devices Pin
superselector13-Aug-14 22:52
superselector13-Aug-14 22:52 
GeneralRe: How to remove escape sequece from string while telnet to HP procurve devices Pin
OriginalGriff13-Aug-14 23:01
mveOriginalGriff13-Aug-14 23:01 
AnswerRe: How to remove escape sequece from string while telnet to HP procurve devices Pin
Member 1028463313-Aug-14 2:22
Member 1028463313-Aug-14 2:22 
QuestionC# Creating Setup Problem Pin
Member 1094435911-Aug-14 23:16
Member 1094435911-Aug-14 23:16 
AnswerRe: C# Creating Setup Problem Pin
Dave Kreskowiak12-Aug-14 2:44
mveDave Kreskowiak12-Aug-14 2:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.