Click here to Skip to main content
15,919,613 members
Home / Discussions / C#
   

C#

 
AnswerRe: Dispose a Tooltip Pin
Gerry Schmitz15-Nov-19 5:41
mveGerry Schmitz15-Nov-19 5:41 
AnswerRe: Dispose a Tooltip Pin
Luc Pattyn15-Nov-19 6:22
sitebuilderLuc Pattyn15-Nov-19 6:22 
QuestionType Overflow... Pin
Bernhard Hiller15-Nov-19 0:02
Bernhard Hiller15-Nov-19 0:02 
AnswerRe: Type Overflow... Pin
phil.o15-Nov-19 0:46
professionalphil.o15-Nov-19 0:46 
GeneralRe: Type Overflow... Pin
Bernhard Hiller15-Nov-19 0:49
Bernhard Hiller15-Nov-19 0:49 
AnswerRe: Type Overflow... Pin
Richard Deeming15-Nov-19 1:20
mveRichard Deeming15-Nov-19 1:20 
GeneralRe: Type Overflow... Pin
Bernhard Hiller15-Nov-19 4:55
Bernhard Hiller15-Nov-19 4:55 
QuestionAdding panels dynamically through user input Pin
jacko112313-Nov-19 1:34
jacko112313-Nov-19 1:34 
I'm have a listBox of categories that are added through user input via a label and a checkedListBox. I'm trying to get a way to add panels dynamically based on the number of categories in the listBox. I need to use hide/show for each panel since I want the information to switch between each panel.



I have this for adding the new panel dynamically based on each new category in the listBox:

C#
private void button2_Click(object sender, EventArgs e)
{
  for(int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
  {
   if (!listBox1.Items.Contains(checkedListBox1.CheckedItems[i]))
   {
                    listBox1.Items.Add(checkedListBox1.CheckedItems[i]);

                    newPanel.Name = "panel " + (i+2).ToString();
                    newPanel.Location = new Point(405, 10);
                    newPanel.Parent = this;
                    newPanel.Size = new Size(341, 333);
                    newPanel.Visible = false;
                    newPanel.Controls.Add(nameLabel);
                    newPanel.Controls.Add(testButton);
                    listPanel.Add(newPanel);
                    newPanel.Show();
      }
   }
}

And then for whichever category is clicked on the sub-category it should open the respective panel using this code:

C#
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int index = this.listBox1.IndexFromPoint(e.Location);

            if(index != System.Windows.Forms.ListBox.NoMatches)
            {
                if(index < listPanel.Count - 1)
                {
                    //nameLabel.Text = "panel " + listPanel[index++].ToString();
                    listPanel[index++].Visible = true;
                    MessageBox.Show("" + listPanel.Count.ToString());
                    listPanel[--index].Show();

                }
            }
        }

I just either get no respective panel opening or an out-of-range index at listPanel[--index].Show();



Thanks for your help
AnswerRe: Adding panels dynamically through user input Pin
OriginalGriff13-Nov-19 1:45
mveOriginalGriff13-Nov-19 1:45 
GeneralRe: Adding panels dynamically through user input Pin
jacko112313-Nov-19 2:20
jacko112313-Nov-19 2:20 
SuggestionRe: Adding panels dynamically through user input Pin
Richard Deeming13-Nov-19 1:58
mveRichard Deeming13-Nov-19 1:58 
GeneralRe: Adding panels dynamically through user input Pin
jacko112313-Nov-19 2:19
jacko112313-Nov-19 2:19 
AnswerRe: Adding panels dynamically through user input Pin
Luc Pattyn13-Nov-19 3:12
sitebuilderLuc Pattyn13-Nov-19 3:12 
QuestionHow to Import database.mdf file in Visual Studio 2010 Project Pin
Member 1464246911-Nov-19 23:59
Member 1464246911-Nov-19 23:59 
AnswerRe: How to Import database.mdf file in Visual Studio 2010 Project Pin
OriginalGriff12-Nov-19 0:07
mveOriginalGriff12-Nov-19 0:07 
GeneralRe: How to Import database.mdf file in Visual Studio 2010 Project Pin
Member 1464246912-Nov-19 0:29
Member 1464246912-Nov-19 0:29 
GeneralRe: How to Import database.mdf file in Visual Studio 2010 Project Pin
OriginalGriff12-Nov-19 0:46
mveOriginalGriff12-Nov-19 0:46 
GeneralRe: How to Import database.mdf file in Visual Studio 2010 Project Pin
Member 1464246912-Nov-19 18:28
Member 1464246912-Nov-19 18:28 
GeneralRe: How to Import database.mdf file in Visual Studio 2010 Project Pin
OriginalGriff12-Nov-19 20:44
mveOriginalGriff12-Nov-19 20:44 
Questionc++ DLL import in c# Pin
Member 1465244911-Nov-19 19:49
Member 1465244911-Nov-19 19:49 
AnswerRe: c++ DLL import in c# Pin
Richard MacCutchan11-Nov-19 21:12
mveRichard MacCutchan11-Nov-19 21:12 
GeneralRe: c++ DLL import in c# Pin
Member 1465244912-Nov-19 19:44
Member 1465244912-Nov-19 19:44 
GeneralRe: c++ DLL import in c# Pin
Richard MacCutchan12-Nov-19 22:09
mveRichard MacCutchan12-Nov-19 22:09 
QuestionCode not splitting for login form. C# Pin
Member 1465157011-Nov-19 1:10
Member 1465157011-Nov-19 1:10 
AnswerRe: Code not splitting for login form. C# Pin
phil.o11-Nov-19 1:19
professionalphil.o11-Nov-19 1:19 

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.