TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Željko Perić
411
3.8k
224.3k
How to change list of items inside DataGridViewComboBoxCell
Jun 21 2019 8:31 AM
Hello,
I am writing simple application that uses DataGridView control with ComboBoxColumn.
I have used this method to change list of items inside one cell of ComboBoxColumn :
void
Fill_Location()
{
DataGridViewComboBoxCell Location =
(DataGridViewComboBoxCell) DGV.Rows[0].Cells[1];
Location.Items.Clear();
string
a =
"hello"
;
Location.Items.Add(a);
}
When executed this method raises DataGridView Default Error Dialog with message:
The following exception occurred in the DataGridView
System.ArgumentException : DataGridViewComboBoxCell value is not valid.
To replace this default dialog please handle the DataError event.
So I have assigned to DGV this DataError event handler :
void
DGV_DataError(
object
sender, DataGridViewDataErrorEventArgs e)
{
MessageBox.Show(e.Context.ToString());
}
After that when executed method raises DataGridView DataError event handler with following message : Formatting, PreferredSize.
Since that I do not know how to resolve above error,
I have changed code for DataError event handler to :
void
DGV_DataError(
object
sender, DataGridViewDataErrorEventArgs e)
{
if
(e.Context== DataGridViewDataErrorContexts.Formatting)
e.ThrowException =
false
;
}
Now when executing method Fill_Location() list of items inside ComboBoxCell is changed as expected, and there is no any error message.
Is this correct use of DataError event handler for resolving this kind of problem,
or there can be some other hidden problems that currently are not evident ?
Program is written for .Net 4.0
All the best,
Željko Peric
Reply
Answers (
2
)
Connect with PVC Plastic Cards Printer using C#
I want to group by on one column in a C# datatable as below.