how to hide Devexpress xtragrid auto emptybands - c#

In DevExpress XtraGrid an Empty Bands is displayed when one of its column position is set Fixed.
Here is the code:
gridview1.DataSource = ds.Table[0];
gridview1.OptionsView.ColumnAutoWidth = false;
gridview1.PopulateColumns();
GridBand DateGridBand = new GridBand();
DateGridBand.Columns.Add(gridview1.Columns["Date"]);
gridview1.Bands.Add(DateGridBand).Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left;
GridBand gdBand = new GridBand();
gdBand .Caption = "Details";
gdBand .Columns.Add(gridview1.Columns["No"]);
gdBand .Columns.Add(gridview1.Columns["Qty");
gridview1.Bands.Add(gdBand );
how to avoid the Blank Bands.
Thanks.

You need to remove the header row.
// remove header row
GridView1.OptionsView.ShowColumnHeaders = False;
Knowing the two below will save you some time with further customization.
// remove side indicator
GridView1.OptionsView.ShowIndicator = False;
// remove group header
GridView1.OptionsView.ShowGroupPanel = False;

Related

Add ContextMenuStrips to multiple DataGridViews on multiple TabPages

I am trying to load multiple DataTables into DataGridViews in separate tabpages of a TabControl, the DataTables are stored in a Dictionary which is in turn stored in a DataObject class.
I can get everything displaying correctly but when I try to add loop through the Datagridview Header to add a contextmenustrip, for some reason I can get it to work for the first DataGridView but subsequent DataGridViews do not have the context menu applied? I have tried adding a print statentment just before the foreach loop and the DataGridView gets a column count of zero…so im guessing that’s why the foreach loop isn’t doing anything…but all the data is still displayed correctly in the dataGridViews in their respective tabs…any help in pointing out what I’m missing would be greatly appreciated.
Regards
Amarino
Code given below
List<ImportObject> lImportObjects = new List<ImportObject>();
private void loadImportFilesToScreen(List<ImportObject> lImportObjects)
{
foreach (ImportObject lImportObject in lImportObjects) {
DisplayImportFiles(lImportObject);
}
}
public void DisplayImportFiles(ImportObject pImportObject)
{
string lTabName="";
//load DataGridView with DataTable
/*
foreach (KeyValuePair<string, DataTable> lDT in pImportObject.DataTableDictionary)
{
lTabName = DisplayTabsInApp(pImportObject.FileName + "_" + lDT.Key, lDT.Key);
LoadDatatableIntoGrid(lDT.Value, lTabName);
}
*/
for (int i = 0; i < pImportObject.DataTableDictionary.Count; i++)
{
KeyValuePair<string, DataTable> lItem = pImportObject.DataTableDictionary.ElementAt(i);
string lKey = lItem.Key;
DataTable lDT = lItem.Value;
lTabName = DisplayTabs(pImportObject.FileName + "_" + lKey, lKey);
LoadDatatableIntoGrid(lDT, lTabName);
lDT = null;
}
}
public string DisplayTabs(string pTabName, string pSheetName)
{
// Create a new Tab Page for this file. Set heading, set name.
TabPage lTabPage_NewFile = new TabPage();
lTabPage_NewFile.Text = pTabName;
lTabPage_NewFile.Name = "TAB_PAGE_" + pTabName;
tabControl_ImportFiles.TabPages.Add(lTabPage_NewFile);
return lTabPage_NewFile.Name;
}
public void LoadDatatableIntoGrid(DataTable pDataTable, string pTabName) {
DataGridView lDGV = new DataGridView();
lDGV.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing;
lDGV.RowHeadersVisible = false;
BindingSource BindingSource1 = new BindingSource(); //create new data binding source
BindingSource1.DataSource = pDataTable; //SetData source
lDGV.DataSource = BindingSource1;
lDGV.RowHeadersVisible = true;
tabControl_ImportFiles.TabPages[pTabName].Controls.Add(lDGV);
//DataGridView lDGV = tabControl_ImportFiles.TabPages[pTabName].Controls[0] as DataGridView;
PrintToConsoleInARD("DataGridView Column Count: " + lDGV.Columns.Count.ToString());
bool runOnce = true;
foreach (DataGridViewColumn lDGVColumn in lDGV.Columns) {
lDGVColumn.HeaderCell.ContextMenuStrip = lCMS_ColumnHeaders;
}
lDGV.Dock = DockStyle.Fill;
lDGV.VirtualMode = true;
BindingSource1 = null;
lDGV = null;
}
I am confident the reason for this is because the “tab page” is not displayed. As the trace is described inside the LoadDatatableIntoGrid method… if you put a breakpoint at the line…
tabControl_ImportFiles.TabPages[pTabName].Controls.Add(lDGV);
Add a watch to the variable lDGV.Columns.Count… will show that IDGV has zero (0) columns. Execute the line above and magically, the grid IDGV has columns. This appears correct since this is the first “tab page” and it is the active (displayed) tab page. Point being… if you do not add the grid to a “Active/Shown/Displayed” tab page most UI code will be ignored. This is why the next time around; the grid will be empty because the grid is added to a non “active/shown/displayed” tab page.
A simple solution is to simply “Show” the tab page before you add the grid to it. This appears to fix the issue you describe. Add the line below before the line above…
tabControl_ImportFiles.TabPages[pTabName].Show();
Hope this helps.

How to set page layout break on worksheet using EPPlus

Is there a way to set specify where to break the page using EEPlus? I have the following code that sets the printer properties but haven't found a way to set a break point on a certain column.
// Set printer settings
ws.PrinterSettings.PaperSize = ePaperSize.Tabloid;
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.FitToPage = true;
ws.PrinterSettings.FitToHeight = 1;
ws.PrinterSettings.FooterMargin = .05M;
ws.PrinterSettings.TopMargin = .05M;
ws.PrinterSettings.LeftMargin = .05M;
ws.PrinterSettings.RightMargin = .05M;
Edit (this helped solve my problem)
ws.Column(30).PageBreak = true;
ws.PrinterSettings.PaperSize = ePaperSize.A3;
ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.Scale = 75;
Just need to get reference to the Row and/or Column objects:
ws.Row(20).PageBreak = true;
ws.Column(2).PageBreak = true;
But keep in mind that FitToPage might suppress these.

AllowUserToResizeColumns and AllowUserToResizeRows of the datagridview doesn't work

I have a datagridview that I want to allow user from resizing columns and prevent hom from resizing rows. I am setting the properties in design and also at runtime but it doesn't affect the datagridview.
The opposite happens, the rows can be resized and the columns not.
I tried to reverse the properties values but same result.
private void SetupAlternatesDataGridView()
{
var recordstateColumn = new DataGridViewTextBoxColumn();
recordstateColumn.Name = Glossary.RecordState;
recordstateColumn.HeaderText = Glossary.RecordStateTitle;
var alternateStatusColumn = new DataGridViewTextBoxColumn();
alternateStatusColumn.Name = Glossary.AliasAlternateStatus;
alternateStatusColumn.HeaderText = Glossary.AlternateStatusTitle;
var alternateNumberColumn = new DataGridViewTextBoxColumn();
alternateNumberColumn.Name = Glossary.AliasAlternateNumber;
alternateNumberColumn.HeaderText = Glossary.AlternateNumberTitle;
AlternateDGV.AllowUserToResizeColumns = true;
AlternateDGV.AllowUserToResizeRows = false;
//TODO: For test only, remove it
AlternateDGV.Columns.AddRange(recordstateColumn, alternateStatusColumn, alternateNumberColumn);
AlternateDGV.Rows.Add("added", "A", "POS-100");
}
How to make those properties work?
Just play with all the properties and found that AutoSizeColumnsMode must be set to None in order to AllowUserToResizeColumns and AllowUserToResizeRows to work.
AutoSizeColumnsMode = None
In my case, it didn't work because I had this line:
Grid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
In other words, if you ask one column to fill all available space, the user won't be able to resize it (at least on Windows 10).
But if your entire grid is set to "Fill", like this:
Grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
then resizing will be allowed.

Can't display linklabel text in a datagridviewlinkcolumn

I have a little but pretty annoying problem:
I have created a datagridview and bound it to a datasource.
Then now I want to add a column which will display links for the user to click.
In order to do that i added a datagridviewlinkcolumn. For each rows of the datagrid I set the value of the cell in that column to the text i want to be displayed. But it shows nothing. All the datagridlinkcolumn is filled with "blank text".
Here is my code:
DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();
dgvColDeletion.Name = "Deletion";
dgvColDeletion.HeaderText = "";
dgvColDeletion.ReadOnly = false;
dgvTrainings.Columns.Add(dgvColDeletion);
foreach (DataGridViewRow row in dgvTrainings.Rows)
{
row.Cells["Deletion"].Value = "Delete";
}
dgvColDeletion.Update();
dgvTrainings.Update();
I also tried with setting directly linklabels or datagridviwlinkcells, but the problem still remains.
I cant get any clue why this isn't working.
Any help will be very much appreciated, thanks.
To display the same link text for every cell, set the UseColumnTextForLinkValue property to true and set the Text property to the desired link text.
DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();
dgvColDeletion.UseColumnTextForLinkValue = true;
dgvColDeletion.Text = "Delete";
Try this. I hope this will helps to you.
DataGridViewLinkColumn dgvColDeletion = new DataGridViewLinkColumn();
dgvColDeletion.UseColumnTextForLinkValue = true;<br/>
dgvColDeletion.Text = "Delete";<br/>
dgvColDeletion.ActiveLinkColor = Color.White;<br/>
dgvColDeletion.LinkBehavior = LinkBehavior.SystemDefault;<br/>
dgvColDeletion.LinkColor = Color.Blue;<br/>
dgvColDeletion.TrackVisitedState = true;<br/>
dgvColDeletion.VisitedLinkColor = Color.YellowGreen;<br/>
dgvColDeletion.Name = "Delete";<br/>
dgvColDeletion.HeaderText = "Delete";<br/>
if (grid_shared.Columns.Contains("Delete") == false)<br/>
{<br/>
dgvColDeletion.Columns.Add(lnkDelete);<br/>
dgvColDeletion.Columns["Delete"].Width = 40;<br/>
}<br/>
Happy coding..:)

