I am using the LookUpEdit control. I bound two columns, a primary key (GUID) and a human readable string. I only want people to see the human readable string, but I want to preserve the relationship between the string value and it's primary key value.
I can't seem to hide the primary key from displaying on dropdown. I've tried the DevExpress forum and their proposed solution does not work for me. So I tried hooking into the ListChanged event. That is not working either.
private void DataBind()
{
messageTypeCbB.ListChanged += new ListChangedEventHandler(messageTypeCbB_ListChanged);
messageTypeCbB.Properties.DataSource = viewModel.SomeNoteTypes.ToArray();
//another attempt at hiding the columns. This fails too.
//messageTypeCbB.Properties.ForceInitialize();
//messageTypeCbB.Properties.PopulateColumns();
//messageTypeCbB.Properties.Columns[0].Visible = false;
messageTypeCbB.Properties.DisplayMember = "NodeType";
messageTypeCbB.Properties.ValueMember = "SomeNoteType_ID";
fromTxt.Text = viewModel.From;
dateTimeDd.DateTime = viewModel.Date;
}
void messageTypeCbB_ListChanged(object sender, ListChangedEventArgs e)
{
//For whatever reason this won't hide the column
(sender as DevExpress.XtraEditors.LookUpEdit).Properties.Columns[0].Visible = false;
}
How can I hide the surrogate key? (Hide ValueMember display only DisplayMember)
DevExpress v11.1.6
Have you tried the other method suggested in that forum listing? i.e. not setting Visible to false but rather explicitly adding the columns you want to be displayed to the Columns collection. Try Columns.Clear() then add your column(s). Or try PopulateColumns() then Columns.RemoveAt(0);
I was calling DataBind() from my Form constructor. I moved the call into the Form Load event and it solved the problem.
Related
I have a gridview and a repositorycheckedit column, I want it to change its value only when it is double-clicked, and prevent it from changing with a single click.
thanks
I think you can achieve this in the following way:
Make the column read-only. This will disable the native behavior of allowing a click to edit the value.
colCheck.OptionsColumn.Readonly = true;
Add an in-place repository item of a check box and assign it to the column. If this column is a boolean, this is normally unnecessary (check is the default control type for a boolean), but this will help for the next step
Fire the double-click event on the repository item and alter the check property as follows:
~
private void repositoryItemCheckEdit1_DoubleClick(object sender, EventArgs e)
{
Foo f = gridView1.GetFocusedRow() as Foo;
f.Check = !f.Check;
gridView1.RefreshData();
}
Let me know if that helps.
I have an infragistics UltraWinGrid and I want to disable the first column or make it "readonly". What is the way to do this?
I tried (none of these worked):
_ultraGridRetailers.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.Disabled;
_ultraGridRetailers.Rows[0].Cells[0].Activation = Activation.Disabled;
For any specific question it will be better to contact the support of Infragistics, but there is regarding your question: Blog one
Try to debug your aplication and see if you are setting this behavior too early or if you are reseting it in code after the pointed one. According to the blog post this should be the way to acieve the goal, and if it is not working you better contact the support and submit a development issue.
What I have tried is hooking to the InitializeLayout event of the UltraGrid like the following, and setting there the desired properties of the columns, which does work for me correctly:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
//Make the column disabled or
e.Layout.Bands[0].Columns[0].CellActivation = Activation.Disabled;
//Make the column readonly
e.Layout.Bands[0].Columns[0].CellActivation = Activation.ActivateOnly;
}
If the above doesn't work for you, most probably something overrides those settings in a later stage of your application.
I have to check / uncheck all the checkboxes (toggle) in a column when the user double clicks the column header.
How can I implement this behaviour in the DevExpress DxGrid control?
I have searched the DevExpress support forum but I haven't found a solution.
Also, i am working on MVVM Pattern.
This case works for WinForms, not tested in WPF yet, I posted might it direct you to some lights:
There is a workaround to accomplish this behave, you have to implement yourGrid_DoubleClick Event Handler, then calculate the hit Info of the mouse click, the hit info object will tell you if the double click was on a column, something like:
private void yourGridViewName_DoubleClick(object sender, EventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView sndr =
sender as DevExpress.XtraGrid.Views.Grid.GridView;
DevExpress.Utils.DXMouseEventArgs dxMouseEventArgs =
e as DevExpress.Utils.DXMouseEventArgs;
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo =
sndr.CalcHitInfo(dxMouseEventArgs.Location);
if (hitInfo.InColumn)
{
string x = hitInfo.Column.Name;
//Rest of your logic goes here after getting the column name,
//You might now loop over your grid's data and do your logic
}
}
but you have to notice that this action will not prevent the sorting that column's header do, you might need to disable sorting for this grid
Hope this helped.
I have a DataGridView populated from a database.
I am trying to get the contents of the row that is selected on the RowEnter event. I have set the grid's selection mode to FullRowSelect
I have tried the following:
int orderId = (int)dgUnprocessedCards.Rows[dgUnprocessedCards.SelectedCells[0].RowIndex].Cells[0].Value;
this keep throwing the error
Index was out of range. Must be non-negative and less than the size of the collection.
Any help is appreciated.
I've just tried this in a sample datagridview app and it works just fine so there must be something going on which you haven't told us about.
First thing to do is break your one big statement up into discrete smaller statements so you can see exactly where the failure is.
You can rewrite the code above to something like this for debugging purposes:
var cellindex = dgUnprocessedCards.SelectedCells[0].RowIndex;
var cellcollection = dgUnprocessedCards.Rows[cellindex].Cells[0];
int orderId = (int)dgUnprocessedCards.Value;
Also, you should be able to do the following to achieve what you want:
int orderId = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
That uses the SelectedRows collection which is a little bit more concise and I'd say the more usual way of accessing selected items from the datagridview.
Finally, you probably want to do checking around your cast of the value, since the Value might not necessarily be an int. Something like:
int orderid;
if (!int.TryParse(cellcollection.Value.ToString(), out orderid))
{
// Some logic to deal with the fact that Value was not an int
}
When is the SelectionChanged event raised?
Now - as you mention, your selection changed event fires while loading data into the grid. This doesn't seem to cause a problem in my test version but could be part of your issue.
Why this happens should not be related to the type of data source you are using, but to when you attach the selection changed eventhandler. This is because databinding causes a selection changed event to be raised.
If you add an eventhandler for the DataBindingComplete event and attach your SelectionChanged or RowEnter eventhandlers there, you should not see the handler invoked during databinding.
void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
this.dataGridView1.RowEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_RowEnter);
this.dataGridView1.SelectionChanged += new System.EventHandler(this.dataGridView1_SelectionChanged);
}
Note that you will need to delete the designer generated event attachment and reference the designer generated methods for this to work.
This also works:
int orderId = (int)dgUnprocessedCards.SelectedCells[0].OwningRow.Cells[0].Value;
You can get specific column value when you click on Datagridview column
private void DataGridview_CellContentClick(object sender,
DataGridViewCellEventArgs e) { int col = e.ColumnIndex; int row =
e.RowIndex; Var value=DataGridview.Rows[row].Cells[col].Value; }
What I tried to do worked fine but the binding was calling the selection changed event. So I done what David Hall suggested (attaching and detaching the event) and I also put it in a try catch block and now it works perfectly.
I'm developing an application of the xtragridview control in that application when i'll double click on row from the xtragridview that time one popup form opens . then the focus of the parent window changes & focus is assigned to the another form which is popup . and that time my selected row changes it's state & it focus/select the default 1st row from the xtrgridview.
but i want to maintain the focused/selected row as it is if user changes the focus from one form to another pop up form.
Is there any solution on this solution? what properties of xtragridview control should i've to set for this problem?
thanxs.....
Generally, the approach you are using does not require you to write an additional code. The XtraGrid does not reset its FocusedRow if you open a form by doubleclicking a grid row. So, I would suggest that you determine the cause of this behavior. This can be done by using the following approach:
1) handle the GridView's FocusedRowChanged event and set a breakpoint in it.
2) reproduce the issue and check which code forces the gridView to focus the first row.
This should give an idea on why this happens.
Also, I would suggest that you review the How to create the PopupForm for editing rows in the GridView and automatically create editors based on the column editors. example where the required functionality is implemented.
I think I know the cause of this problem. It appears because you are changing the DataView's RowFilter property. I think you want your editors to point to the clicked record. The best solution is to do not filter the DataView but to assign the BindingContext as it is done in the example above. Here is the code from it:
public EditForm(Point location, GridColumnCollection columns, object dataSource, BindingContext context)
: this() {
StartPosition = FormStartPosition.Manual;
Location = location;
BindingContext = context; // <<<<<<
allowTrackValueChanges = false;
this.dataSource = dataSource;
...
}
Mehod 1:
In the double click event handler just mention
return;
after all processes (Opening of another form etc.) are done.
After understanding your question better, I suggest to try method 2 I hope it surely works.
Method 2:
First record the current selected index before it opens another form or dialog ..
int index = datagridview.SelectedRows[0].Index; //or xdatagrid.SelectedRows[0].Index;**
Then after completion of form opening or other procedure add the following line
datagridview.Rows[index].Selected = true; //or xdatagrid.Rows[index].Selected = true;**
**N.B.: I have never used xdatagrid, but suggesting the solutions depending on my datagridview experience.
I use
GridView view = (GridView) sender;
Point pt = view.GridControl.PointToClient(Control.MousePosition);
var info = DoRowDoubleClick(view, pt);
when DoRowDoubleClick is:
private static GridHitInfo DoRowDoubleClick(GridView view, Point pt) {
GridHitInfo info = view.CalcHitInfo(pt);
if (info.InRow || info.InRowCell){
string colCaption = info.Column == null ? "N/A" : info.Column.GetCaption();
MessageBox.Show(string.Format("DoubleClick on row: {0}, column: {1}.", info.RowHandle, colCaption));
return info;
}
return null;
}