This is a migrated thread and some comments may be shown as answers.

Spreadsheet Control select a user's active cell/column

6 Answers 178 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 1
Nathan asked on 23 Aug 2019, 07:11 PM

I am having trouble just trying to get a user's currently selected cell when using this control.

https://docs.telerik.com/devtools/winforms/controls/spreadsheet/features/ui-working-with-selection.html

from this page I can't even get this to work with my control (Selection seems to not be found so I Underlined and Bolded it)

Selection selection_2 = this.radSpreadsheet.SpreadsheetElement.ActiveWorksheetEditor.Selection;

selection_2.Select(new CellIndex(0, 0), false);

yes I have all the required References added to my project and form.

 

6 Answers, 1 is accepted

Sort by
0
Nathan
Top achievements
Rank 1
answered on 23 Aug 2019, 07:29 PM

here is my code

Telerik.WinForms.Controls.Spreadsheet.Worksheets.Selection selection = this.radSpreadsheet1.SpreadsheetElement.ActiveWorksheetEditor.Selection;

MessageBox.Show(selection.ActiveCellIndex.ToString());

here is my build error

The type 'System.Windows.IWeakEventListener' is defined in an assembly that is not referenced. You must add a reference to assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.


0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Aug 2019, 06:11 AM

Hello, Nathan,  

Following the provided information, I was unable to reproduce the issue you are facing. Please refer to the following screenshot:

I have the following assemblies added to the project and it runs as expected:

  • Telerik.WinControls
  • Telerik.WinControls.RadSpreadsheet
  • Telerik.WinControls.UI
  • Telerik.Windows.Documents.Spreadsheet
  • TelerikCommon

You can find attached my sample project for your reference. Am I missing something? Do I need to perform any changes in order to replicate the problem you are facing?

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Nathan
Top achievements
Rank 1
answered on 26 Aug 2019, 12:25 PM

Interesting your project works fine for me.  I had to upgrade your project to 2018.2.621.  I run Telerik in VS 2013.  I don't have the Excel Ribbon in my other App.  I removed it from your app and it still works.  I also have plenty of other libraries.  Here is all the libraries I have included in my form.  Perhaps there is some conflict.  I look forward to your reply.

 

All my code & attached screenshots of the reference folder.  FYI Most is commented out.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Net;
using System.Text.RegularExpressions;
using Telerik.WinControls.UI;
using Telerik.WinControls.Spreadsheet;
using Telerik.Windows.Documents.Spreadsheet;
using Telerik.Windows.Documents.Core;
using Telerik.Documents.SpreadsheetStreaming;
using Telerik.Windows.Data;
using Telerik.Windows.Zip;
using Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx;
using System.IO;
using System.Windows;

 

    public partial class ToolsURLChecker : Telerik.WinControls.UI.RadForm
    {
        public ToolsURLChecker()
        {
            InitializeComponent();
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var formatProvider = new XlsxFormatProvider();
                using (Stream input = new FileStream(openFileDialog1.FileName, FileMode.Open))
                {
                    radSpreadsheet1.Workbook = formatProvider.Import(input);
                }
            }
        }

        private void ToolsURLChecker_Load(object sender, EventArgs e)
        {
            radSpreadsheet1.ElementTree.EnableApplicationThemeName = false;
        }

        private void btnPageTitles_Click(object sender, EventArgs e)
        {
            Telerik.WinForms.Controls.Spreadsheet.Worksheets.Selection selection = this.radSpreadsheet1.SpreadsheetElement.ActiveWorksheetEditor.Selection;
            MessageBox.Show(selection.ActiveCellIndex.ToString());
            //MessageBox.Show(radSpreadsheet1.ActiveSheet.Name);
           
            //{

            /*
            try
            {
                WebClient wc = new WebClient();
                string html = wc.DownloadString("https://Nathan.sertaretailers.com");

                Regex x = new Regex("<title>(.*)</title>");
                MatchCollection m = x.Matches(html);

                if (m.Count > 0)
                {
                     MessageBox.Show(m[0].Value.Replace("<title>", "").Replace("</title>", ""));
                }
                else
                     MessageBox.Show("");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not connect. Error:" + ex.Message);
            }
             */
            //}
        }

        private void btnStatusCodes_Click(object sender, EventArgs e)
        {
            /* 
            Uri urlCheck = new Uri("https://Nathan.sertaretailers.com");
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlCheck);
            request.Timeout = 15000;

            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
                MessageBox.Show("Code:  " + response.StatusCode + "  Desc:  " + response.StatusDescription);
                
            }
            catch (Exception)
            {
                MessageBox.Show("UH OH");
            }
            */
        }
    }

 

 

0
Nathan
Top achievements
Rank 1
answered on 26 Aug 2019, 01:01 PM

I added your form to my Project and it no longer works.

I get the same build error

Error1The type 'System.Windows.IWeakEventListener' is defined in an assembly that is not referenced. You must add a reference to assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.C:\Users\nathan.herritt\Google Drive\GWA_Projects\GWA_ERP\GWA_ERP\ToolsURLCheckerV2.cs2313GWA_ERP

 

0
Nathan
Top achievements
Rank 1
answered on 26 Aug 2019, 01:44 PM
oh my I was missing the reference to WINDOWSBASE.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Aug 2019, 10:15 AM
Hello, Nathan,  

I am glad that the problem you were facing is now resolved. Usually, the WindowsBase assembly is present in the project after creation of the form and adding the RadSpreadsheet control to it. Hence, it is not necessary to add it explicitly. I suppose that you have removed it by mistake once you dragged and dropped the control onto the form. 

Should you have further questions please let me know.

 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Nathan
Top achievements
Rank 1
Answers by
Nathan
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or