473,287 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

ComboBox & AddNew problem

Hello!

I have Windows Forms application form containing TextBoxes, six ComboBoxes,
and DataGrid for details. I have created DataSet with needed tables, and
created relations between tables, and bound controls to datatables.

Everything is working almost fine including saving data, but when I press
'New' - button ...

thisCurrencyManager.EndCurrentEdit()
thisCurrencyManager.AddNew()
cboComBo1.SelectedIndex = -1
cboComBo2.SelectedIndex = -1
cboComBo3.SelectedIndex = -1
cboComBo4.SelectedIndex = -1
cboComBo5.SelectedIndex = -1
cboComBo6.SelectedIndex = -1

....to add new entry, only ComboBoxes 3 to 6 are moving to .SelectedIndex
= -1, but ComboBoxes 1 and 2 to .SelectedIndex = 0 ?!?

QUESTION: Why not these ComboBoxes 1 and 2 are not moving to .SelectedIndex
= -1 too (when AddNew) ?
- All these six ComboBoxes are populated like this same way ...

daArticleTypes = New OleDbDataAdapter(New OleDbCommand("SELECT ID,
ArticleType, Description FROM ARTICLE_TYPES", cnn))
daArticleTypes.Fill(ds, "ArticleTypes")

- Even their source table in database is quite similar ...

ID AutoNumber int
ArticleType nvarchar
Description nvarchar

.... only 'ArticleType' - field has another name in other database tables
because all those tables are storing other kind of basic list.
- All ComboBoxes are bound like this same way ...

cboCombo1.DataSource = ds.Tables("ArticleTypes")
cboCombo1.DisplayMember = "ArticleType"
cboCombo1.ValueMember = "ID"
cboCombo1.DataBindings.Add("SelectedValue", ds, "Products.ArticleTypeID")
- I show ToolTip for the user by the following way in every ComboBoxes ...

Private Sub cboCombo1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboCombo1.SelectedIndexChanged
Dim cb As ComboBox = CType(sender, ComboBox)

If cb.SelectedIndex > -1 Then
ToolTip1.SetToolTip(cb,
ds.Tables("ArticleTypes").Rows(cb.SelectedIndex).I tem("Description").ToStrin
g)
Else
ToolTip1.SetToolTip(cb, Nothing)
End If
End Sub

Hopefully you understand what I'm trying to ask :)

--
Thanks for your help in advance!

Mika
Nov 20 '05 #1
5 1590
Hi Mika,

Set a breakpoint immediately after cbocombo1.selectedindex = -1 just to see
if it goes to -1 (empty) for an instant; if this is the case (I'm guessing
it is), then it is code that follows this code that is resetting combos 1
and 2 to another index.

HTH,

Bernie Yaeger

"Mika M" <mika .m a h o n e n@kolumbus.fi> wrote in message
news:uc**************@TK2MSFTNGP11.phx.gbl...
Hello!

I have Windows Forms application form containing TextBoxes, six ComboBoxes, and DataGrid for details. I have created DataSet with needed tables, and
created relations between tables, and bound controls to datatables.

Everything is working almost fine including saving data, but when I press
'New' - button ...

thisCurrencyManager.EndCurrentEdit()
thisCurrencyManager.AddNew()
cboComBo1.SelectedIndex = -1
cboComBo2.SelectedIndex = -1
cboComBo3.SelectedIndex = -1
cboComBo4.SelectedIndex = -1
cboComBo5.SelectedIndex = -1
cboComBo6.SelectedIndex = -1

...to add new entry, only ComboBoxes 3 to 6 are moving to .SelectedIndex
= -1, but ComboBoxes 1 and 2 to .SelectedIndex = 0 ?!?

QUESTION: Why not these ComboBoxes 1 and 2 are not moving to ..SelectedIndex = -1 too (when AddNew) ?
- All these six ComboBoxes are populated like this same way ...

daArticleTypes = New OleDbDataAdapter(New OleDbCommand("SELECT ID,
ArticleType, Description FROM ARTICLE_TYPES", cnn))
daArticleTypes.Fill(ds, "ArticleTypes")

- Even their source table in database is quite similar ...

ID AutoNumber int
ArticleType nvarchar
Description nvarchar

... only 'ArticleType' - field has another name in other database tables
because all those tables are storing other kind of basic list.
- All ComboBoxes are bound like this same way ...

cboCombo1.DataSource = ds.Tables("ArticleTypes")
cboCombo1.DisplayMember = "ArticleType"
cboCombo1.ValueMember = "ID"
cboCombo1.DataBindings.Add("SelectedValue", ds, "Products.ArticleTypeID")
- I show ToolTip for the user by the following way in every ComboBoxes ...

Private Sub cboCombo1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboCombo1.SelectedIndexChanged
Dim cb As ComboBox = CType(sender, ComboBox)

If cb.SelectedIndex > -1 Then
ToolTip1.SetToolTip(cb,
ds.Tables("ArticleTypes").Rows(cb.SelectedIndex).I tem("Description").ToStrin g)
Else
ToolTip1.SetToolTip(cb, Nothing)
End If
End Sub

Hopefully you understand what I'm trying to ask :)

--
Thanks for your help in advance!

Mika

Nov 20 '05 #2
> Set a breakpoint immediately after cbocombo1.selectedindex = -1 just to
see
if it goes to -1 (empty) for an instant; if this is the case (I'm guessing
it is), then it is code that follows this code that is resetting combos 1
and 2 to another index.
Hello Bernie, and thank you for your reply!

Yes I tried that already, but it's not the reason for the problem. I tried
to create 'ArticleTypes' - table into DataSet using SELECT-sql query of the
other working ComboBox, and then it was working ok, except using wrong
database table :'(.

Weird because source tables in database are identical, except
'ArticleType'-Column Name is not same, but field types and properties are.
I'm using MS SQL 2K version 8.00.760 database. I think there's something
weird with database.
HTH,

What does this abbreviation means? Here in Finland we don't have much
abbreviations. In fact our words are quite long :)

-- Mika
Nov 20 '05 #3
Hi Mika,

HTH means 'hope this helps'.

OK, let's see - is the field name 2 words? If it is, you should bracket it
([....]) in the select. Also, try another field from the table in question;
any field, just to see if it's the field or the table that's causing the
problem.

Can you send me an .xml of the tables in question? If you can, I would try
to replicate the conditions on my system.

HTH,

Bernie

"Mika M" <m i k a .ma*****@kolumbus.fi> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
Set a breakpoint immediately after cbocombo1.selectedindex = -1 just to see
if it goes to -1 (empty) for an instant; if this is the case (I'm guessing it is), then it is code that follows this code that is resetting combos 1 and 2 to another index.


Hello Bernie, and thank you for your reply!

Yes I tried that already, but it's not the reason for the problem. I tried
to create 'ArticleTypes' - table into DataSet using SELECT-sql query of

the other working ComboBox, and then it was working ok, except using wrong
database table :'(.

Weird because source tables in database are identical, except
'ArticleType'-Column Name is not same, but field types and properties are.
I'm using MS SQL 2K version 8.00.760 database. I think there's something
weird with database.
HTH,

What does this abbreviation means? Here in Finland we don't have much
abbreviations. In fact our words are quite long :)

-- Mika

Nov 20 '05 #4
Hello Bernie, and thank you for your reply again!

Today I noticed when I pressed 'New'-button twice, then those two problem
ComboBoxes also changed to

..SelectedIndex = -1.

In this case when adding new, DataAdapters Update will insert one empty line
and one with forms data into databases parent/master table. Then I added two
lines for these problem ComboBoxes like ...

thisCurrencyManager.EndCurrentEdit()
thisCurrencyManager.AddNew()
cboCombo1.SelectedIndex = -1
cboCombo1.SelectedIndex = -1
cboCombo2.SelectedIndex = -1
cboCombo2.SelectedIndex = -1
cboCombo3.SelectedIndex = -1
cboCombo4.SelectedIndex = -1
cboCombo5.SelectedIndex = -1
cboCombo6.SelectedIndex = -1

.... well, this is not very clever way to solve this :) but it works - but
why like this way ?!?

In fact I have also 6 x Grid components on the separate TabPages in the
bottom of the same form for the details (maybe too many for same form, I
have to think this solution again). Pressing once 'New'-button AddNew causes
that 3 Grid components clears, but when 'New'-button again then all grids
are empty - but like few lines above mentioned - DataAdapters Update will
insert one empty line and one with forms data into databases parent/master
table. Any ideas how to try to solve this?

--
Thanks for your reply in advance!

Mika
Nov 20 '05 #5
Hi Mika,

No, I wouldn't do that - you're creating empty rows, and that will surely
get you into trouble down later on. I would rather suggest that you go back
to the original code and work with one combobox and one column at a time
until you identify the problem.

Sorry I don't have any better ideas.

Bernie

"Mika M" <mika .m a h o n e n@kolumbus.fi> wrote in message
news:uw**************@TK2MSFTNGP12.phx.gbl...
Hello Bernie, and thank you for your reply again!

Today I noticed when I pressed 'New'-button twice, then those two problem
ComboBoxes also changed to

.SelectedIndex = -1.

In this case when adding new, DataAdapters Update will insert one empty line and one with forms data into databases parent/master table. Then I added two lines for these problem ComboBoxes like ...

thisCurrencyManager.EndCurrentEdit()
thisCurrencyManager.AddNew()
cboCombo1.SelectedIndex = -1
cboCombo1.SelectedIndex = -1
cboCombo2.SelectedIndex = -1
cboCombo2.SelectedIndex = -1
cboCombo3.SelectedIndex = -1
cboCombo4.SelectedIndex = -1
cboCombo5.SelectedIndex = -1
cboCombo6.SelectedIndex = -1

... well, this is not very clever way to solve this :) but it works - but
why like this way ?!?

In fact I have also 6 x Grid components on the separate TabPages in the
bottom of the same form for the details (maybe too many for same form, I
have to think this solution again). Pressing once 'New'-button AddNew causes that 3 Grid components clears, but when 'New'-button again then all grids
are empty - but like few lines above mentioned - DataAdapters Update will
insert one empty line and one with forms data into databases parent/master
table. Any ideas how to try to solve this?

--
Thanks for your reply in advance!

Mika

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John | last post by:
Hi, In my years as a VB programmer, I have settled into this pattern of creating collections classes, with an AddNew() method. AddNew() validates the parameters, instantiates the object, adds...
1
by: Stephen.Hunter | last post by:
Hello Everybody (anybody)? I am trying to appent a combobox to include data entered by a user which is Not In List. I have came accross this code from Allen Browne which seems to be what I am...
4
by: Mika M | last post by:
Hello! I'm using VB.NET 2003 and Windows Forms application type. Question: Why ComboBoxes are not changing their arrearance to XP-Styles look althought other UI Components does when I use the...
1
by: Bruce | last post by:
Hi, there, I meet a problem about comboBox binding. -------------------- Database: Northwind Tables: 1) Products 2) Categories I create a form (named "form1") to edit the record from...
2
by: Nate | last post by:
I have used the feedback on this issue to remedy my comboboxes showing the first item on the list when a new record is added to the binding context --- Me.BindingContext(dsOrders,...
2
by: Crazy Cat | last post by:
I am using a data-bound combobox with dropdownstyle set to dropdownlist. Teh combobox is bound to a bindingsource which is in turn bound to a table in my database. The table has only 4 rows and I...
8
by: MLH | last post by:
Here's a snippet from A97 HELP on AddNew... The record that was current before you used AddNew remains current. If you want to make the new record current, you can set the Bookmark property to...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
4
by: EManning | last post by:
I have a combobox whose rowsource is a union query. This query displays a person's name in "lastname, firstname" format and in "firstname lastname" format. The query results look like this: ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.