Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2007, 03:56 AM
Authorized User
 
Join Date: Mar 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to erictamlam Send a message via MSN to erictamlam Send a message via Yahoo to erictamlam
Default DataGridViewCheckBoxColumn Value Problem

Hey exports
I dragged a DataGridView on form and it was already successfully connected to database.Then I added a column to DataGridView like this:

DataGridViewCheckBoxColumn aColumn= new DataGridViewCheckBoxColumn();
            aColumn.ThreeState = false;
            dataGridView1.Columns.Add(aColumn );

How can I get the value of this newly added column?I mean I thought there should be certain property like "checked" to examine if a row in DataGridView is checked.But it seems there wasn't. How could it be called "DataGridViewCheckBoxColumn" without even a property like "checked"?It would have made things so much easier.
I wanna update the checked row into database without those unchecked ones....so I need to judge the value of the cell containing DataGridViewCheckedBox to see if it's checked...How can I make it?
"Value" property can be helpful only when I use it like this:
if(dataGridView1.Rows[i].Cells[3].Value.ToString() == "True")
   .......
any easier way?
Thanks for your kind help,I really appreaciate it...kinda urgent,sorry.


ERIC
__________________
ERIC
 
Old April 23rd, 2007, 07:40 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I haven't worked with this much, but....

I think the cells collect of a row is a collection of base cell types. Your cell 3 may very well be a checkbox cell, but the collection doesn't know that because it has to support all possible cell types. You may be able to cast that cell to a checkbox cell (I don't know the exact syntax) and that class should have a "checked" or similar property.

-Peter
 
Old April 23rd, 2007, 10:01 AM
Authorized User
 
Join Date: Mar 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to erictamlam Send a message via MSN to erictamlam Send a message via Yahoo to erictamlam
Default

There is an object like "DataGridViewCheckBoxCell".But it still has no property like "checked".
DataGridViewCheckBoxCell acell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[3];
.....
I searched online and there is a solution like this:

   If checkBoxCell IsNot Nothing Then
        If checkBoxCell.ValueType.Equals(GetType(Boolean)) Then
            Dim checked As Boolean = CType(checkBoxCell.Value, Boolean)
        Else
            ' checkBoxCell may have 3 states instead.
        End If
    Else
        ' Current cell is not a DataGridViewCheckBoxCell.
    End If

I haven't tried it yet.Maybe it works.But it's still an indirect way,I think!
any other better ways?
LOTS APPRECIATION

ERIC





Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridViewCheckBoxColumn as a Check Box Supriya.Karagave C# 2005 3 February 15th, 2008 05:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.