Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datagridview needs to hide Scrollbar, but scroll should be achievable through code

I have 2 Datagrids with same number of columns

Datagrid1 is displaying only headers, Datagrid2 is just below it displaying all the data. In essence, the 2 grid's need to be synchronised to appear as 1 grid.

My issue here is I need to hide the horizontal scrollbar of datagrid1, but display only that for the datagrid2. When the user scroll's the datagrid2, I need to programmatically synchronise the headers on datagrid1.

Can anyone suggest?

like image 496
Kamath Avatar asked Jan 17 '23 02:01

Kamath


2 Answers

Try this..

dataGridViews1.ScrollBars = ScrollBars.None;

 private void dataGridViews2_Scroll(object sender, ScrollEventArgs e)
    {
       int offSetValue = dataGridViews1.HorizontalScrollingOffset;

      try 
          { 
            dataGridViews1.HorizontalScrollingOffset = offSetValue; 
          }
      catch { }

           dataGridViews1.Invalidate();
    }
like image 79
prabhuK2k Avatar answered Jan 31 '23 18:01

prabhuK2k


You can set the DataGridViews ScrollBasr property to hide vertical scrollbar

e.g.

dataGridViews1.ScrollBars = ScrollBars.None;

or see other enumeration value at link http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbars

like image 25
HatSoft Avatar answered Jan 31 '23 16:01

HatSoft