473,570 Members | 2,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ...

thisCurrencyMan ager.EndCurrent Edit()
thisCurrencyMan ager.AddNew()
cboComBo1.Selec tedIndex = -1
cboComBo2.Selec tedIndex = -1
cboComBo3.Selec tedIndex = -1
cboComBo4.Selec tedIndex = -1
cboComBo5.Selec tedIndex = -1
cboComBo6.Selec tedIndex = -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 OleDbDataAdapte r(New OleDbCommand("S ELECT ID,
ArticleType, Description FROM ARTICLE_TYPES", cnn))
daArticleTypes. Fill(ds, "ArticleTyp es")

- 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.DataS ource = ds.Tables("Arti cleTypes")
cboCombo1.Displ ayMember = "ArticleTyp e"
cboCombo1.Value Member = "ID"
cboCombo1.DataB indings.Add("Se lectedValue", ds, "Products.Artic leTypeID")
- I show ToolTip for the user by the following way in every ComboBoxes ...

Private Sub cboCombo1_Selec tedIndexChanged (ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles cboCombo1.Selec tedIndexChanged
Dim cb As ComboBox = CType(sender, ComboBox)

If cb.SelectedInde x > -1 Then
ToolTip1.SetToo lTip(cb,
ds.Tables("Arti cleTypes").Rows (cb.SelectedInd ex).Item("Descr iption").ToStri n
g)
Else
ToolTip1.SetToo lTip(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 1603
Hi Mika,

Set a breakpoint immediately after cbocombo1.selec tedindex = -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******** ******@TK2MSFTN GP11.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 ...

thisCurrencyMan ager.EndCurrent Edit()
thisCurrencyMan ager.AddNew()
cboComBo1.Selec tedIndex = -1
cboComBo2.Selec tedIndex = -1
cboComBo3.Selec tedIndex = -1
cboComBo4.Selec tedIndex = -1
cboComBo5.Selec tedIndex = -1
cboComBo6.Selec tedIndex = -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 OleDbDataAdapte r(New OleDbCommand("S ELECT ID,
ArticleType, Description FROM ARTICLE_TYPES", cnn))
daArticleTypes. Fill(ds, "ArticleTyp es")

- 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.DataS ource = ds.Tables("Arti cleTypes")
cboCombo1.Displ ayMember = "ArticleTyp e"
cboCombo1.Value Member = "ID"
cboCombo1.DataB indings.Add("Se lectedValue", ds, "Products.Artic leTypeID")
- I show ToolTip for the user by the following way in every ComboBoxes ...

Private Sub cboCombo1_Selec tedIndexChanged (ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles cboCombo1.Selec tedIndexChanged
Dim cb As ComboBox = CType(sender, ComboBox)

If cb.SelectedInde x > -1 Then
ToolTip1.SetToo lTip(cb,
ds.Tables("Arti cleTypes").Rows (cb.SelectedInd ex).Item("Descr iption").ToStri n g)
Else
ToolTip1.SetToo lTip(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.selec tedindex = -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*****@kolumb us.fi> wrote in message
news:uH******** ******@TK2MSFTN GP09.phx.gbl...
Set a breakpoint immediately after cbocombo1.selec tedindex = -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 ...

thisCurrencyMan ager.EndCurrent Edit()
thisCurrencyMan ager.AddNew()
cboCombo1.Selec tedIndex = -1
cboCombo1.Selec tedIndex = -1
cboCombo2.Selec tedIndex = -1
cboCombo2.Selec tedIndex = -1
cboCombo3.Selec tedIndex = -1
cboCombo4.Selec tedIndex = -1
cboCombo5.Selec tedIndex = -1
cboCombo6.Selec tedIndex = -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******** ******@TK2MSFTN GP12.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 ...

thisCurrencyMan ager.EndCurrent Edit()
thisCurrencyMan ager.AddNew()
cboCombo1.Selec tedIndex = -1
cboCombo1.Selec tedIndex = -1
cboCombo2.Selec tedIndex = -1
cboCombo2.Selec tedIndex = -1
cboCombo3.Selec tedIndex = -1
cboCombo4.Selec tedIndex = -1
cboCombo5.Selec tedIndex = -1
cboCombo6.Selec tedIndex = -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
1370
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 it to the collection, and returns it. The AddNew() method was used to get around the lack of a constructor in VB classes. Now I was just about to...
1
2036
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 looking for can anybody tell me if I have to change any of the code below to match field names or combobox name from my own database. Thanks in...
4
3198
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 following code in my Sub Main ... System.Windows.Forms.Application.EnableVisualStyles() System.Windows.Forms.Application.DoEvents()
1
2617
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 Products table.
2
2842
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, "tblOrders").AddNew() Me.ComboBox1.SelectedIndex = -1 but... how do we deal with the same issue during record navigation? When I move forward or backward onto a...
2
1949
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 am using it to display geographical regions - Northeast, Southeast, West, and Central. In the bindingsource AddNew is set to false. Whenever I...
8
2339
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 the bookmark identified by the LastModified property setting. My own experience is indicating that the newly added record becomes current during...
2
8655
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 list of values from a table, and as the user selects values, a datagrid displays related records from another table because it is bound via FK...
4
4955
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: Mouse, Mickey Mickey Mouse When a person is added, the querys' underlying recordset is updated in the NotInList event. I can't figure out how to...
0
7732
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7703
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3671
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2136
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.