15,920,708 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 15154225 (Top 6 by date)
Member 15154225
28-Jul-22 15:00pm
View
The 'data type' is 'bit' for this column in SSMS. In VS, it shows 'System.Boolean'. I have the following code:
foreach(DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[6].Value != null)
{
if ((bool)row.Cells[6].Value)
{
row.Cells[3].Value = null;
}
}
}
When I execute, it returns the error:
- $exception {"Specified cast is not valid."} System.InvalidCastException
Is it a problem that the majority of these rows are NULL and not 0 or 1?
Member 15154225
28-Jul-22 14:47pm
View
It looks like it's classified as 'bit'.
Member 15154225
28-Jul-22 14:42pm
View
I'm not sure what the problem is. Now that I've modified my code based on your latest response, I'm receiving the error:
- $exception {"Specified cast is not valid."} System.InvalidCastException
Member 15154225
28-Jul-22 14:12pm
View
I am still experiencing the same issue with the code you outline above. Say there are 150 rows returned and I check the bool (column 6) in row 51, it turns all rows in column 3 blank (null) when I'm only aiming to nullify column 3 for row 51.
Member 15154225
28-Jul-22 13:52pm
View
Sorry, what I meant is that when I started, I knew that the columns were addressed beginning with zero, as I addressed them in a separate piece of code, as such, but mistakenly started at one later on in my code. Thanks for pointing this out.
I'm not sure how to write it without the snippet of code you reference. I've also tried what is shown below, but when I check a single cell in column six, every cell in column three goes null. I'm trying to keep it to the respective row.
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
if (dataGridView1.Rows[i].Cells[6].Value != null)
{
dataGridView1.Rows[i].Cells[3].Value = null;
}
}
Member 15154225
28-Jul-22 13:37pm
View
Thanks for pointing out such a novice mistake! :) And, to think, I address them as zero through six above in my code. However, now that I've fixed that, if I check any box in column six, it nullifies EVERYTHING in column 3. :\
Show More