Highlight the row and column headers for the active cell

Posted by: bdota on 8 September 2017, 2:25 pm EST

  • Posted 8 September 2017, 2:25 pm EST

    I want to Highlight the row and column headers for the active cell.. well it id done automatically

    but my problem is that I have a SPAN for my row headers : each two header rows are spanned to look like one row

    and there are situations in the program that because of that I cannot easily read the row number and determine which row and column to highlight by checking odd/even numbers of rows,etc... 

    any thought?!

     

    thanks all 

  • Replied 8 September 2017, 2:25 pm EST

    Hello,

    Please have a look at the attached sample wherein we are able to get the row and column index even if the Row and Column Headers are spanned on the click of a button. Have a look at the same and let us know if it helps you.

    Thanks.


    2010/08/SpanningInRowAndColumnHeader.zip
  • Replied 8 September 2017, 2:25 pm EST

    Thanks,

     well your example has the same problem...

    I attached a screen shot of it that shows the problemo

     http://i38.tinypic.com/2zxnxwp.png

     

     when we click on the cell that I have written "good" in it, the highlight is Good but when we click on the cell that I have written "bad" in it, the highlight is wrong! I want the same  things be highlighted as I were clicking on the "good" cell ... 

    In my own real example I do not even have those borders between rows IF I am spanning the row headers for those rows.. so if I am spanning row header 1 and 2, then the rows 1 and two are also spanned.\\

     

     

    thanks 

  • Replied 8 September 2017, 2:25 pm EST

    Hello,

    Please have a look at the modified attached sample and let us know If I am able to comprehend your issue correctly or not?

    As
    you have said that in your own real example you do not have those
    borders between rows, i.e. you are spanning two columns in row headers
    as i have done in my modified attached sample and on clicking the cell
    having  text "Bad" you are not able to highlight the RowHeader (Branch
    #1), it only gets highlighted when you click on the cell having having
    text "Good".

    Please let us know if this is your issue in order to proceed further. Thanks.
    2010/08/SpanningInRowAndColumnHeader-2.zip
  • Replied 8 September 2017, 2:25 pm EST

    thanks for following this question :)

    well Ok I think I did not describe it very good last time:

    Case1: I am only spanning the row headers: each two row headers are showing as one. but the normal rows of the spread are as their normal shape. so the border Exists..just as always... : in this case since each row header is taking two  rows, so when I click on either row 1 or 2,   the correct row and column header should be highlighted... if I click on row 3 or 4 the correct row and column header should be highlighted...

    same as the pic in this link : http://img3.imageshack.us/img3/6969/96597354.png

      

  • Replied 8 September 2017, 2:25 pm EST

    Hello,

    Please have a look at the modified sample wherein we are able to highlight the correct column and row header when we click either on row 1 or row 2 by checking the row index and work accordingly.

    Have a look at the sample and let us know if it helps. Thanks.


    2010/08/SpanningInRowAndColumnHeaderModified.zip
  • Replied 8 September 2017, 2:25 pm EST

    Thank a lot 

    in this version you are using the row even/odd numbers which I mentioned in my initial post :

    quote: "and there are situations in the program that because of that I cannot easily read the row number and determine which row and column to highlight by checking odd/even numbers of rows,etc"

    so if I want to decide based on the row numbers - being odd, even - for highlighting, then there might be problems... OK finally I could put my thoughts together to describe the situation.

    here is a sample situation I will have, all together in one spread sheet

    a) row headers 1 and 2 : span them together ... but their rows are Not spanned ... but either I click on row 1 or row 2 : we want the same highlighted row and column headers as I described before.

    b)  row headers 1 and two are spanned together ... Also their rows Are spanned together .... so the highlight should work correctly 

    c) row headers are Not spanned,  their rows are not spanned either .. like a default behavior of  the spreadsheet... 

     

    that's why I think if I go with the even/odd route , it gets confused and will not highlight correctly.

     

    Thanks  again 

     

  • Replied 8 September 2017, 2:25 pm EST

    Hello,

    Please find below the modified code wherein I am able to highlight the correct ColumnHeader and RowHeader depending on the cell being selected. Here all the possible spanning as mentioned by you in your previous code have been done and the code has been modified to highlight the ColumnHeader and RowHeader separately.

            private void button1_Click(object sender, EventArgs e)

            {

     
                MessageBox.Show(fpSpread1.ActiveSheet.ActiveCell.Row.Index + " , " + fpSpread1.ActiveSheet.ActiveCell.Column.Index);

                if (fpSpread1.ActiveSheet.ActiveCell.Row.Index % 2 > 0)

                {

                    fpSpread1.ActiveSheet.RowHeader.Rows[fpSpread1.ActiveSheet.ActiveRowIndex - 1].BackColor = Color.Green;

                }

                else

                {

                    fpSpread1.ActiveSheet.RowHeader.Rows[fpSpread1.ActiveSheet.ActiveRowIndex].BackColor = Color.Green;

                }

     
                if (fpSpread1.ActiveSheet.ActiveCell.Column.Index % 2 > 0)

                {

                    fpSpread1.ActiveSheet.ColumnHeader.Columns[fpSpread1.ActiveSheet.ActiveColumnIndex - 1].BackColor = Color.Green;

                }

                else

                {

                    fpSpread1.ActiveSheet.ColumnHeader.Columns[fpSpread1.ActiveSheet.ActiveColumnIndex].BackColor = Color.Green;

                }

     
            }

            private void Form1_Load(object sender, EventArgs e)

            {

                // Set the number of rows in the column header.

                fpSpread1.ActiveSheet.ColumnHeader.RowCount = 2;

                // Set the number of columns in the row header.

                fpSpread1.ActiveSheet.RowHeader.ColumnCount = 2;

                // Define the labels for the spanned column header cells.

                fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 0].Text = "1st Quarter";

                fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 2].Text = "2nd Quarter";

                fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 4].Text = "3rd Quarter";

                fpSpread1.ActiveSheet.ColumnHeader.Cells[0, 6].Text = "4th Quarter";

                // Define the column header cell spans.

                fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(0, 0, 2, 2);

                fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(0, 2, 2, 2);

                fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(0, 4, 2, 2);

                fpSpread1.ActiveSheet.AddColumnHeaderSpanCell(0, 6, 2, 2);

                // Define the label for the spanned row header cells.

                fpSpread1.ActiveSheet.RowHeader.Cells[0, 0].Text = "Branch #1";

                fpSpread1.ActiveSheet.RowHeader.Cells[2, 0].Text = "Branch #2";

                fpSpread1.ActiveSheet.RowHeader.Cells[4, 0].Text = "Branch #3";

                fpSpread1.ActiveSheet.RowHeader.Cells[6, 0].Text = "Branch #4";

                fpSpread1.ActiveSheet.RowHeader.Cells[8, 0].Text = "Branch #5";

                // Define the row header cell span.

                fpSpread1.ActiveSheet.AddRowHeaderSpanCell(0, 0, 2, 2);

                fpSpread1.ActiveSheet.AddRowHeaderSpanCell(2, 0, 2, 2);

                fpSpread1.ActiveSheet.AddRowHeaderSpanCell(4, 0, 2, 2);

                fpSpread1.ActiveSheet.AddRowHeaderSpanCell(6, 0, 2, 2);

     
                fpSpread1.ActiveSheet.AddRowHeaderSpanCell(8, 0, 2, 2);

                fpSpread1.ActiveSheet.Cells[8, 0].RowSpan = 2;

     
                fpSpread1.ActiveSheet.AddRowHeaderSpanCell(8, 2, 2, 2);

                fpSpread1.ActiveSheet.Cells[8, 2].RowSpan = 2;

            }

    Let us know if it helps you, else please send us a sample replicating the issue with all possible spanning in cells, RowHeader or ColumnHeader which you have done for us to proceed further on this issue and provide you with a solution.

    Thanks.

  • Replied 8 September 2017, 2:25 pm EST

    and maybe some code like this -  not perfect yet -  does the job?   

     

     fpSpread1.ActiveSheet.RowHeader.Rows[e.Row].BackColor = Color.Yellow;

                fpSpread1.ActiveSheet.ColumnHeader.Columns[e.Column].BackColor = Color.Green; 

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels