This is a migrated thread and some comments may be shown as answers.

[Solved] Issue with GridView Combo box

12 Answers 241 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sulagna
Top achievements
Rank 1
sulagna asked on 13 Jan 2011, 10:05 AM
Hi,
I have a IterationStatusCollection property in view model which gets the status list current,waiting and closed.They are the combo box list tems.Inside row loaded I am running 2 linq queries to fill the StatusList as per my requirement.This StatusList I am binding to the xaml.
In new row I am also adding the required list but the problem is when I click on the current iteration(refer WrongCurrentStatusList.jpg) it holds the last updated listof Waiting status which is wrong it should hold its own list.
What should I do to update the list everytime??I also tried with 2 individual properties but no use.Plz help.

public void RadProjectIterationGridView_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            GridViewRow row = e.Row as GridViewRow;
            //Get parent grid.
            RadGridView _radGridView = e.GridViewDataControl as RadGridView;          
            if (e.Row is GridViewRow && !(e.Row is GridViewNewRow))
            {
                Iteration iteration = e.DataElement as Iteration;
                  if (e.Row.Cells[5].Content != null)
                    {                                       
                        if(((LeMonNext.Common.Entities.Iteration)(((System.Windows.FrameworkElement)(e.Row.Cells[4].Content)).DataContext)).IterationStatusID.ToString() == LeMonNextResource.IterationClosedStatusID)
                        {
                            e.Row.Cells[5].IsEnabled = false;
                            e.Row.IsEnabled = false;
                        }
                        else
                            if (iteration != null & e.Row.Cells[5].Content != null)
                                if (iteration.IterationStatus == LeMonNextResource.IterationCurrentStatus && iteration.IterationID != 0)
                                {
                                    this.StatusList = (from _statusRead in this.IterationStatusCollection
                                                       where _statusRead.IterationStatusId != 7
                                                       select _statusRead).ToList<IterationStatus>();
                                    (_radGridView.Columns["IterationStatus"] as GridViewComboBoxColumn).ItemsSource = StatusList;
                                                                       
                                }

                        if (iteration.IterationStatus == LeMonNextResource.IterationWaitingStatus && iteration.IterationID == 0)
                        {
                            this.StatusList = (from _statusRead in this.IterationStatusCollection
                                               where _statusRead.IterationStatusId != 9
                                               select _statusRead).ToList<IterationStatus>();
                            (_radGridView.Columns["IterationStatus"] as GridViewComboBoxColumn).ItemsSource = StatusList;                           
                        }                       
                    }               
            }
        }

public void RadProjectIterationGridView_AddingNewDataItem(object sender, GridView.GridViewAddingNewEventArgs e)
        {
            RadGridView _radGridView = e.OwnerGridViewItemsControl as RadGridView;
            IEnumerator<Iteration> iterEnum = IterationCollection.GetEnumerator();
            int i = 0;
            //Finding the current row
            while (i < IterationCollection.Count)
            {
                ++i;
                iterEnum.MoveNext();
            }
            Iteration iter = iterEnum.Current;
            //Finding the duration of the project
            if (ClientStateService.SelectedProject.ProjectId != 0)
            {
                ProjectIterationHelper projectIterationHelper = new ProjectIterationHelper();
                Iteration newIteration = projectIterationHelper.CreateNewIteration(ClientStateService.SelectedProject, iter);

                if (newIteration.IterationID==0 && newIteration.IterationStatus == LeMonNextResource.IterationWaitingStatus)
                {
                    this.StatusList = (from _statusRead in this.IterationStatusCollection
                                       where _statusRead.IterationStatusId != 9
                                       select _statusRead).ToList<IterationStatus>();
                    (_radGridView.Columns["IterationStatus"] as GridViewComboBoxColumn).ItemsSource = StatusList;
                }
                e.NewObject = newIteration;
            }
        }
My xaml where StstusList is there
<telerik:GridViewComboBoxColumn   
         DataMemberBinding="{Binding IterationStatusID,Mode=TwoWay}"
                                            SelectedValueMemberPath="IterationStatusId"
                                            DisplayMemberPath="IterationStatusName" 
                                            UniqueName="IterationStatus" Width="80"
                                            IsResizable="False" ItemsSource="{Binding Path = StatusList,Mode=TwoWay}"                
                                            HeaderCellStyle="{StaticResource CustomHeaderCellStyle}"                                           
                                            CellTemplate="{StaticResource StatusComboBoxSelectionBoxTemplate}">
                </telerik:GridViewComboBoxColumn>