AspxGridView selection at runtime

I have an aspxGridView on my page, and i create the columns at runtime. I also add CommandColumn with ShowSelectCheckBox set to true. But after i select one row and click a button to get the row values, AspxGridView.Selection.Count returns 0. I create this GridView on AspxButtons Click event also for paging, create the gridView on Page_Init. Here is the code to create the AspxGridView:
Colenter code hereorCollection colorCol = ConfAttributesManager.Instance
.GetColors();
if (colorCol.Count > 0)
{
GridViewDataTextColumn grdColorCodeColumn = new GridViewDataTextColumn();
grdColorCodeColumn.FieldName = "ColorCode";
GridViewDataTextColumn grdDescriptionColumn = new GridViewDataTextColumn();
grdDescriptionColumn.FieldName = "Description";
gv_Attributes.Columns.Clear();
gv_Attributes.Columns.Add(grdColorCodeColumn);
gv_Attributes.Columns.Add(grdDescriptionColumn);
GridViewCommandColumn grdCmdColumn = new GridViewCommandColumn();
grdCmdColumn.ShowSelectCheckbox = true;
grdCmdColumn.VisibleIndex = 0;
gv_Attributes.Columns.Add(grdCmdColumn);
gv_Attributes.DataSource = colorCol;
gv_Attributes.DataBind();
}
I don't know where do i make a mistake?
Thanks for your help.
It seems that you do not specify the ASPxGridView.KeyFieldName property that is required for Row Selection operation:
gv_Attributes.KeyFieldName = "ColorCode";
//gv_Attributes.KeyFieldName = Unique Key Field;

Categories