1
Answer

Fixed header in a gridview (both horizontally and vertically)

jesbon

jesbon

15y
7.6k
1

Hi,
How to get a fixed header both horizontally and vertically in a gridview?
 
I have my gridview located in a scrollable (auto) panel control and want to have the header row fixed. I want it always visible and when I scroll horizontally I want that the header row should follow so that I can see headers for columns all the time.
 
I have just found solutions for making the header row fixed vertically but I need it to be fixed both vertically and horizontally. Any ideas/solutions is highly appreciated. 
Answers (1)
0
Vulpes

Vulpes

NA 98.3k 1.5m 10y
Assuming all numeric columns are of type double, then try:

   foreach(DataRow dr in table1.Rows)
   {
      string colName = dr["Par Name"].ToString();
      if(table5.Columns.Contains(colName))
      {
         double lower = (double)dr["lower_limit"];
         double upper = (double)dr["upper_limit"];
         double min = table5.Rows.Cast<DataRow>().Min(r => r.Field<double>(colName));
             
         if (min >= lower)
         {
            double max = table5.Rows.Cast<DataRow>().Max(r => r.Field<double>(colName));
            if (max <= upper) table5.Columns.Remove(colName);
         }
      }
   }

or, if they're all strings, try:

   foreach(DataRow dr in table1.Rows)
   {
      string colName = dr["Par Name"].ToString();
      if(table5.Columns.Contains(colName))
      {
         double lower = double.Parse(dr["lower_limit"].ToString());
         double upper = double.Parse(dr["upper_limit"].ToString());
         double min = table5.Rows.Cast<DataRow>().Min(r => double.Parse(r.Field<string>(colName)));
             
         if (min >= lower)
         {
            double max = table5.Rows.Cast<DataRow>().Max(r => double.Parse(r.Field<string>(colName)));
            if (max <= upper) table5.Columns.Remove(colName);
         }
      }
   }

Accepted
0
Farhan Shariff

Farhan Shariff

NA 1.1k 111.4k 10y
Thank you vulpes . works perfect only  thing is I had to remove the last three columns from table5 (Split , Die_id and normal inverse), since I am adding it later again no problem :)
0
Khan Abrar Ahmed

Khan Abrar Ahmed

NA 5.8k 200k 10y
Hi,
what basis u want to match the rows?? please explain little bit more.