7 Replies - 1502 Views - Last Post: 08 May 2013 - 06:31 AM Rate Topic: -----

#1 ACParson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-February 10

Issue adding items to combobox from other form.

Posted 08 May 2013 - 05:37 AM

I've been working on a new project, and I may have already asked this, or seen an answer, but I can't find it.

I'm trying to add a number value to a combobox on frmMessages from my form frmLeaveMessages.
I've managed to pull a value from it, but can't get it to add the item to the ComboBox collection.

 frmMessages.cboText.Items.Add(messcount)



The cboText combobox is set to Public Visibility, so what am I doing wrong here? I searched for adding items to a combobox from other forms, but none of their suggestions worked.

Is This A Good Question/Topic? 0
  • +

Replies To: Issue adding items to combobox from other form.

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Issue adding items to combobox from other form.

Posted 08 May 2013 - 05:50 AM

did you check to make sure messcount has a value and that it's not just adding "" to the combobox?

set a breakpoint on that line and when execution stops. hover over messcount and see what it contains.
Was This Post Helpful? 0
  • +
  • -

#3 ACParson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-February 10

Re: Issue adding items to combobox from other form.

Posted 08 May 2013 - 06:00 AM

View PostCharlieMay, on 08 May 2013 - 05:50 AM, said:

did you check to make sure messcount has a value and that it's not just adding "" to the combobox?

set a breakpoint on that line and when execution stops. hover over messcount and see what it contains.


It does have a value, and when I add an item to the combobox in the editor, it displays with the right count. But it's not adding the item.
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Issue adding items to combobox from other form.

Posted 08 May 2013 - 06:06 AM

Show me how you opened and showed frmMessages. What line(s) of code did you use to make it show?
Was This Post Helpful? 0
  • +
  • -

#5 ACParson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-February 10

Re: Issue adding items to combobox from other form.

Posted 08 May 2013 - 06:15 AM

View PostCharlieMay, on 08 May 2013 - 06:06 AM, said:

Show me how you opened and showed frmMessages. What line(s) of code did you use to make it show?


frmMessages.Show()
frmMessages.Hide()



That loads the form into memory, and leaves it invisible. It doesn't show up in the taskbar (as I set it). So I don't understand why it's still blank.
Was This Post Helpful? 0
  • +
  • -

#6 ACParson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-February 10

Re: Issue adding items to combobox from other form.

Posted 08 May 2013 - 06:26 AM

View PostACParson, on 08 May 2013 - 06:15 AM, said:

View PostCharlieMay, on 08 May 2013 - 06:06 AM, said:

Show me how you opened and showed frmMessages. What line(s) of code did you use to make it show?


frmMessages.Show()
frmMessages.Hide()



That loads the form into memory, and leaves it invisible. It doesn't show up in the taskbar (as I set it). So I don't understand why it's still blank.


Also, when I try to add an item to the combobox on the actual form itself, it doesn't add.
Was This Post Helpful? 0
  • +
  • -

#7 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: Issue adding items to combobox from other form.

Posted 08 May 2013 - 06:30 AM

is there any kind of error while u r adding item to combo box?
msgbox(messcount)

Quote

Also, when I try to add an item to the combobox on the actual form itself, it doesn't add.

Try to add item on other combo box in form itself
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Issue adding items to combobox from other form.

Posted 08 May 2013 - 06:31 AM

Ok, that's fine. Is that the same way you do it when you actually show the form to the user?

Also, the default instance of the form (as you're doing there) can be accessed without ever showing it so that code is really unnecessary.

What I'm looking for is, is there anywhere in your code that you're using
dim something as new frmMessages
something.show


Where something is a variable name for a form.

It appears that you're instantiating a new form to show to the user but adding to the default instance. Otherwise I could do this right out of the box using the default instance of a form

Create a form1 and form2
on form2 add a combobox

on form1 add a button

in that buttons click event add
form2.combobox1.items.add("foo")

form2.show


Form2 would contain foo in it's combobox.

This is all using the default instance of the form1 and form2 classes. It is really not the way VB.Net was meant to be used but Microsoft decided to add it to make migrating from VB6 to VB.Net easier and allow for more procedure type programming than true object-oriented programming

Notice I did not have to show form2 to access it I was able to access all its controls from form1 using that default instance.

So that being said, how are you showing the frmMessages to the user, because it would seem you're mixing a little bit of both methods here. But that's just a guess from what I understand from how the default instance works.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1