473,666 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridViewCom boBoxColumn return wrong index.

1 New Member
I have a datagridview containing a datagridviewcom bobox.
The combobox has a dataset containing city_name and city_id.
When I select a new city_name in the combobox I would like to return the city_id corresponding to that city_name.

Code:

//City ComboBox
comboboxCity.Da taPropertyName = "city_name" ;
comboboxCity.He aderText = "City";
comboboxCity.Da taSource = city_table;
comboboxCity.Va lueMember = "city_name" ;
comboboxCity.Di splayMember = comboboxCity.Va lueMember;
comboboxCity.Na me = "comboboxCi ty";
dgvVSK.Columns. Insert(20, comboboxCity);

This is the code where I retrieve the selected index after selecting a new city in the combobox.

Code:

private void comboboxControl Showing(object sender, DataGridViewEdi tingControlShow ingEventArgs e)
{
comboBox1 = e.Control as ComboBox;

if (comboBox1 != null)
{
comboBox1.Selec tedIndexChanged += new EventHandler(co mboBox1_Selecte dIndexChanged);

}
}


private void comboBox1_Selec tedIndexChanged (object sender, EventArgs e )
{
if (comboBox1 != null)
{
dgvVSK.Rows[dgvVSK.Selected Rows[0].Index].Cells["city_id"].Value = ((ComboBox)send er).SelectedInd ex.ToString();
}
}

I do return the selectedindex for that combobox. But it does not correspond to the city_id but to the table row index.

Thanks,
Pierre
Apr 17 '09 #1
1 2713
Bassem
344 Contributor
dgvVSK.Rows[dgvVSK.Selected Rows[0].Index].Cells["city_id"].Value = ((ComboBox)send er).SelectedInd ex.ToString();
Maybe this is the probelm else do,
dgvVSK.Rows[dgvVSK.Selected Rows[0].Index].Cells["city_id"].Value = ((ComboBox)send er).SelectedVal ue.ToString();
Apr 18 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3456
by: Shawn | last post by:
I am trying to use a DataGridView to display one column of textboxes with a single value from a query and then next to it have a combobox that displays results from another query. What happens is the second query just returns 1 value to each combobox. So, in other words, for each textbox, the next result of the second query puts 1 value in the corresponding combobox. Here is my code... What the heck am I doing wrong???? cmd =...
3
22142
by: Rain County | last post by:
I am programmatically building and populating a table and then making it the data source for a dataGridView. I want to add a column to the dataGridView which will be a DataGridViewComboBoxColumn. I wish to populate, by default, all of the ComboBoxes with the same list of three choices. How do I add the DataGridViewComboBoxColumn, and do I first populate one as a template for the others? I will appreciate any help.
4
7553
by: John | last post by:
Hi, I've been trying to populate a DataGridViewComboBoxColumn with objects. The object is defined as : private struct manufactItem { public string name; public Guid? man_id;
0
2958
by: Simon Tamman | last post by:
How do other people get around having to define the ValueMember in a DataGridViewComboBoxColumn when binding to a list of business objects? I'm currently doing the following, and it feels wrong and woefully misguided. public class SomeClass { private string name;
0
2206
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application). All classes that implement this interface are shown in a drop down in a DataGridViewComboBoxColumn named Validator. By choosing the class to validate this specific data in the drop downbox IValidator<T>.Validate is called and returns true/false....
1
2144
by: sklett | last post by:
I have a DataGridView bound to a custom business object. The business object has 2 attributes that are FKs to a lookup table (think HairColorID, EyeColorID, etc) For these 2 columns I have created DataGridViewComboBoxColumn and hooked them up to BindingSources that populate them with the lookup table's value (in edit mode) When editing a row and selecting one of the item from the DataGridViewComboBoxColumn cell, the value that is...
0
2003
by: =?ISO-8859-2?B?UmFmYbMgR2llemdhs2E=?= | last post by:
I have: protected void InitControls() { gvProfile.AutoGenerateColumns = false; DataTable dtProfile = new DataTable("KFS"); // dodajemy kolumny foreach(DataGridViewColumn dc in gvProfile.Columns) { DataColumn ndc = new DataColumn();
0
1923
by: ajey | last post by:
hi all! Im doing a windows application (C#), i have a datagridview bound from a Sql database in which i want one column to be ComboBox.I use DataGridViewComboBoxColumn and bind that column value.... Now the problem is when i change the value in the DataGridViewComboBoxColumn it is reloading the datagrid and pointing to another cell containing the selected value... how can i make this function like a normal combobox... thanks in advance...
1
5319
by: =?Utf-8?B?RWQgQ29oZW4=?= | last post by:
I have tried to use the DataGridComboBoxColumn object with limited success. What I want to do is to create one new unbound column to be a combo box (so far, this has worked), populate it with items from the database (this also has worked). But, now I want to be able to have the user select one of the items in that combo box and fire off an event to select more data from the database based on what the user selected in the combo box. Well,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.