After rendering full grid I need to change data context of selected Row since initially "simple" objects are filled as data source and when single item is selected (looking at RowDetailsVisibilityChanged event), then I want to change DataContext to complex object, that shows much more info in details than in collapsed row.
Using GridViewRowDetailsEventArgs.DetailsElement.DataContext seems to do the trick for Details element that is expanded below row on selecting, BUT Header (Columns) stay the same and values are not updated when changing GridViewRowDetailsEventArgs.DetailsElement.DataContext or GridViewRowDetailsEventArgs.Row.DataCOntext .
(Imagine like column of collapsed row is bound to Name, where Name is "John", and when expanding, Row.DataContext is changed to to object with property Name with "John Dough", but column still shows "John").
Ok i found a solution and it seems to be pretty simple.
so ... you hook up event handler to RadGridView.RowDetailsVisibilityChanged and in event handler itself you change Item property of provided Row:
private void OnRowDetailsVisibilityChanged(object sender, GridViewRowDetailsEventArgs e)
{
e.Row.Item = (my New Data);
}
Only problem right now is that row is no longer clickable (details no longer expands when selecting it).
Related
I have a Windows form with a series of list boxes
The contents of subsequent lists change based on choices in earlier ones
All the boxes are bound to a BindingList with OnListChanged enabled
I use this to retain user-specified 'checked' items when elements are added or removed
However, I note that if I add an item to the list, it appears to update the UI only after all the other events have been fired
I've looked at the events I would expect to fire on the CheckedListBox, and in the related ViewModel, in order to catch the one which adds an item to the list, but so far without success
Can someone please advise me which event would allow me to call my 'CheckBoxes' method after the UI has been updated, otherwise they all get set to blank again until the form is closed and opened
private void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
// I've removed the debug statements, but this event when the bound list updates is fired before the UI updates
}
private void teams_checked_list_box_SelectedIndexChanged(object sender, EventArgs e)
{
// same with this event, and the other events like SizeChanged
}
EDITED: On reflection, I realise that the problem occurs because I am not setting the true / false checked flag in the binding, because I couldn't figure out how to do it. If someone could point me in the right direction? Code currently looks like this:
teams_checked_list_box.DataSource = Globals.ThisAddIn.TFSTeamsViewModel.ListOfTeamsFromVM.value;
teams_checked_list_box.DisplayMember = "name";
So basically I am only updating the item name, and the check flag is handled on a later pass
How are you adding items to your list? Are you re-binding the listbox? There are basically two ways you can do this depending on your method of adding items:
If you are re-binding, capture the event BEFORE the item is added. Loop through the CheckedItems property of your list box. Save the values. Add your item. Loop through the NEW values and recheck.
OR
When the user checks the item in the listbox, capture that using the ItemChecked event and then store the value of the item somewhere. (Variable, hidden textbox -- ugly, but it works -- etc.) If you are only adding items to the BOTTOM of your list, you can store the index of the item. If you are re-sorting your list, you'll need to store a unique id to reference the item. (Note: you will also need to REMOVE the checked items from your stored value if the user UN-checks an item in your listbox.) Then, after you add your items to the listbox, loop back through and set the checked value on the appropriate listbox items.
I have created a simple sample with datacontext. Please get the sample from here : source I understand that the uses of DataContext is
If the user change any content in UI, it should be updated in the back end datacontext class without any additional work.
If we make any change in back end datacontext object, it should be updated in UI without any additional work.
In my sample,
If I click "click" button, the textbox value gets updated. - pass
If I click "update" button, the textbox value gets updated. - pass
If I click "clear" button, the textbox value not updated. - fail
After clicked "clear" button, If "click" or "update" button is clicked the textbox value not updated. - fail
Am I doing anything wrong? If yes, how can I initialize some value in the textbox in constructor, and after that if the user make changes, the datacontext object values need to be updated. If I update any value in code behind, the values need to updated in UI. Also if I click "clear" button all the textbox values need to be cleared. After that if user enter value again, the object need to update. How can I achieve it? Please help.
Note: In my sample I have commented some lines. In that i have casted the datacontext to the model class every time and changed it. Its working fine. Do i need to use that method to update values run time. Changing values in object will not update in UI?
The problem is that you consider the variable 'dc' linked to the DataContext, but that is not the case. To fix your code simply set the DataContext again after you change the 'dc' variable.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
dc = new Journal();
myPanel.DataContext = dc;
//myPanel.DataContext = new Journal();
}
I'm fairly new to infragistics and i need help -
i need to add a checkbox to every cell in my grid while still displaying the cell value and allow user to check/uncheck the cell-
for ex - my grid has many columns - text, datetime, numbers etc
each cell will display the text/date/number and also have a checkbox for user to check/uncheck that field
IS THIS POSSIBLE?
One possible way is to add an editor in the grid cells. For example, you can add UltraTextEditor with StateEditorButton (on the left or right as is better for your solution) in each cell like this:
private void UltraGrid_InitializeRow(object sender, InitializeRowEventArgs e)
{
if (!e.ReInitialize)
{
foreach (UltraGridCell cell in e.Row.Cells)
{
StateEditorButton checkBox = new StateEditorButton();
UltraTextEditor textEditor = new UltraTextEditor();
textEditor.ButtonsRight.Add(checkBox);
cell.EditorComponent = textEditor;
cell.Column.ButtonDisplayStyle = ButtonDisplayStyle.Always;
}
}
}
Keep in mind this will add many editors to your grid - bad performance. Other possible solution is to add via Creation Filter the check boxes to your cells.
Either way the main question is - how you will save the checked state back to your data source? If you have a boolean column for each column you actually do not need to add any check boxes. So think how you will save this information.
I am having a Datagrid that gets populated with values from a DataTable. In my program i have four buttons: Goto First, Last, Next and Previous, as the name name indicates i have to select the rows based on the selection made using these buttons. Everything seems well if i use the below code to get the row (for example first row).
DataGridRow row =(DataGridRow)userControl.m_DataGrid.ItemContainerGenerator.ContainerFromIndex(0);
row.IsSelected = true;
But the code throws null value when there is more rows than the height of the Datagrid(When scrollbar comes into picture).
Please help me out of this issue. I think this is because of the view problem.
Due to virtualization the containers are only created when the object is in view, so you could first scroll the item into view using the respective method, wait for the creation of the container and then select it.
As this is rather messy i would suggest binding the IsSelected to a property on your item using a style for DataGridRow (set it as ItemContainerStyle). Then you can just set the property to true and scroll the item into view if need be.
I have a combobox that goes out to the database to load it's content on clicking the dropdown arrow. if after the dropdown box is shown with data and I don't select anything, than the current value of the combobox is blown away. Inside my routine to load data, I tried saving the current value and restoring it back after the loading is done. doesn't work.
[Edit] Added the code from the comment here for legibility
MyUltraCombo myultracombo = new MyUltraCombo();
//MyUltraCombo inherits from UltraCombo inside MyUltraCombo, I keep the table name to load from
MyUltraCombo.BeforeDropDown += new System.ComponentModel.CancelEventHandler(cb_BeforeDropDown);
//inside the eventhandler
myultracombo.Load();
//inside the Load method
datatable = DataUtility.GetAllRecords(tablename);
combobox.datasource = datatable;
If you store "the current value" as just the SelectedItem property, then it will probably not be an object that is present in the new list, since it will consist of completely new objects. What you will have to do is store an ID of the current value (if you're lucky to have a unique id) and then search the newly created list for an object with the same id (or whatever you use to uniquely identify an item, maybe just ToString()...).