My StsusList in view model:
public IList<IterationStatus> StatusList
        {    get
            {    return this._status;            }
            set
            {
                if (_status != value)
                {   _status = value;
                    OnPropertyChanged("StatusList");
                }
            }
        }
Thanks,
Sulagna

12 Answers, 1 is accepted

Sort by
0
sulagna
Top achievements
Rank 1
answered on 13 Jan 2011, 01:03 PM
Hi,
The above issue got resolved by BeginningEdit.Other issue I am facing in Cell validating.i.e when I change the cell value from current to closed it should allow the user to do any action after showing one alert but I am not able to save or do any thing.If I make IsValid true then also it restrict.
   if (e.NewValue != null)
                    {
                        //Making current iteration closed
                        if (e.NewValue.ToString() == LeMonNextResource.IterationClosedStatusID)
                        {
                            MessageBox.Show("Once you close an iteration, You won't be able to make further changes to it." +
                                    "\n" + "Are you sure, You want to continue?");
                           
                            if (MessageBoxButton.OK == 0)
                            {
                                e.Row.Cells[5].Content = "Closed";
                                e.IsValid = false;
                            }
                        }
Should I write this inside GridViewComboBox selection change event?I tried with this but I am not getting SelectionChangedEvent.
Is this "RadComboBox" the name of GridViewComboBoxColumn?
this.RadGridView1.AddHandler(RadComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(OnSelectionChanged));
 
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // TODO: Implement this method
    throw new NotImplementedException();
}
My xaml is
    <telerik:GridViewComboBoxColumn  x:Name="ComboBox"
                                            DataMemberBinding="{Binding IterationStatusID,Mode=TwoWay}"
                                            SelectedValueMemberPath="IterationStatusId"
                                            DisplayMemberPath="IterationStatusName" 
                                            UniqueName="IterationStatus" Width="80"
                                            IsResizable="False" ItemsSource="{Binding Path = StatusList,Mode=TwoWay}"                 
                                            HeaderCellStyle="{StaticResource CustomHeaderCellStyle}"                                           
                                            CellTemplate="{StaticResource StatusComboBoxSelectionBoxTemplate}"/>
 
Regards,
Sulagna            
0
Maya
Telerik team
answered on 13 Jan 2011, 06:31 PM
Hi sulagna,

I have tried to implement the idea of using the CellValidating event in a way like you do and everything works as expected. What is the exact issue that you experience ? Furthermore, it is not exactly recommended to work with the values of the visual elements - the content of a cell in your case. You would better find the corresponding property of the data item and set it instead.
Another possible approach may be to handle the CellEditEnded event and implement your logic inside it.
As far as the SelectionChanged event is concerned, you may use it too. The RadComboBox is not the name of the column, but the control inside it. It fires the SelectionChanged event that you subscribe to by adding a handler. 
 

All the best,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
sulagna
Top achievements
Rank 1
answered on 14 Jan 2011, 07:07 AM
Hi Maya,
I tried CellEditEnded event but here also I am facing the same issue.When the user changes the iteration from current to closed it should change the combobox item to close & allow the user to do any kind of action after displaying one alert.But what its doing is its changing the combo box item to Current it should retain Closed state.This is happing in CellEditEnded as well as CellValidating both. In CellValidating if I make  e.IsValid = false; then it changes the value to Closed but restricts the user to proceed.

Thanks,
Sulagna
0
Maya
Telerik team
answered on 14 Jan 2011, 10:28 AM
Hello sulagna,

I am sending you a sample project illustrating a possible approach for achieving the desired result. You may test the functionality by selecting Ana Trijillo from the source of the GridViewComboBoxColumn.
 

All the best,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
sulagna
Top achievements
Rank 1
answered on 14 Jan 2011, 11:31 AM
Hi,
I am not able to run that application its giving unhandled exception in Silverlight Application Code-4004 error.Just in time debugger error.
Other issue is.... to test that combo box selection I disabled all the event calls to check its able to hold the combo box changed value or not but strange that its not holding.After selection if I click outside the grid anywhere its going back to its previous status(item).Am I missing something?Please help.

Thanks,
Sulagna  
0
Maya
Telerik team
answered on 14 Jan 2011, 11:57 AM
Hello sulagna,

In case you are not able to run it, you may just take a look at the MainPage.xaml.cs code and more specifically on the CellEditEnded event. 
As far as the second issue is concerned, I would need a bit more details about the way you are handling the SelectionChanged event. Generally, there should be no problem for you to edit and save the values. Are the values of the other cells retained after editing ?
 

Greetings,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
sulagna
Top achievements
Rank 1
answered on 14 Jan 2011, 12:03 PM
I am not handling any event now.I commented all that.In general when we select an item in the combo box it should hold that perticular value not the previous value but in my case if I select some other value its setting the previous value.Why its behaving like that?

