To enter data into a RadGridView cell?

1 Answer 100 Views
GridView
kim
Top achievements
Rank 1
kim asked on 13 Jul 2022, 04:32 PM

 

Hello, Telerik users.

There is one problem with me. Data must be entered in each corresponding cell, but data cannot be entered. 
I couldn't find the reason. 
The source code is below.

It's a red syntax, but it doesn't work. Do you know why?

I really hope we can solve this problem. 
Thank you.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Collections;

namespace TEST
{
    public partial class ViewerControl2 : UserControl
    {
        protected bool IsDesignMode { get { return DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime; } }
        private const int ROWCOUNT = 100;
        private const int COLUMNCOUNT = 100;

        public ViewerControl2()
        {
            try
            {
                InitializeComponent();
                if (IsDesignMode) return;

                SetLayout();
                SetEventHandler();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        private void SetLayout()
        {
            try
            {
                this.radGridView1.ShowGroupPanel = false;
                this.radGridView1.VirtualMode = true;
                this.radGridView1.RowCount = 5;
                this.radGridView1.ColumnCount = 19;
                //this.radGridView1.BackColor = Color.Transparent;
                this.radGridView1.ReadOnly = true;
                this.radGridView1.TableElement.DrawFill = false;
                this.radGridView1.TableElement.RowHeight = 50;
                this.radGridView1.TableElement.CellSpacing = 0;
                this.radGridView1.MasterTemplate.ShowRowHeaderColumn = true;
                this.radGridView1.MasterTemplate.ShowColumnHeaders = true;
                this.radGridView1.MasterTemplate.AllowAddNewRow = false;

                createData();

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void SetEventHandler()
        {
            try
            {
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void createData()
        {

            string getData = "SEND;BIT;1;0;0;1;1;0;1;1;1;1;1;1;1;1;1;1;1;1;0;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;0;1;1;1;1;1;1;1;1;1;1;1;0;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;0;0;1;1;1;0";

            string[] spstring = getData.Split(';');

            int dataLength = (spstring.Length - 2);

            int horizontal_length = dataLength / 5;

            string[,] lineData = new string[5, horizontal_length];

            int startData = 2;

            for (int j = 0; j < horizontal_length; j++) {

                for (int i = 4; i > -1; i--) {

                    lineData[i, j] = spstring[startData++];

                }
            }

            for (int i = 0; i < 5; i++) {

                for (int j = 0; j < horizontal_length; j++) {

                    this.radGridView1.Rows[i].Cells[j].Style.CustomizeFill = true;

                    this.radGridView1.Rows[i].Cells[j].Style.DrawFill = true;

                    this.radGridView1.Columns[j].HeaderText = j.ToString();

                    if (lineData[i, j] == "1") {

this.radGridView1.Rows[i].Cells[j].Value = 1;
                        this.radGridView1.Rows[i].Cells[j].Style.BackColor = Color.Green;

                    } else {

this.radGridView1.Rows[i].Cells[j].Value = 0;
                        this.radGridView1.Rows[i].Cells[j].Style.BackColor = Color.Black;

                    }
                }
            }
        }
    }
}

                                                                                           

1 Answer, 1 is accepted

Sort by
0
Maria
Telerik team
answered on 14 Jul 2022, 12:23 PM

Hello Kim,

According to the code snippet you provided, I can see that the VirtualMode property is set to true. For virtual mode you should have two events which I don't see in the presented code - CellValueNeeded and CellValuePushed which are responsible for loading the data in RadGridView and pushing it back to the external source collection after editing a cell. Additional information how to properly use the virtual mode is available here:

https://docs.telerik.com/devtools/winforms/controls/gridview/virtual-mode/virtual-mode 

To be honest, for so few rows and columns, it is not necessary to use the virtual mode at all. It is appropriate to use either bound mode or unbound mode for populating the grid control with data.

Off topic, I have also noticed that the ReadOnly property is enabled which does not allow you to edit the cells in the RadGridView. I am not sure whether it is intended but make sure that it is with the expected value for your scenario. 

I hope this is helpful, don't hesitate to write if you have any more questions.

Regards,
Maria
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
kim
Top achievements
Rank 1
Answers by
Maria
Telerik team
Share this question
or