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 October 8th, 2007, 03:24 AM
Registered User
 
Join Date: Oct 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hyder_master Send a message via Yahoo to hyder_master
Default HOW CHAGE VALUES IN CELLS DYNAMICALLY dATAGRIDVIEW

I HAVE A DATAGRIDVIEW BINDED TO A DATATABLE AND GRIDSETTINGS IS

//---------------------------------------------------------------------------------------------------------------------------------------------------
    DataGridView1.Datasource = MyDatatable;
            DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
            DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Sunken;
            DataGridView1.Font = new Font("Times New Roman", 10);
            DataGridView1.AllowUserToResizeRows = false;
           DataGridView1.RowsDefaultCellStyle.BackColor = Color.GreenYellow;
           DataGridView1.RowsDefaultCellStyle.ForeColor = Color.Blue;
            DataGridView1.MultiSelect = false;
           DataGridView1.RowHeadersVisible = false;
            DataGridView1.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            DataGridView1.Columns[5].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
//-------------------------------------------------------------------------------------------------------------------------------------------------------
the last column is a check box column which is defined in datatable as
dtexam.Columns[7].DataType = System.Type.GetType("System.Boolean");

//------------------------------------------------------------------------------------------------------------------------------------------------------------
I WANT THAT WHEN USER CLICK ON CHECK BOX COLUMN IF IT IS CHECKED THE COLUMN 5 SHOULD BE SET TO ZERO IN THE SAME ROW . I M USING THIS CODE AT CELLCLICK
//--------------------------------------------------------------------------------------------------------------------------------------

 try
            {
                int crow = DataGridView1.CurrentRow.Index;
                string fl = DataGridView1.CurrentRow.Cells[7].Value.ToString();
                Boolean bl = Boolean.Parse(fl);
                if (bl == true)
                {
                    //dgvexam.CurrentCell = dgvexam.SelectedCells[5];
                         DataGridView1.Rows[crow][5] = "0";

                }
            }
            catch
            { }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

but there is problem with this code that value desnot set to zero when cell is checked but sets to zero when I chaNge the row or I access the cell to which I want to assign value

please help me



hyder_master
 
Old October 9th, 2007, 04:13 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Click a cell does not change the value of the "Value" property, only moving out of that cell does.

Check the documentation for DataGridViewCheckBoxCell for details of how to get around this restriction by committing the changes in the CurrentCellDirtyStateChanged event.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
cells values with validation in another cell srahuf Excel VBA 1 May 30th, 2008 04:05 AM
how to add from text values into excel cells kotaiah Excel VBA 2 September 12th, 2006 10:55 AM
Dynamically generated textboxes and their values Frode ASP.NET 2.0 Basics 1 April 17th, 2006 03:46 PM
update values of changed cells into database using changusee2k PHP Databases 0 March 9th, 2006 01:05 PM





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