473,657 Members | 2,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about DataGridViewCom boBoxCell

i want a editable comboboxcell for a datagridview, i have done these:

[dgvConfigShow is a DataGridView]

public partial class Form1 : Form
{
....
private static List<string_tem pList = new List<string>(ne w string[]
{});
....
private void lbTypes_Selecte dIndexChanged(o bject sender, EventArgs e)
{
foreach(...)
{
int newRowIndex = dgvConfigShow.R ows.Add();
DataGridViewRow newRow = dgvConfigShow.R ows[newRowIndex];

DataGridViewCel l dgvcellCategory Name =
newRow.Cells["dgvcolCategory Name"];
dgvcolCategoryN ame.DataSource = _tempList;
}
}
....
private void dgvConfigShow_E ditingControlSh owing(object sender,
DataGridViewEdi tingControlShow ingEventArgs e)
{
DataGridViewCom boBoxEditingCon trol comboControl = e.Control as
DataGridViewCom boBoxEditingCon trol;
if (comboControl != null)
if (comboControl.D ropDownStyle != ComboBoxStyle.D ropDown)
comboControl.Dr opDownStyle = ComboBoxStyle.D ropDown;
}
....
private void dgvConfigShow_C ellValidating(o bject sender,
DataGridViewCel lValidatingEven tArgs e)
{
DataGridViewCom boBoxCell cell = dgvConfigShow.C urrentCell as
DataGridViewCom boBoxCell;
if (cell == null) return;

string curVal = e.FormattedValu e as string;
if (!String.IsNull OrEmpty(curVal) && !_tempList.Cont ains(curVal))
_tempList.Add(c urVal);

cell.Value = curVal;
}
....
}

everything goes fine until i try this:

input "a" into row 1 <-_tempList = ["a"]

input "b" into row 2 <-_tempList = ["a", "b"]

input "a" into row 1 <-_tempList = ["a", "b"]

input/select "b" on row 1 <-_tempList = ["a", "b"] but meanwhile
raised the well-known exception (DataGridViewCo mboBoxCell: Value is
not valid)

any idea, please?

Mar 17 '07 #1
1 6441
On 3ÔÂ17ÈÕ, ÏÂÎç11ʱ58·Ö, "aXqd" <axqd...@gmail. comwrote:
i want a editable comboboxcell for a datagridview, i have done these:

[dgvConfigShow is a DataGridView]

public partial class Form1 : Form
{
...
private static List<string_tem pList = new List<string>(ne w string[]
{});
...
private void lbTypes_Selecte dIndexChanged(o bject sender, EventArgs e)
{
foreach(...)
{
int newRowIndex = dgvConfigShow.R ows.Add();
DataGridViewRow newRow = dgvConfigShow.R ows[newRowIndex];

DataGridViewCel l dgvcellCategory Name =
newRow.Cells["dgvcolCategory Name"];
dgvcolCategoryN ame.DataSource = _tempList;}
}

...
private void dgvConfigShow_E ditingControlSh owing(object sender,
DataGridViewEdi tingControlShow ingEventArgs e)
{
DataGridViewCom boBoxEditingCon trol comboControl = e.Control as
DataGridViewCom boBoxEditingCon trol;
if (comboControl != null)
if (comboControl.D ropDownStyle != ComboBoxStyle.D ropDown)
comboControl.Dr opDownStyle = ComboBoxStyle.D ropDown;}

...
private void dgvConfigShow_C ellValidating(o bject sender,
DataGridViewCel lValidatingEven tArgs e)
{
DataGridViewCom boBoxCell cell = dgvConfigShow.C urrentCell as
DataGridViewCom boBoxCell;
if (cell == null) return;

string curVal = e.FormattedValu e as string;
if (!String.IsNull OrEmpty(curVal) && !_tempList.Cont ains(curVal))
_tempList.Add(c urVal);

cell.Value = curVal;

}
...
}

everything goes fine until i try this:

input "a" into row 1 <-_tempList = ["a"]

input "b" into row 2 <-_tempList = ["a", "b"]

input "a" into row 1 <-_tempList = ["a", "b"]

input/select "b" on row 1 <-_tempList = ["a", "b"] but meanwhile
raised the well-known exception (DataGridViewCo mboBoxCell: Value is
not valid)

any idea, please?
what i want is the datagridviewcom boboxcells of each row share the
same datasource, and each one of them is able to add items into the
common datasource by typing into/select the combobox.

Mar 17 '07 #2

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

Similar topics

0
3024
by: Moshazu | last post by:
I am attempting to use the DataGridView control in my software and have not been able to easily find answers to a couple of questions that I have. 1. Is the only way to change the data in a DataGridViewComboBox during the runtime the way that I have done it here? If not, is there an easier way? Dim tmpCMBRow As New DataGridViewRow tmpCMBRow.CreateCells(Me.grid)
0
3060
by: Jay | last post by:
I am using Windows .Net 2.0 SDK I have a DataGridView control in a windows form. None of my controls are databound prior to run time. I am creating a string array with which I want to populate each DataGridViewComboBoxCell programmatically. Some of the items in the comboboxcell controls may be the same, but most will not, so I can not populate the DataGridViewComboBoxColumn. I have tried adding rows to the datagrid using Rows.Add. I have...
2
8828
by: kofteros | last post by:
I have a DataGridView in which one of its columns is a DatagridViewCombobox. This column contains values as 1. "ROAMING" 2. "MOBILE" 3. "TELEPHONY"... I want to select an index from this DatagridViewComboboxCell programmatically, for example 2 ("MOBILE"). Is anyone knows an easy way of doing this. Thak you
1
23650
by: hangdee | last post by:
I have a DatagridviewComboBoxCell with self added object (with an id and a string field) as items to the DatagridviewComboBoxCell. Dim cboCell As New DataGridViewComboBoxCell cboCell.Items.Add(new MyObj(1,"Item 1")) cboCell.Items.Add(new MyObj(2,"Item 2")) cboCell.Items.Add(new MyObj(3,"Item 3")) But I cannot find a method from DataGridViewComboBoxCell to get back the selected MyObj in the cboCell list.
0
2142
by: Bruno Neves Pires Silva | last post by:
Hello, everybody. How can I get the selected item index in a DataGridViewComboBoxCell, in a datagridview?
0
3393
by: news.microsoft.com | last post by:
Hello- I'm having a dickens of a time trying to set the value on a DataGridViewComboBoxColumn. I actually have two DataGridViewComboBoxColumns in my datagrid view. First, I'm setting up the grid/column as follows.. DataGridViewComboBoxColumn someColumn = new DataGridViewComboBoxColumn();
0
2860
by: =?Utf-8?B?R2FkeUM=?= | last post by:
HI I populate one col. in a dataiewgrid with a combocell as DataGridViewComboBoxCell. (create on the fly and assign it to cell) I need to avid arrow user's up/down on that cells. All the grid events ignore edit state of combocell. Any idea? Thanks in advance.
1
3239
by: JB | last post by:
Hi All, Is there a way to programmatically open the drop down list of a DataGridViewComboBoxCell? Thanks JB
4
2714
by: Martin Horst | last post by:
Hi, I've got a Windows Form DataGridView with several DataGridViewComboBoxCell columns. The Items collection of the DataGridViewComboBoxCell can take any kind of objects. But when the user selects another item inside the combobox, the Value property always returns a string. In my case, I need the real object which was added to the items collections. Is there any way to prevent this conversion. Thanks in advance
0
8392
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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
8726
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...
0
8603
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...
1
6163
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
4151
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.