locked
grid view cell header ????????? RRS feed

  • Question

  • hello to all respected expert,

            Actually I Need to place the header text in the each grid view cells ..Is it possible or not ?? please explain me..

    Monday, September 17, 2012 9:39 AM

Answers

  • ... to the heading of the column? What would that suppose to mean?  Sorry but you are still unclear...

    Maybe:

    If you mean to "combine" data from 1st six columns to 7th column, then you can do:

    List<string> list =new List<string>();
    for(int i=0;i<dgv.Rows.Count;i++)
    {
       list.Clear();
       for(int j=0;j<dgv.Columns.Count -1;j++) //note:this will not count the last - 7th column!
       {
           list.Add(dgv[j,i].Value.ToString());
       }
       //add data from list to 7th column
       dgv[6,i].Value = string.Join(", ", list.ToArray()); //split data by comma and a white space!!
    }


    Mitja

    Tuesday, September 18, 2012 7:37 AM

All replies

  • For column1:

    dgv.Columns[0].HederText = "new header text";
    Do the same for other columns.

    Mitja

    Monday, September 17, 2012 10:11 AM
  • thanks for reply,

                              Actually i want to give the header text for each cells,not the columns. Is it possible or not??

    Monday, September 17, 2012 10:46 AM
  • You mean to pass the headerText of each column to all the rows bellow?

    Like:

    for(int i=0;i<dgv.Rows.Count;i++)
    {
        for(int j=0;j<dgv.Columns.Count;j++)
        {
            dgv[j,i].Value = dgv.Columns[j].HeaderText;
        }
    }
    

    This will populate all the cells in all the rows with the header text from the columns.


    Mitja

    • Proposed as answer by Spartan_578 Tuesday, September 18, 2012 6:09 AM
    Monday, September 17, 2012 1:11 PM
  • thanx for reply sir,

                     Actually I have a gridview bind with sql command,and after binding it have 7 columns in it

    Its a daily report based records.so first 6 columns are  related to the single task description data and seventh column is mainly the daily report about task.

    now I merge the data for first six column  and collectively show in first column and hide the other columns..

    Now my admins told that he need this merge data in the heading of the status column cell that is the cell number 7.

    I need to put for every row the data from first six column to the heading of the seventh column..

    so is this possible??

    thanks again  sir.....

    Tuesday, September 18, 2012 6:39 AM
  • ... to the heading of the column? What would that suppose to mean?  Sorry but you are still unclear...

    Maybe:

    If you mean to "combine" data from 1st six columns to 7th column, then you can do:

    List<string> list =new List<string>();
    for(int i=0;i<dgv.Rows.Count;i++)
    {
       list.Clear();
       for(int j=0;j<dgv.Columns.Count -1;j++) //note:this will not count the last - 7th column!
       {
           list.Add(dgv[j,i].Value.ToString());
       }
       //add data from list to 7th column
       dgv[6,i].Value = string.Join(", ", list.ToArray()); //split data by comma and a white space!!
    }


    Mitja

    Tuesday, September 18, 2012 7:37 AM