I turned DevExpress Themes off for DevExpress GridView, does anybody know how to provide images for checked unchecked?
var grid = Html.DevExpress().GridView( settings => {
settings.EnableTheming = false;
settings.Columns.Add("isGrant", "Grant", MVCxGridViewColumnType.CheckBox);
}
When theming is on, I get nice check boxes in the grid, when it is off, there is no indication of any check marks, when "isGrant" is true. Does anybody know how to show an image when true, and a different image when false when themes are off?
Solved my own problem ... what I did was modify the VIEW and included this property:
public string GrantCheck {
get {
return isGrant ? "<img src='/Theme/css/images/checkmark.png'>" : " ";
}
}
Then in the gridview added a column with:
settings.Columns.Add(column => {
column.ColumnType = MVCxGridViewColumnType.TextBox;
column.FieldName = "GrantCheck";
column.Caption = "Grant";
column.PropertiesEdit.EncodeHtml = false;
column.CellStyle.CssClass = "dxcheckbox";
});
This way I get a nice check box. The css class is defined as:
.dxcheckbox { text-align: center;}
Cheers.
Related
When programmatically adding controls to a tab control, I have been using the Form_Load event to create and embed things like datagridviews into my UI. I made a class that inherits from DataGridView
class DBDataGridView : DataGridView
{
public DBDataGridView()
{
DoubleBuffered = true;
AllowUserToAddRows = false;
AllowUserToDeleteRows = false;
AllowUserToResizeRows = false;
AllowUserToOrderColumns = false;
AllowUserToResizeColumns = false;
RowHeadersVisible = false;
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
ReadOnly = true;
Dock = DockStyle.Fill;
SelectionMode = DataGridViewSelectionMode.FullRowSelect;
TabStop = false;
}
}
And I call it later in the Form_Load event like so
private void MainDesignerForm_Load(object sender, EventArgs e)
{
DBDataGridView _DGV = new DBDataGridView();
var listOfOverlays = new List<OverlaySelectionList>()
{
new OverlaySelectionList { Description = "Description 1", PartNumber = "123-R1"},
new OverlaySelectionList { Description = "Description 2", PartNumber = "456-R1"}
};
var overlayList = new BindingList<OverlaySelectionList>(listOfOverlays);
_DGV.DataSource = overlayList;
Tab_Overlay.Controls.Add(_DGV);
_DGV.ClearSelection();
}
This gridview is on the THIRD tab of the TabControl, and everything works as expected except the ClearSelection(). No matter where I call it, it does not clear the initial row selection of the DGV. However, if I fire the same code block from a button ON the third tab, the formatting AND the ClearSelection() behave as expected.
What is causing this behavior?
Thanks to 41686d6564 and Jimi for the insight into the specifics on why this was happening.
Reiterating what they said in the comments: Assignment of properties appear to be cached regardless of whether the control they belong to is active or not (Hence why all the sizing and formatting properties were present at run time). However, actions that require a handle, like ClearSelection() require the control to be shown and active for the intended behavior to be observed.
Setting the selected tab to where the DataGridView before calling ClearSelection() was the solution (Or in my case, I had nested tabs, so I had to follow the tab tree to get to the specific tab that the DataGridView was on)
So now, part of the Load_Form logic is to check WHERE the control is located, make that tab active, THEN format and clear selections for each control that is being added. This allowed ClearSelection() to work as intended.
I am using a Xtra Grid Control (Dev express 11.2). All columns are Read Only
AllowEdit = false
and I have created a function witch user can make Right-Clickand choose edit in a column, then this column if is 'amaColumn' or 'phoneColumn' then change to AllowEdit=true;
My Code is bellow
private void SetFocusedColumnOptionAllowEdit(bool allowEdit)
{
try
{
GridColumnCollection column = mainGridView.Columns;
GridColumn focusedColumn = column.View.FocusedColumn;
switch (focusedColumn.Name)
{
case "amaColumn":
case "phoneColumn":
focusedColumn.OptionsColumn.AllowEdit = allowEdit;
break;
}
}
catch (Exception ex) {
_logger.ErrorException("SetFocusedColumnOptionAllowEdit", ex);
}
}
But then to that I want to pu the cursor to flashing in the end of text without extra click in these columns. Is it possible?
if yes how can to that in c#?
Can anyone help me?
Thank you!
You need to open editor first. Then you will be able to put a cursor at an appropriate position:
mainGridView.ShowEditor();
TextEdit editor = (TextEdit)mainGridView.ActiveEditor();
editor.SelectionStart = editor.Text.Length - 1;
editor.SelectionLength = 0;
I currently have a ListBox (called wafersListBox) bounded to an ArrayList of a certain object type (called wafers). When I want to add to the ListBox dynamically, I use the following code:
wafersListBox.DataSource = null;
wafersListBox.DataSource = wafers;
wafersListBox.Refresh();
This successfully changes the items in the ListBox, but all of the items disappear (they're still there and can be selected, but the user just can't see them).
Any ideas on how to fix this?
UPDATE:
This is my Wafer class:
public class Wafer
{
public string maID;
public string MID
{
get
{
return maID;
}
set
{
maID = value;
}
}
public Wafer(string m)
{
maID = m;
}
}
This is the code that I call, it adds a copy of the currently selected item to the listbox:
Wafer w = wafersListBox.SelectedItem as Wafer;
wafers.Add(w);
wafersListBox.DataSource = null;
wafersListBox.DisplayMember = "MID";
wafersListBox.DataSource = wafers;
wafersListBox.Refresh();
You should probably tell the wafersListBox what property to use as it's caption.
Do it like this;
wafersListBox.DisplayMember = "PropertyNameThatYouWantToShow";
Sorry - I'm not able to add an additional comment, which would have been preferable over writing a new "answer" but do you see any difference if you switch the position of the lines as below?
Wafer w = wafersListBox.SelectedItem as Wafer;
wafers.Add(w);
wafersListBox.DataSource = null;
wafersListBox.DataSource = wafers;
wafersListBox.DisplayMember = "MID";
wafersListBox.Refresh();
One other thing I just came across on a different SO posting (ListBox doesn't show changes to DataSource):
"There is also a bug in the list box which can cause this problem. If you set the SelectionMode to None this problem appears.
As a work around I set the selection mode to One and then back to None when updating the datasource."
I'm new to wpf. With Windows Forms and a DataGridView I can force a user to stay in edit mode if the value entered in the grid is not valid (for example when entering letters in a column with ValueType set to double) with a code like this:
DataGridView grid = new DataGridView();
grid.DataError += (sender, e) => { };
I'm trying to have similar behavior with the wpf DataGrid with no luck.
I tried the following binding options:
dataGrid.Columns.Add(new System.Windows.Controls.DataGridTextColumn() { Header = "aHeader", Binding = new System.Windows.Data.Binding("aProperty") { ValidatesOnDataErrors = false, ValidatesOnExceptions = false } });
But I can't see any change at all. Entering a non valid data causes the app to crash.
Any idea please?
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..:)