Category / Section
How to load a button below the SfDataGrid in RelativeLayout?
1 min read
A button can be loaded below the SfDataGrid in RelativeLayout by adding appropriate rules to the LayoutParameters of RelativeLayout.
Refer the below code in which a rule is added to LayoutParameters of RelativeLayout to align a button below the grid.
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); viewModel = new ViewModel(); grid = new SfDataGrid(this); add_row = new Button(this.BaseContext); grid.Id = 1; grid.ItemsSource = viewModel.Info; RelativeLayout relative = new RelativeLayout(this.BaseContext); RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); param.AddRule(LayoutRules.AlignBottom,1); relative.LayoutParameters = param; add_row.SetBackgroundColor(Color.Navy); add_row.Text = "Add Row"; add_row.Click += Add_row_Click; relative.AddView(grid, ViewGroup.LayoutParams.MatchParent, 1000); relative.AddView(button, param); SetContentView(relative); } private void Add_row_Click(object sender, System.EventArgs e) { viewModel.AddRow(); }
Screenshot
Sample Link
How to load a button below the SfDataGrid in RelativeLayout?