We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

dynamic itemssource inside datagrid

Thread ID:

Created:

Updated:

Platform:

Replies:

109887 Jul 9,2013 01:00 PM UTC Jun 15,2018 03:45 AM UTC WPF 3
loading
Tags: GridDataControl
Andreas Löwe
Asked On July 9, 2013 01:00 PM UTC

Hi,

perhaps there exists a solution for my Problem.

http://www.syncfusion.com/support/forums/grid-wpf/106267/Column-combobox-itemsource

but this sample download works not.

Could you please reactivate also other examples. many links to sample files doesn't work.

If it's impossible, would you mind to offer a sample with a Combobox column .

The itemssource depends on the Content of the row

Cheers

 

Andreas Löwe


Divya A [Syncfusion]
Replied On August 1, 2013 10:49 AM UTC

Hi Andreas,

Sorry for the delay caused.

We can set dynamic Items Source for Combo Box in GridDatacontrol by using QueryCellInfo event. Here, you can retrieve the Particular record from its CellIdentity and also you can check for the Particular column using its mapping name and can assign your dynamic items source to that particular cell as in the following code snippet.

Code Snippet:

void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)

         {

            var style = e.Style as GridDataStyleInfo;

            var cellidentity = style.CellIdentity;

            if (cellidentity != null && cellidentity.Record != null && cellidentity.Column.MappingName == "State")

            {

                //Here based on the cellidentity.Record, you can apply items source 

                var Record = cellidentity.Record as Model;

                var item = Record.Country;

 

                if (item.ToString().Contains("USA"))

                {

                    e.Style.ItemsSource = new USStateRepository();

                }

 

                e.Style.CellValue = ((ObservableCollection<String>)e.Style.ItemsSource)[0];

            }

We have also prepared a sample based on this and attached it in the following location.

Sample: http://www.syncfusion.com/downloads/Support/DirectTrac/110535/Country%20correct605559276.zip

Regarding the “Dead Links in forum”

Due to a server failure at one of our hosting sites, the file you are looking for is not available. We are making every effort to retrieve this file and other files that are unavailable as a result of this outage. We regret this inconvenience. We will inform you when the file has been recovered. If you need any other sample from Forums then please let us know the Forum link or your requirement, we will prepare a sample based on your requirement and update you with the details.

Regards,

Divya.


Kamlesh Kumawat
Replied On June 5, 2018 06:07 PM UTC

The given example works. But say, if I resize the column the event "Model.QueryCellInfo" calls again and I loose my selected item. There may other UI interactions as well which may call QueryCellInfo event.

Do you have solution for this?

Thanks!
Kamlesh

Shobika Palani [Syncfusion]
Replied On June 15, 2018 03:45 AM UTC

Hi Andreas, 
 
We have analyzed your query and you can achieve you requirement by using below code snippet 
 
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
        { 
            var style = e.Style as GridDataStyleInfo; 
            var cellidentity = style.CellIdentity; 
            if (cellidentity != null && cellidentity.Record != null && cellidentity.Column.MappingName == "State") 
            { 
                var Record = cellidentity.Record as Model; 
                var item = Record.Country; 
                if (item.ToString().Contains("USA")) 
                { 
                    e.Style.ItemsSource = new USStateRepository(); 
                } 
                else if (item.ToString().Contains("Australia")) 
                { 
                    e.Style.ItemsSource = new AusStateRepository(); 
                } 
                else if (item.ToString().Contains("India")) 
                { 
                    e.Style.ItemsSource = new IndStateRepository(); 
                } 
                var itemsource = e.Style.ItemsSource as ObservableCollection<string>; 
                if(!(itemsource.Contains(e.Style.CellValue.ToString()))) 
                    e.Style.CellValue = ((ObservableCollection<String>)e.Style.ItemsSource)[0]; 
            } 
        } 
 
Please find sample for the same from below link 
 
Regards, 
Shobika 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;