473,396 Members | 2,070 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,396 software developers and data experts.

Databound combobox, new and selected value confusion.

I have a combobox that is very much like the one found in the RSS
project here:
http://msdn.microsoft.com/vstudio/ex...harp/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 relationship.

My table:
/****** Object: Table [dbo].[ProjectNames] Script Date: 06/19/2006
19:46:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProjectNames](
[ProjectName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
CONSTRAINT [PK_ProjectNames] PRIMARY KEY CLUSTERED
(
[ProjectName] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
I have the combobox bound to projectNamesBindSource, and projectNames
is the single column of names of projects. Display Member and Value
Member are both bound to ProjectName, which is the column in the
ProjectNames table. I have added the below code to allow me to add a
new record. When the user clicks the AddButton a blank item is
displayed in the combobox, the users cursor is placed into the
combobox, and when they finish typing and press enter my intention is
to add a new record to the table. I have not added all the updating
and error checking code as of yet. Whenever the user presses enter,
then the call to EndEdit() produces an exception: "Column 'ProjectName'
does not allow
nulls."

I can fix this by binding the combobox Text property to the
ProjectNames column. However, I get a new exception whenever selecting
items in the combo box:
"Column 'ProjectName' is constrained to be unique. Value
'SomeProjectName' is already present."

It appears when I select a different item in the combobox, then it is
trying to use the new text value to update the previously select
record. Since my column requires unique values, then the update is not
possible.

The intention of selecting items in the combobox is that this effects
what is displayed by the seperate datagrid, which shows data in a table
on the many side of a many-to-one relationship with the ProjectNames
table by binding to the FK relationship.

So either:

I need to implement a replacement for the text binding behavior when
adding new items and updating items, so that I can remove the text
binding.

OR

I need to make sure when I select a different item, the selected record
is chosen, rather than the combobox thinking I'm trying to update the
current record with a new value selected from the combobox.

OR

Anything else someone might suggest.

private void addButton_Click(object sender, EventArgs e)
{
projectNamesBindingSource.AddNew();
projectNameComboBox.Focus();
}

private void projectNameComboBox_KeyUp(object sender,
KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
projectNamesBindingSource.EndEdit();
}
}

Jun 20 '06 #1
2 8636
The SelectionChangeCommitted event for the combobox occurs before the
exception, so I guess I need to put into that event handler something
that will go ahead and move to the selected record. That way when the
databound Text property tries to write to the current record, then it
will write to the one it already belongs to.

I'm not really sure how to do this though.
sh******@cs.fsu.edu wrote:
I have a combobox that is very much like the one found in the RSS
project here:
http://msdn.microsoft.com/vstudio/ex...harp/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 relationship.

My table:
/****** Object: Table [dbo].[ProjectNames] Script Date: 06/19/2006
19:46:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProjectNames](
[ProjectName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
CONSTRAINT [PK_ProjectNames] PRIMARY KEY CLUSTERED
(
[ProjectName] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
I have the combobox bound to projectNamesBindSource, and projectNames
is the single column of names of projects. Display Member and Value
Member are both bound to ProjectName, which is the column in the
ProjectNames table. I have added the below code to allow me to add a
new record. When the user clicks the AddButton a blank item is
displayed in the combobox, the users cursor is placed into the
combobox, and when they finish typing and press enter my intention is
to add a new record to the table. I have not added all the updating
and error checking code as of yet. Whenever the user presses enter,
then the call to EndEdit() produces an exception: "Column 'ProjectName'
does not allow
nulls."

I can fix this by binding the combobox Text property to the
ProjectNames column. However, I get a new exception whenever selecting
items in the combo box:
"Column 'ProjectName' is constrained to be unique. Value
'SomeProjectName' is already present."

It appears when I select a different item in the combobox, then it is
trying to use the new text value to update the previously select
record. Since my column requires unique values, then the update is not
possible.

The intention of selecting items in the combobox is that this effects
what is displayed by the seperate datagrid, which shows data in a table
on the many side of a many-to-one relationship with the ProjectNames
table by binding to the FK relationship.

So either:

I need to implement a replacement for the text binding behavior when
adding new items and updating items, so that I can remove the text
binding.

OR

I need to make sure when I select a different item, the selected record
is chosen, rather than the combobox thinking I'm trying to update the
current record with a new value selected from the combobox.

OR

Anything else someone might suggest.

private void addButton_Click(object sender, EventArgs e)
{
projectNamesBindingSource.AddNew();
projectNameComboBox.Focus();
}

private void projectNameComboBox_KeyUp(object sender,
KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
projectNamesBindingSource.EndEdit();
}
}


Jun 20 '06 #2
Well enough shooting around in the dark and I finally hit the solution.
Added this to the SelectionChangeCommitted handler.

projectNamesBindingSource.Position = projectNameComboBox.SelectedIndex;
sh******@cs.fsu.edu wrote:
The SelectionChangeCommitted event for the combobox occurs before the
exception, so I guess I need to put into that event handler something
that will go ahead and move to the selected record. That way when the
databound Text property tries to write to the current record, then it
will write to the one it already belongs to.

I'm not really sure how to do this though.
sh******@cs.fsu.edu wrote:
I have a combobox that is very much like the one found in the RSS
project here:
http://msdn.microsoft.com/vstudio/ex...harp/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 relationship.

My table:
/****** Object: Table [dbo].[ProjectNames] Script Date: 06/19/2006
19:46:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ProjectNames](
[ProjectName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
CONSTRAINT [PK_ProjectNames] PRIMARY KEY CLUSTERED
(
[ProjectName] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
I have the combobox bound to projectNamesBindSource, and projectNames
is the single column of names of projects. Display Member and Value
Member are both bound to ProjectName, which is the column in the
ProjectNames table. I have added the below code to allow me to add a
new record. When the user clicks the AddButton a blank item is
displayed in the combobox, the users cursor is placed into the
combobox, and when they finish typing and press enter my intention is
to add a new record to the table. I have not added all the updating
and error checking code as of yet. Whenever the user presses enter,
then the call to EndEdit() produces an exception: "Column 'ProjectName'
does not allow
nulls."

I can fix this by binding the combobox Text property to the
ProjectNames column. However, I get a new exception whenever selecting
items in the combo box:
"Column 'ProjectName' is constrained to be unique. Value
'SomeProjectName' is already present."

It appears when I select a different item in the combobox, then it is
trying to use the new text value to update the previously select
record. Since my column requires unique values, then the update is not
possible.

The intention of selecting items in the combobox is that this effects
what is displayed by the seperate datagrid, which shows data in a table
on the many side of a many-to-one relationship with the ProjectNames
table by binding to the FK relationship.

So either:

I need to implement a replacement for the text binding behavior when
adding new items and updating items, so that I can remove the text
binding.

OR

I need to make sure when I select a different item, the selected record
is chosen, rather than the combobox thinking I'm trying to update the
current record with a new value selected from the combobox.

OR

Anything else someone might suggest.

private void addButton_Click(object sender, EventArgs e)
{
projectNamesBindingSource.AddNew();
projectNameComboBox.Focus();
}

private void projectNameComboBox_KeyUp(object sender,
KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
projectNamesBindingSource.EndEdit();
}
}


Jun 20 '06 #3

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

Similar topics

8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
2
by: jan v | last post by:
Hi everyone. I have a user control with 2 comboboxes these comboboxes are Databound to the same datatable.. Wheb 1 add 2 of thos usercontrols (not the comboboxes but the usercontrol itself) to...
0
by: John Smith | last post by:
Hello all: Another day another problem :). How do you synch a databound combobox with the rest of the controls that are on a form. I have a combobox that lists a bunch of names and upon...
0
by: Ken Arway | last post by:
Using .Net framework 1.1 I've got a Windows Forms application with a tab control having four tab pages. TabPage4 contains a Combobox and a TextBox, which are bound to the same XML file as a...
6
by: Johann Blake | last post by:
I fill a table in a dataset with values that will be used by a combobox for the combobox's items. The combobox is a drop down list that only allows the user to select from the list but not enter...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
9
by: Jakob Lithner | last post by:
1) I have a DataGridView with edit capability. But in some columns I want to limit the input with a DropDownList. There is no inbuilt column for DropDownLists so I intended to add one myself. I...
3
by: Benny | last post by:
Does anyone know how I would go about adding a blank value to the list of items in a ComboBox that has a set datasource? Thank in advance!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.