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;
Related
I am using a "DevXpress.XtraGrid.GridView" and I have a column there which is bound to a boolean data. This column shows check boxes to represent values. I need to show "YES/NO" instead of check boxes. Please advice me.
Thanks for helping,
Kushan Randima.
This is how I do it in code in one of my tools. This is a dynamic SQL Query tool and it returns a checkmark or red X beside the query result, at runtime. You can also do this through the designer but this is done in code.
This is for Winforms, but the low level GridView should be the same code for WPF (I am not positive).
First, in the Data Grid GridView designer, I add a column (mine is "IsError" column). Then in my form constructor or InitializeForm() I do this:
RepositoryItemCheckEdit checkEdit = gridOutput.RepositoryItems.Add("CheckEdit") as RepositoryItemCheckEdit;
checkEdit.PictureChecked = global::Gyrasoft.Common.DX.Properties.Resources.exclamation;
checkEdit.PictureUnchecked = global::Gyrasoft.Common.DX.Properties.Resources.accept;
checkEdit.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.UserDefined;
gridViewOutput.Columns["IsError"].ColumnEdit = checkEdit;
The resources, of course, have to be valid images.
Basically you add a repository item (RepositoryItemCheckEdit) and set CheckStyle to UserDefined, and assign the checkEdit to the gridView column. You can add the same checkedit to multiple columns. It is simply for rendering or editing.
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.
I am using a WPF DataGrid with procedurally (C#, VS 2010) generated, bound columns, and the DataGrid will not sort data correctly.
CanUserSortColumns is set to true.
SortMemberPath is set to the same property as the text displayed in the grid.
Regardless of which column the user sorts, and despite the sort icon being displayed over the appropriate column, the DataGrid merely alternates the sort order of the first column.
column.Header = departmentColumn.ColumnHeader;
column.Width = departmentColumn.ColumnWidth;
column.Binding = new Binding("Cells[" + departmentColumn.Ordinal.ToString() + "]");
column.SortMemberPath = "DisplayString";
I have no problems with any other data being displayed or used incorrectly by the DataGrid, so I am stumped. Why would the sort only consider text in the first column, when everything else binds to data from the appropriate column?
This is how I sort the datagrid, maybe it will help
Dim cv As ICollectionView = CollectionViewSource.GetDefaultView(dgMyDataGrid.ItemsSource)
cv.SortDescriptions.Clear()
cv.SortDescriptions.Add(New SortDescription("iOrderNum", ListSortDirection.Ascending))
cv.Refresh()
After spending a couple hours on this today, I found the answer myself almost immediately after I posted the question.
I had to change:
column.SortMemberPath = "DisplayString";
To:
column.SortMemberPath = "Cells[" + departmentColumn.Ordinal.ToString() + "].DisplayString";
I guess SortMemberPath does not always automatically bind to the current data item.
My thanks to anyone who already started working on this.
According to the DataGridColumn.SortMemberPath Property page at MSDN, the SortMemberPath property sets
The path of the data-item member to sort by
This would lead me to believe that you should not set this property unless you only want to sort by the one column that you set it to.
I'm working on a GUI that allows the user to manipulate xml files. I display the xml file in a datagridview organized neatly by columns through xml elements. I allow the user to add columns as an extention on my project. The column gets added to the dataset table, then updated to the datagridveiew that I use to display the xml file in. I've included the ability for the user to add a combobox column to select choices instead of entering them in constantly like.. true or false. However, that is where the problem lies. Saving a normal column was easy. The combobox column is being a pain.
I have a "save combobox column" to have it updated to the xml and a "save" button to save in a destination of the user's choice.
I've done some research and it seems like the combobox class has such a feature to gain access to the selecteditem in the combobox put in by the user.
Where we have:
ComboBox box = new ComboBox();
box.SelectedItem;
I tried applying this to the combobox column class but it does not have such a function. Thus, I cannot figure out how to directly obtain the value of the user's selected item. I tried experimenting with comboboxcell's as well, but that didn't lead me anywhere either. Both those classes I played around with do not have a... "selected item" function and even google does not have a solution for me. =( I've also tried using the cell.value, but it is "null" for some reason. Even when the user selects an item in the box, it doesn't get saved into the cell's value.
TLDR:
My question in short is, how, if possible, do you gain access to the comboboxcolumn cell's selected item? Additionally, how would you then ensure that the item value is saved in the cell?
Thanks in advance. I'm using .NET 3.5 SP1, through Visual Studio 2008 C#.
Sincerely,
tf.rz
The Control in a DataGridView is not a ComboBox, it is a DataGridViewComboBox and has different properties and methods. From MSDN
Unlike the ComboBox control, the DataGridViewComboBoxCell does not have SelectedIndex and SelectedValue properties. Instead, selecting a value from a drop-down list sets the cell Value property.
However, you mentioned that the Cell.Value is null for you. Well there may be another step you are missing according to the following article (How to: Access Objects in a Windows Forms DataGridViewComboBoxCell Drop-Down List).
You must set the DataGridViewComboBoxColumn.ValueMember or DataGridViewComboBoxCell.ValueMember property to the name of a property on your business object. When the user makes a selection, the indicated property of the business object sets the cell Value property.
If we have bound a datagridcomboboxcell with a different DisplayMember and ValueMember, like so:
dgcombocell.DisplayMember = "Name";
dgcombocell.ValueMember = "Id";
dgcombocell.DataSource = dataset1.Tables[0];
Then for getting SelectedText, and SelectedValue, we can write this code:
string SelectedText = Convert.ToString((DataGridView1.Rows[0].Cells["dgcombocell"] as DataGridViewComboBoxCell).FormattedValue.ToString());
int SelectedVal = Convert.ToInt32(DataGridView1.Rows[0].Cells["dgcombocell"].Value);
I hope it solves your problem.
Use this to get or set selected value:
object selectedValue = currentRow.Cells["comboboxColumnName"].Value
Don't forget to set DisplayMember and ValueMember for your DataGridViewComboBoxColumn
This is how it is done
DataGridViewComboBoxCell comboCell = (DataGridViewComboBoxCell)dgv.Rows[0].Cells[1];
MessageBox.Show(""+comboCell.Items.IndexOf(comboCell.Value));
A .Net combox is actually a composite control made up of a textbox and a dropdownlist. Use box.Text to get the currently displayed information.
EDIT: The row or the cell should have a .FindControl() method. You'll need to do something like:
Combobox box = (Combobox)(row.FindControl("[combobox ID]"));
string val = box.Text;
Basically, you're finding the control within its container (row or cell), then casting the control found as a combobox, then accessing its .Text property.
I use this:
private int GetDataGridViewComboBoxCellSelectedIndex(DataGridViewCell d)
{
return ((DataGridViewComboBoxCell)d).Items.IndexOf(d.Value);
}
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;}