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. Image for the cookie policy date

dynamic itemssource inside datagrid

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


3 Replies

DA Divya A Syncfusion Team 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.



KK Kamlesh Kumawat 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


SP Shobika Palani Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon