Scroll Element of the WPF C#Datagrid class

Asked

Viewed 172 times

2

I have a function that creates a grid, But I don’t know how to get that value, the function is down here:

using System.Windows.Controls;

     public override FrameworkElement criar()
        {
          if (formulario == null)
            return null;

          DataGrid    grid = new DataGrid();
          ContextMenu menu = new ContextMenu();


          definirStyle(grid, "tema.estiloGradeDados");
          definirBinding(grid, DataGrid.ItemsSourceProperty, "dados", true);

          grid.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
          grid.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;

          grid.GroupStyle.Add(new GroupStyle() {ContainerStyleSelector = new SeletorEstiloItemGrupo() });
          grid.ContextMenu = menu;

          grid.Height = 800;

          foreach (DskCampo campo in dskFormulario.campos)
          {
            criarItemMenu(menu, campo);
            criarColuna  (grid, campo);
          }

          return grid;
        }

Does the Datagrid scroll descend from "Scrollviewer"? How do I manipulate it?

  • The DataGrid has an event Scroll, he doesn’t help? system.windows.Forms.datagrid.scroll

  • No, this library uses Forms, and I am using the "System.Windows.Controls" Datagrid https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid(v=vs.110). aspx

2 answers

0

Datagrid has a property called Scrollviewer, in it you can add the scroll event (Scrollchanged) and has several properties: Contentverticaloffset, and several others related to size and vertical scroll.

Source: Scrollviewer.Contentverticaloffsetproperty Field

  • My question is exactly how to get this property then, given my function above. I can’t find any example on how to do this.

0

At your event ScrollChanged, you can use the code below:

int AlturaTotal = 0;
foreach (DataGridViewRow row in grid.Rows){
    AlturaTotal += row.Height;
}

if (AlturaTotal - grid.Height < grid.VerticalScrollingOffset)
{
    //quando entrar aqui é por que chegou na ultima linha
}
  • I am using the Datagrid of Controls and not Forms, these properties do not exist in System.Windows.Controls;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.