How to create Editable Cell in DataGrid in Windows Mobile

No.of Views5827
Bookmarked0 times
Downloads 
Votes0
By  RRaveen   On  25 Apr 2011 05:04:15
Tag : Windows Mobile , Grid Controls
In this code snippet, i will show how to create Editable Cell in DataGrid in Windows Mobile.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In one of my project, i want to edit cell in DataGrid in .NET Compact Framework.The .NET CF is did not built features to editable cell in datagrid.So i would like to implement this features with MSDN help.

Implementation

The implementation is very simple, Firstlly we have to add a textbox into form and rename "txtEPQTY" and then make it visible false and then place DataGrid Control in form add few columns as well.

Now when user focus the cell in datagrid, i'm going to replace by textbox and make it visible to enter the value and then when fouse lost assign value to Cell and make textbox is visible false.

Code

DataGridCell editCell;
        bool isEditPQTY = false;
        bool isUpdateCurrentCell = false;

        private void grdItems_CurrentCellChanged(object sender, EventArgs e)
        {
           
                if (!isUpdateCurrentCell)
                {
                    if (isEditPQTY && !grdItems.CurrentCell.Equals(editCell))
                    {
                        isUpdateCurrentCell = true;
                        grdItems.Visible = false;
                        DataGridCell currentCell = grdItems.CurrentCell;
                        grdItems[editCell.RowNumber, editCell.ColumnNumber] = txtEPQTY.Text;
                        grdItems.CurrentCell = currentCell;
                        grdItems.Visible = true;
                        isUpdateCurrentCell = false;
                        txtEPQTY.Visible = false;
                        isEditPQTY = false;
                    }

                    editCell = grdItems.CurrentCell;
                    txtEPQTY.Text = grdItems[editCell.RowNumber, editCell.ColumnNumber].ToString();
                    Rectangle cellPos = grdItems.GetCellBounds(editCell.RowNumber, editCell.ColumnNumber);
                    txtEPQTY.Left = cellPos.Left - 1;
                    txtEPQTY.Top = cellPos.Top + grdItems.Top - 1;
                    txtEPQTY.Width = cellPos.Width + 2;
                    txtEPQTY.Height = cellPos.Height + 2;
                    txtEPQTY.Visible = true;
                    isEditPQTY = true;
                }
            }
           
        }

That's all, just copy and paste this code and run it.

 
Sign Up to vote for this article
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popularSectionarticles
Comments
By:KarthikDate Of Posted:7/9/2014 6:21:52 AM
L.Karthikeyan
Thanks for your code. Your code very much helpful for my project
By:smartDate Of Posted:7/23/2012 11:58:28 AM
thnx man
thnx for ur code, i hope to find more about datagrid in wnindow CE , ....... ^_^
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top
</