Thanks,
Sulagna 
0
Maya
Telerik team
answered on 14 Jan 2011, 12:33 PM
Hi sulagna,

Is that behavior observed only when editing values in the GridViewComboBoxColumn or it is the same for all the other columns ? May you try to add a GridViewDataColumn, whose DataMemberBinding is set to the same property as the for the GridViewComboBoxColumn and edit it?   Do you handle any other events that may be relevant to this issue ? 
Still, I am sending you another - different than the previous one - project demonstrating a possible approach for implementing a GridViewComboBoxColumn, so that you can use it as a reference. (The EntityCollectionView in the project is used only with the purpose of adding the functionality of inserting and deleting items). Feel free to change it in the way you want and send it back if needed.
However, it would be great if you could send a sample project so that I could see your exact settings and can make a specific suggestion not only a guess. 
 

Best wishes,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
sulagna
Top achievements
Rank 1
answered on 14 Jan 2011, 01:10 PM
Yes that behavior is observed only when editing values in the GridViewComboBoxColumn but I have commented that row_editended event.I am only selecting the combobox item.

When I remove CellTeplate it works fine holds the selected combo box changed vales but the entire column disappears.If I click on the column it appears and again disappears if I click outside.So what should I do to get the column values in place? To fix that combo box selection issue I need to remove celltemplate but how to fix that disappearing issue? Below is my xaml. How can I upload size limit is 2 MB ?
<telerik:GridViewComboBoxColumn
                                            DataMemberBinding="{Binding IterationStatusID,Mode=TwoWay}"
                                            SelectedValueMemberPath="IterationStatusId"
                                            DisplayMemberPath="IterationStatusName"   
                                            UniqueName="IterationStatus" Width="80"
                                            IsResizable="False" ItemsSource="{Binding Path = IterationStatusCollection}"                 
                                            HeaderCellStyle="{StaticResource CustomHeaderCellStyle}">
                    <telerik:GridViewComboBoxColumn.Header>
                        <StackPanel>
                            <TextBlock Text="Status*" Style="{StaticResource CustomHeaderLabelStyle}" Width="48" />
                        </StackPanel>
                    </telerik:GridViewComboBoxColumn.Header>                   
                    <telerik:GridViewComboBoxColumn.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding IterationStatusName}" Grid.Column="0"></TextBlock>
                            </Grid>
                        </DataTemplate>                       
                    </telerik:GridViewComboBoxColumn.ItemTemplate>
                    <telerik:GridViewComboBoxColumn.CellTemplate>
                        <DataTemplate >
                            <TextBlock Text="{Binding IterationStatus}" HorizontalAlignment="Left"  />
                        </DataTemplate>
                    </telerik:GridViewComboBoxColumn.CellTemplate>
                </telerik:GridViewComboBoxColumn>

Thanks,
Sulagna
0
Maya
Telerik team
answered on 14 Jan 2011, 03:13 PM
Hi sulagna,

You may take a look at this article for a reference on the way of solving the issue with the GridViewComboBoxColumn (while the no CellTemplate is defined).
 

Greetings,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
sulagna
Top achievements
Rank 1
answered on 17 Jan 2011, 10:59 AM
Hi,
I tried the 2nd approach of binding the itemsource at runtime.But if I do that and remove cell templete it only displays the combobox list having 3 items in all the rows but doesnt show the default value(different status for each row).For that I need Cell Templete.Now if I put cell templete and bind the list at run time it solves the purpose but if I change the items in the combobox it holds the previous value(the propblem that I was facing earlier).I found a link in google
http://www.windowsdevelop.com/windows-forms-data-controls-databinding/how-to-get-datagridviewcomboboxcolumns-selected-value-for-validation-34947.shtml

which says to cast the EditingControl property to a combobox and access the SelectedValue property.How can I get EditingControl property in my case?Where will I get that?
Please help.

Thanks,
Sulagna
0
Maya
Telerik team
answered on 17 Jan 2011, 04:39 PM
Hello sulagna,

Generally, there is no need to define a CellTemplate in order the corresponding value of the item to be displayed in the GridViewComboBoxColumn. You may take a look at our demo to check what should be the default behavior and settings of the column on different ItemsSources.
However, since I am not able to provide any further suggestions based only on the code-snippets, it would be best if you send a sample project (via support ticket). Thus I will be able to see your exact settings and scenario and give the most accurate and appropriate solution.

Best wishes,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
sulagna
Top achievements
Rank 1
Answers by
sulagna
Top achievements
Rank 1
Maya
Telerik team
Share this question
or