Hide a Column from ColumnChooser - c#

Currently I'm developing an application with devexpress, and I had set two columns to hide like this:
gridView1.Columns[2].Visible = false;
However, when I run my program, there is an option from the DataGrid called "Selector de Columnas" (in English ColumnChooser). In this option the two columns that I set to be hidden are shown. I don't want the user to see these columns but I still need them, so I just want to hide them.
I searched in the online documentation from Devexpress and they state here that columns can be hidden with the ShowInColumnChooser property. However I'm not able to hide these columns in the ColumnChooser. They don't show you any example, just this line of code:
public bool ShowInColumnChooser { get; set; }
I guess this is a property from some Devexpress control, however they don't state how to use it.

All the links you referred to are related to the WPF DXGrid, but as far as I can see from your screenshot, you are working with the XtraGrid (WinForms). If so, you should use the OptionsColumn.ShowInCustomizationForm property as follows:
column1.OptionsColumn.ShowInCustomizationForm = false;
Related help articles:
Column and Card Field Overview
Customization Form

If you want to prevent a specific column from being showed/hidden, set the column's properties OptionsColumn.ShowInCustomizationForm and OptionsColumn.AllowShowHide to false.

Related

Autocomplete TextBox for C# Winform VS2008 clarification needed

I am working on C# winform vs2008 project. Requirement is to show line level details into grid and grid one text box cloumn user will type the text and it should populate the autocomplete text. Autocomplete search should based on one column only, but need to show additional one column to user. Exampe : Name and Phone number. user will search based on Name only additional column phone should display purpose.
I have following query :
1) Database is large, is there any free autocomplete 3 party tool available.?
2) How can i show muliple columns in autocomplete.
Please let me know, how i can show multiple columns in autocomplete.
I am stuck here.. please help me out..
Thanks and Regards
Ram
There are third party components that can be used to support multiple column drop down, for example DevExpress's LookUpEdit, Infragistics's UltraCombo and Telerik's RadMultiColumnComboBox. You can change the filter then popup the dropdown when typing, but that is not going to beat the performance of Windows's autocomplete, which uses a second thread to enumerate candidates.
If you have that much data, auto-sizing the drop down columns and animation probably need to be disabled if your control library enables them by default.
public Class YourClass
{
public string Name;
{
get;
private set;
}
public string PhoneNo;
{
get;
private set;
}
public override string ToString()
{
return String.Format("{0,-50} {1,-15}", this.Name, this.PhoneNumber);
}
}
internal class YourForm : Form
{
ComboBox YourComboBox = new Combobox();
//Set the style of your combobox such that it looks like a text box
BindingList<KeyValuePair<string, YourClass> bl = new Binding<string, YourClass>();
//Query for the data to populate the BindingList
//Lets say you put the UserId or ContactId of the person in the Key..
YourComboBox.DataSource = bl;
YourComboBox.DisplayMember = "Value";
YourComboBox.ValueMember = "Key";
}
Do what ever you are doing for autocomplete
There's no ready and elegant implementation for what you need. What I gave you would display the results like in a table..
Eg:-
Reese W 32
Pamela A 40
but with the name, taking about characters of space in what ever font the control renders..
(You will have to look at this answer in edit mode to see it)
If you want exactly what you need, you WILL have to use some available 3rd party controls or write one of your own. And as some one said, it's too much of code..

C# DataGridView, custom property from columns editor is not saved

I have a datagridview in my form. This datagridview has some columns. There are some custom columns (I have created custom datagridview cells). These custom cells have some properties that I want to do visible from datagridview's columns editor in design time in order to set them. So in design time, I open datagridview's columns editor, and I create a column of the custom datagridview cell. Then, I set some custom properties and I close datagridview's olumns editor. When I open the datagridview's columns editor, the values that I set previously for those custom properties are not reflected, it seems like they were not saved once datagridview's columns editor was closed. So... why? why the values for the custom properties are not saved? What Am i doing wrong?
Furthermore, I cannot leave as empty these custom properties because an exception I raised once form is loaded (object reference not set as a instance of an object).
I highly appreciate if someone could help me.
I ran into this identical issue. After searching, I found some feedback on a microsoft site that said I had to implement iCloneable in my datagridviewtextboxcolumn derivation.
You can find the article here and the relevant section:
In some rare cases, the column type may want to expose a property that
has no equivalent property at the cell level. Examples of that are
DataGridViewLinkColumn.Text and DataGridViewImageColumn.Image. In
those cases, the column class needs to override the Clone method to
copy over that property.
My column added four extra properties, and here's my icloneable function:
//Override this method to set the custom properties.
public override object Clone()
{
var col = base.Clone() as BauerDataGridViewTextBoxColumn;
col.ShowBorder = this.ShowBorder;
col.BorderColor = this.BorderColor;
col.ColumnChooserIsOptional = this.ColumnChooserIsOptional;
col.ColumnChooserColumnLabel = this.ColumnChooserColumnLabel;
return col;
}

