DevExpress GridControl BestFit | AutoSizeMode? - c#

I have 4 Dev Express Grid Columns (Two are not visible)
I'am trying to make the visible Columns like :
this.DataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
I tried the following :
gridView2.Columns["MyColumnB"].BestFit();
It works fine but is there is anyway so It dosen't get Width more then GridControl and don't get that Horizental ScrollBar ?
Sorry , Fixed using :
gridView2.OptionsView.ColumnAutoWidth = true;

Try this code which will tell the grid view to never display the horizontal scroll bar, then create the best fit columns for the entire grid view, instead of just doing so for a specific column.
gridView2.HorzScrollVisibility = ScrollVisibility.Never;
gridView2.BestFitColumns();

Related

Trying to fix this dataGridView column Autosizemode issue

I have this datagridview in C#. When I load the form and the data is loaded (data is loaded from SQL Server Database) in this datagridview, one of my column is not visible also the width of columns is not correct, but when I search something and that data is loaded in the datagridview then everything is perfect. I don't want the scrollbar in the datagridview.
The following images shows the difference.
One column "Description" is not shown.
How I want the datagridview to show the data
You can use this code to change the width of the column in DatagridView:
DatagridView.Columns[your columns index].Width = your size;
You can turn off the auto-size mode with this:
DatagridView.AutoSize = false;
I have fixed the issue by setting Autosizemode to NotSet in Layout for DataGridView columns and giving them custom width values.
When I run the application and the data is loaded in the DataGridView I set AutosizeMode for one column to Fill and everything is perfect.

Add new row at the top of grid without using row indicator

I have a button. When I click at it, a new row is added to the gridview and allow a user to edit in that row. How do I make new row appear in the first row?
It looks like the top most row in the following article but not
https://documentation.devexpress.com/#windowsforms/CustomDocument778
Currently, I did like the following code. It works but not good. With this solution, I also have a problem with scroll bar. If grid has many rows, the scroll bar will appear. Grid view will have a little blink when a new row is added because
it moves focus and scroll to last row -> last row is removed -> new row is added at the top -> move focus and scroll to top row
To disable scroll, I followed the article https://www.devexpress.com/Support/Center/Question/Details/CQ19190 to create a custom gridview. So far so good. But the problem is I do not want to custom grid. Does anybody have idea?
If I have to custom grid, how can I convert MainView to my custom grid at design mode?
- in design mode, click on MainView of grid view, then choose convert to ...-> custom grid view does not appear in the menu
Sample code
private void AddNewRow(GridView gv) {
gv.AddNewRow();
var row = gv.GetRow(GridControl.NewItemRowHandle);
var helper = new ListDataControllerHelper(gv.DataController);
// Binding list has a method InserAt(index, object), but in my case the object can not be created directly.
// Hence, I do not know what it is. I only get new object through gv.AddNewRow()
// I can work around by extending binding list
// but grid view does not support adding new row at specific position to adapt with InsertAt or my custom binding list
// It is not a good idea
helper.BindingList.Remove(row);
helper.BindingList.Insert(0, row);
gv.FocusedRowHandle = 0;
gv.SetFocusedRowModified();
}
I will appreciate all the help.
Thank you
If you simply want to add a row without your layout being updated automatically, try to suspend and resume the layout like so:
gv.SuspendLayout();
helper.BindingList.Remove(row);
helper.BindingList.Insert(0, row);
gv.FocusedRowHandle = 0;
gv.SetFocusedRowModified();
gv.ResumeLayout(true);
In general, your method of inserting a row seems fine.

How to make the columns fill a data grid view completely

I have 2 columns in my data grid view. But these 2 columns occupy only a portion of the view. How do i make both columns fill the view completely such first columns takes 50% space and second column takes the rest
Use
this.MyColumn1.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
this.MyColumn2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
Then play with property this.MyColumn2.FillWeight for your purpose...
In visual studio in the properties window, when you select the dataGridView go to the property AutoSizeColumnsMode and select the option Fill.
All the columns will fit all the place of the dataGridView.
Change the column width to fill e.g.
oColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
If you do this for all columns they will equally fill the grid (with or without the scrollbars). If you only sent if for 1 column that column will fill the remaining space leftover after all columns have been sized

WPF Make layout dynamically

I want to make layout dynamically.
For example, When I drag and drop a image, 1 image appears on the box.
When I drag and drop another image, box divide into 2 box (dynamically divide into two).
My question is, what layout should I use (stack panel, grid, or something else) and How to I make layout dynamically using code?
I know question is a little vague but I'm not so good at WPF so please understand Thx.
I would use a GridView and so you can add column or row.
DataGridViewTextBoxColumn trackPositionTextBox = new DataGridViewTextBoxColumn();
trackPositionTextBox.HeaderText = "Track Postion";
trackPositionTextBox.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewSamples.Columns.Add(trackPositionTextBox);
That's to add a Column in a DataGridView.
dataGridViewSamples.Row.Add()
That's to add a row.
I'm also not the best in wpf, but I hope it was helpful.
If you don't need any animation, you could simple add new columns and rows to your WPF-Grid, while drop an image.
Maybe this help you: How to add rows and columns to a WPF Grid programmatically

Devexpress get horizontal position of particular detail view row's scrollbar?

I have a master view with many rows, each of these rows has a detail view. Therefore each detail view can have its own horizontal scrollbar.
I wish to iterate through each master-row, check if it is expanded (I have done this) but now I wish to grab the horizontal scroll position of the corresponding detail view per expanded row.
How is this achieved?
I thought it would be masterGridView.GetDetailView(i,0).LeftCoord
but this doesnt work because GetDetailView cant return LeftCoord.....
SOLVED:
GridView gv = (GridView)mainGridView.GetDetailView(i,0);
gv.LeftCoord
it seems then you were using the WinForms XtraGrid control. You can read more about the GetDetailView method here
You can also ping the DevExpress support team directly.
Thanks.

Categories

Resources