ReoGrid Forum

Fast and powerful .NET Spreadsheet Component

You are not logged in.

Announcement

This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.

https://github.com/unvell/ReoGrid/issues

#1 2015-11-08 21:16:44

CopyPaul
Member
Registered: 2015-09-21
Posts: 19

Correcting referencing selected row across classes.

Hi,

I am using 0.9

I am building a jobs application (c#)

I have a form that is invoked when I want to change/delete a job. On that form I have a reogrid and I expect the user to click on a row to select a job. After I capture the click event I have to return a static class variable which can be referenced in another class, which displays the selected job and all the job items (on another grid) to allow changing and/or confirm deletion.

I've looked at the events documentation and was not able to see how to to accomplish this.

Thanks in advance

Paul

Offline

#2 2015-11-09 01:10:28

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: Correcting referencing selected row across classes.

Hi Paul, there is several approach to achieve your target, below are the tips.

Method 1

1.1. Making full row selection only

worksheet.SelectionMode = WorksheetSelectionMode.Row;

1.2. Adding cell mouse up event handler

worksheet.CellMouseUp += (s,e)=>{
  // get the row number 
  MessageBox.Show("Row index " + e.CellPosition.Row + " selected");
};

295.png

More about selection control: https://reogrid.net/document/selection/

Method 2

Add check boxes at first cell for every row and handle the CheckChanged event of checkbox

for (int r = 1; r < 6; r++)
{
	var cb = new CheckBoxCell();

	cb.CheckChanged += (s, e) =>
	{
		if (cb.Checked)
		{
			MessageBox.Show("Row index " + cb.Cell.Position.Row + " selected");
		}
	};

	worksheet[r, 0] = cb;
}

296.png

More about cell types: https://reogrid.net/document/built-in-cell-types/
and column cell type: https://reogrid.net/document/row-and-column/

Jing

Offline

#3 2015-11-09 18:32:41

CopyPaul
Member
Registered: 2015-09-21
Posts: 19

Re: Correcting referencing selected row across classes.

Thanks as always for the prompt reply.

I am having some problems implementing your suggestions.

If I try method 1

var sheet = grid1.CurrentWorksheet;
sheet.SelectionMode = WorksheetSelectionMode.Row;

I get Error:    The name 'WorksheetSelectionMode' does not exist in the current context
I've tried just the enum "Row" but get the same or similar error

And 1.2 ... create the event

  private void grid1_MouseUp(object sender, MouseEventArgs e)
        {
            var worksheet = grid1.CurrentWorksheet;
            worksheet.CellMouseUp += (s, e) =>{
                // get the row number  ----- above line is line 201
                selectedRow = e.CellPosition.Row;
//                MessageBox.Show("Row index " + e.CellPosition.Row + " selected");
            };
        }

I get the error:
A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else    F:\vs\Projects\anotes\anotes\JobSheet.cs    201
I've tried renaming the parameter but got similar errors (tried ev and evm)

Method 2 left me a little confused.

You are creating a checkChanged event for the checkBox.  In the event you entered a value of < 6 (hardcoded) and at the end you tell that column 0 for each line will hold the checkbox.  I thought I had to define the checkbox position on the load Event for the form and I don't know the upper limit of rows filled out during the program execution (unless there is a call that returns this value.

Sorry, if this is trivial but I could not find the answer in the documentation, and I am using 0.9

Paul

Offline

#4 2015-11-09 22:37:53

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: Correcting referencing selected row across classes.

CopyPaul wrote:

I get Error:  The name 'WorksheetSelectionMode' does not exist in the current context

Make sure you have added namespace declaration.

using unvell.ReoGrid;
CopyPaul wrote:

A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e'
...
I've tried renaming the parameter but got similar errors (tried ev and evm)

Renaming should fix this error. You have another variable 'e' in outside scope. If error still happen, please post your code.

CopyPaul wrote:

I thought I had to define the checkbox position on the load Event for the form and I don't know the upper limit of rows filled out during the program execution (unless there is a call that returns this value.

You maintains a job list so I think you should have a variable to save the number of current jobs. When add a job, +1 for the variable, when remove a job, then -1.
How to know the number of jobs is by your design, but if you really can't get such a number, you could to check every row to see whether the row has content like job name, if the row has job name, then add a checkbox for the row at 0 column.

Good Luck. Jing

Offline

#5 2015-11-10 00:42:21

CopyPaul
Member
Registered: 2015-09-21
Posts: 19

Re: Correcting referencing selected row across classes.

Jing, I already had reference(s) to reogrid on that form, and I am still having the errors. You are right I can keep tabs on the number of jobs populating the grid, when I load them in my application, I am not adding/changing/deleting the jobs on this form it is just invoked when a user wants to retrieve a specific job, and the job id is passed back to the invoking class. The errors occur in my JobSheet class. To make it easier for you to debug I am emailing you a zipped file of my VS project.

I just thought that it would be nice to provide the number of the "highest" populated row on a sheet via the API

Paul

Offline

#6 2015-11-10 07:08:26

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: Correcting referencing selected row across classes.

I have checked your project.

Problem 1: Is WorksheetSelectionMode not WorkSheetSelectionMode

Problem 2: Just rename second e

+= (s, e) =>{ 
to
+= (s, e1) =>{

Don't rename MouseEventArgs e to MouseEventArgs e1, you make them same again.

ReoGrid has property MaxContentRow and MaxContentCol that return the number of last data row, but I saw you are getting job list from database, the best way is to get number of jobs from database like:

select count(*) from dbo.Jobs

Jing

Offline

#7 2015-11-10 20:59:12

CopyPaul
Member
Registered: 2015-09-21
Posts: 19

Re: Correcting referencing selected row across classes.

Thank you Jing, this took care of the issue.

I am developing for a windows server while the application is being developed and debugged.

Once this is done I'd like to port it to the web. I understand reogrid is not web compatible. (I'll port my code to ASPX and I know Microsoft has a grid view). Do you have plans on porting it to the web.

I understand that the original project was linux/unix based.

Paul

Offline

#8 2015-11-11 07:50:40

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: Correcting referencing selected row across classes.

You're welcome. There is no plan for ReoGrid to development a web version of this control. At present, ReoGrid has an ability to convert a worksheet into HTML grid view. That maybe you could have a try.

worksheet.ExportAsHTML(htmlStream, ...)

Document at: https://reogrid.net/document/export-as-html/

Offline

Board footer

Powered by FluxBB