473,513 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about DataGridViewComboBoxCell

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_tempList = new List<string>(new string[]
{});
....
private void lbTypes_SelectedIndexChanged(object sender, EventArgs e)
{
foreach(...)
{
int newRowIndex = dgvConfigShow.Rows.Add();
DataGridViewRow newRow = dgvConfigShow.Rows[newRowIndex];

DataGridViewCell dgvcellCategoryName =
newRow.Cells["dgvcolCategoryName"];
dgvcolCategoryName.DataSource = _tempList;
}
}
....
private void dgvConfigShow_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewComboBoxEditingControl comboControl = e.Control as
DataGridViewComboBoxEditingControl;
if (comboControl != null)
if (comboControl.DropDownStyle != ComboBoxStyle.DropDown)
comboControl.DropDownStyle = ComboBoxStyle.DropDown;
}
....
private void dgvConfigShow_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
DataGridViewComboBoxCell cell = dgvConfigShow.CurrentCell as
DataGridViewComboBoxCell;
if (cell == null) return;

string curVal = e.FormattedValue as string;
if (!String.IsNullOrEmpty(curVal) && !_tempList.Contains(curVal))
_tempList.Add(curVal);

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 (DataGridViewComboBoxCell: Value is
not valid)

any idea, please?

Mar 17 '07 #1
1 6435
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_tempList = new List<string>(new string[]
{});
...
private void lbTypes_SelectedIndexChanged(object sender, EventArgs e)
{
foreach(...)
{
int newRowIndex = dgvConfigShow.Rows.Add();
DataGridViewRow newRow = dgvConfigShow.Rows[newRowIndex];

DataGridViewCell dgvcellCategoryName =
newRow.Cells["dgvcolCategoryName"];
dgvcolCategoryName.DataSource = _tempList;}
}

...
private void dgvConfigShow_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
DataGridViewComboBoxEditingControl comboControl = e.Control as
DataGridViewComboBoxEditingControl;
if (comboControl != null)
if (comboControl.DropDownStyle != ComboBoxStyle.DropDown)
comboControl.DropDownStyle = ComboBoxStyle.DropDown;}

...
private void dgvConfigShow_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
DataGridViewComboBoxCell cell = dgvConfigShow.CurrentCell as
DataGridViewComboBoxCell;
if (cell == null) return;

string curVal = e.FormattedValue as string;
if (!String.IsNullOrEmpty(curVal) && !_tempList.Contains(curVal))
_tempList.Add(curVal);

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 (DataGridViewComboBoxCell: Value is
not valid)

any idea, please?
what i want is the datagridviewcomboboxcells 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
3013
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...
0
3048
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...
2
8815
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...
1
23620
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...
0
2126
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
3374
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...
0
2846
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...
1
3230
by: JB | last post by:
Hi All, Is there a way to programmatically open the drop down list of a DataGridViewComboBoxCell? Thanks JB
4
2701
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...
0
7264
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,...
0
7166
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
7543
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
7534
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
5689
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,...
1
5094
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...
0
4749
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...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
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 ...

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.