Enabling and disabling of columns in Infragistics UltraGrid

I have an Infragistics grid and I want to disable and enable some columns based upon some requirement. I have read some articles that say to use AllowUpdate = DefaultableBoolean.True but it did not work for me.
I suppose that when you talk of disabled columns you mean disable editing in these columns.
Also you don't specify the language, so I will use C#
UltraGridColumn c = grdWork.DisplayLayout.Bands[0].Columns["YourColumnName"];
c.CellActivation = Activation.NoEdit;
c.CellClickAction = CellClickAction.CellSelect;
The property CellActivation could also be set to Activation.Disabled or Activation.ActivateOnly.
The property CellClickAction allows to set an appropriate selection status for the cell clicked. You could use CellSelect or RowSelect. (This last one, to mimic the behavior of a ListBox)
As usual, the real difficulty is to find the correct property. Then Intellisense will give you a quick and fair explanation of the meaning of these values.
If you just want to show and hide the columns as needed then you can try the following.
UltraGrid myGrid = new UltraGrid();
//Bind to your data here
myGrid.DisplayLayout.Bands[0].Columns["ColumnName"].Hidden = true;

How To Hide ListView ColumnHeader?

I am struggling to figure out the correct control to use for a list of predefined jobs in the included form. I currently have a ListBoxControl in the Predefined Job Name group that lists all of the predefined jobs for a marine service shop (i.e. oil change, tune up, etc...). Then, based on the item (i.e. job name) that is selected in my ListBox, I need to display the items that correspond to that job. For example, if oil change is the selected job I need to show 4 quarts oil, 1 oil filter, labor, etc...and so on.
Currently, when I load the form data I have a DAO that retrieves all of my jobs from the database using LINQ to SQL. Then I iterate over the results and put the job names into the ListBox. The problem that I am having is that there is no tag for ListBox items like there is for ListView items. So each time the user selects another item in the ListBox, I have to perform another LINQ query to get the job from the database again so that I can display its' corresponding items. If I could use a ListView and hide the column header I could set the entire job on the tag so that each time the user selects a new item I would have access to the details without having to make another call to the database. Is there a way that I can hide the column header of a ListView without hiding the entire column?
You can set the HeaderStyle member of the ListView to None.
listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
Checkout the ListView HeaderStyle property. It has the following options:
None
Nonclickable
Clickable
From MSDN:
The HeaderStyle property allows you to specify whether the column headers are visible or, if they are visible, whether they will function as clickable buttons. If the HeaderStyle property is set to ColumnHeaderStyle.None, the column headers are not displayed, although the items and subitems of the ListView control are still arranged in columns
You can also create simple object like ListItem which has two poperties: Text (string) and Tag (object). Then implement ListItem.ToString() and you can use these in the ListBox as well.
You can also check out Better ListView Express component, which is free and allows displaying items in Details view without columns. The advantage over ListBox and ListView is a native look and many extra features.
Easy way is using the ColumnWidthChanging event
private void listViewExtended1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
if (e.ColumnIndex == 0)
{
e.Cancel = true;
e.NewWidth = listViewExtended1.Columns[e.ColumnIndex].Width;
}
}
I found that if you know for a fact you are not displaying the headers it may be best to set the HeaderStyle property to None, as Rajesh mentions above.
When setting in the .CS when screen initially loads the headers are displayed until screen is fully rendered.

Block columns in DataGridView

Again a c# question I cant't seem to figure out:
I have a datagridview on my form. In Visual Studio design mode, I enter 4 columns: refernce, country, name & city.
After a searchform is filled in, I try to refresh the datasource: A custom class fetches all the data from the selected table and fills the datagridview. The problem is: the datagridview now has all the columns of the table, and I only want the 4 columns entered in design mode.
I can put all the other columns on visible = false in design mode, and that works. But I want this datagridview as a custom control. So I only want to show the 4 entered columns, without disabling all the others. The data which is invisible is used to bind to a panel with other Controls like TextBoxes.
Does somebody know if this is possible, and how I should try to solve this?
Thanks!
You have three ways of hide columns.
1.- setting the visible property to false (as ksogor said) and don't create columns in design mode. Note that
GridView1.Columns["ColumnName"].Visible = false;
is more readable and mantenible that
GridView1.Columns[1].Visible = false;
2.- setting AutoGenerateColumns to false and create columns in the designer
3.- in your class, set the attribute [Browsable(false)] in the fields you don't want to show. Don't create columns in design mode.
The third way will hide the column in all the datagrids of your app. I love it.
[Browsable(false)]
public string Something{get;set;}

Categories

Resources