Click here to Skip to main content
16,017,261 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
In the name Of God

hi
i want to split a cell to multiple rows in gridline
for example a person has several job i want to show it in one row with all his job
it means all his job show in cell which taged with job
if you know suitable software or know good solution i need your help

sample:

name------job
jhon------programmer
----------shopkeeper
----------driver
Posted
Updated 8-Jun-14 6:37am
v3
Comments
DamithSL 8-Jun-14 12:39pm    
how you bind data can you update the code and add more details about controls you using, what kind of a program this is (winform asp.net etc..)
roza54 8-Jun-14 12:41pm    
winform
Richard MacCutchan 8-Jun-14 12:40pm    
This is not a good question. We have no idea what you mean by "gridline", what control you are using, where the data is coming from, how your code identifies the various parts of the record etc.
roza54 8-Jun-14 12:44pm    
data are in database sqlserver2012
Richard MacCutchan 8-Jun-14 12:45pm    
How very interesting. And how do you think that makes anything more clear?

1 solution

when fill grid (in fill grid function) you need loop datatable rows and checks when repeated the ID(Primary), and store it in temporary variable then compare it with another rows in datatable when equal use string builder to append all job data inside it.

then bind datatable to your grid.

Ex.
C#
DataTable dt = all data from database;
DataTable dtCurrent = new DataTable();
bool found = false;
dtCurrent = dt;
for (int i=0 ; i< dt.rows.count;i++)
{
  int ID = dt.rows(i)("ID");
  //you need another for loop to compare temporary data with another in the same grid.
  //here you can use list<string> or arraylist to add job data.
  List<string> lst = new List<string>;
  for (int j=0; j<dt.rows.count;>  {
    if (dt.rows(j)("ID") == ID)
     lst.Add(row(j)("JobName"));
  }
  //don't forget using System.Text
  StringBuilder str = new StringBuilder();
  for(int l =0; i<lst.count;>  {
    str.AppendFormat("{0},",lst(l).ToString(),Environment.NewLine);
  }

  for(int current = 0; current < dtCurrent.rows.count; current++)
  {
     if(dtCurrent.rows(current)("ID") == ID && found == false)
     {
       found = true;
       dtCurrent(current)("JobName") = str.ToString();
     }

     if (found)
     {
       if(dt.rows(current)("ID") == ID)
       {
         dt.rows(current).delete();
       }
     }
  }
}

grid.datasource = dt;</string></string></string>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900