But in my case i want to bind the data With the use of WCF source. But i cant able to bind the data for combobox in code behind because of cant able to get the Combobox name from datatemplate like
cbotest.ItemSource = e.Result;
How can i do this fuctionalities . Please help me.
How to get Template field control id in silverlight datagrid.
I also take the code from that site only.But the itemsource of the Combobox is given in sourcecode itself.But i want to bind the datasource for combobox from WCF service for this how can i do?.
Here i have modified City;provider class only.Here Service is returning data from which property is getting populated.
public class CityProvider
{
public CityProvider()
{
ServiceReference2.WebService1SoapClient client = new SilverlightApplication2.ServiceReference2.WebService1SoapClient();
client.HelloWorldCompleted+=new EventHandler<SilverlightApplication2.ServiceReference2.HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
you can access resource in codebehind also and can set its property.
Some thing like below mentined code.
public Page()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
ServiceReference2.WebService1SoapClient client = new SilverlightApplication2.ServiceReference2.WebService1SoapClient();
client.HelloWorldCompleted += new EventHandler<SilverlightApplication2.ServiceReference2.HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
Thanks for reply.But i am not clear how to use this code, and also its showing error while using like (The type or namespacename 'ObjectX' could not be found). Please give me any sample code using with WCF service.
ObjectX describes an example of type of your object.... In your case, I guess you have a asynchron method to retrieve an ObservableCollection (or a List) of objects
You must have something like ObservableCollection<typeofObject> myCollect = e.result ;
After, you can bind with your datagrid, using ItemsSources property like myDatagrid.ItemsSource = myCollect. If you want the current row in your datagrid, create a new object (with the same type like in your ObservabeCollection) and then
TypeOfObject myObj = myDatagrid.SelectedItem as TypeOfObject. So you could have access to all the properties of your objet..
For example :
My class :
public class Cat
{
public string sName { get; set; }
}
My WCF call :
public void loadClient(string codends)
{
srFormation.Service1Client myService = new nSLFormationWeb.srFormation.Service1Client();
myService.GetCatCompleted += new EventHandler<nSLFormationWeb.srFormation.GetCatCompletedEventArgs>(myService_GetCatCompleted);
myService.GetCatAsync();
}
kargo
Member
52 Points
142 Posts
How to get Template field control id in silverlight datagrid.
Jul 03, 2009 08:46 AM | LINK
I can able to bind the data to template field combobox as follow
<
data:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <ComboBox x:Name="cbotest" ItemsSource="{Binding CityList, Source={StaticResource cityProvider}}" SelectedItem="{Binding CityInfo, Mode=TwoWay}" DisplayMemberPath="CityName"/></DataTemplate> </data:DataGridTemplateColumn.CellEditingTemplate>But in my case i want to bind the data With the use of WCF source. But i cant able to bind the data for combobox in code behind because of cant able to get the Combobox name from datatemplate like
cbotest.ItemSource = e.Result;
How can i do this fuctionalities . Please help me.
How to get Template field control id in silverlight datagrid.
HarshBardhan
Star
10118 Points
1749 Posts
Re: How to get Template field control id in silverlight datagrid.
Jul 03, 2009 12:55 PM | LINK
check this article for combobox inside a datagrid.
http://weblogs.asp.net/manishdalal/archive/2008/09/28/combobox-in-datagrid.aspx
Harsh Bardhan
koyot3
Participant
805 Points
177 Posts
Re: How to get Template field control id in silverlight datagrid.
Jul 03, 2009 01:04 PM | LINK
with your wcf service, you must have a list or an observablecollection of Object X.
try it :
myDatagrid.itemsSource = null
myDatagrid.itemsSource = myCollection or myList
kargo
Member
52 Points
142 Posts
Re: Re: How to get Template field control id in silverlight datagrid.
Jul 03, 2009 01:33 PM | LINK
Hi HarshBardhan,
I also take the code from that site only.But the itemsource of the Combobox is given in sourcecode itself.But i want to bind the datasource for combobox from WCF service for this how can i do?.
koyot3
Participant
805 Points
177 Posts
Re: Re: How to get Template field control id in silverlight datagrid.
Jul 03, 2009 02:04 PM | LINK
for example, in the link you bind the combobox with city1, city2....
create a class City
set property public string cityName { get; set;}
next, use you wcf to receive a collectyion of City Object like
ObservableCollection<City> myCollect = new ObservableCollection<City>()
mycollect = e.result ;
also you can use this collection to bind with your combobox !!!
hope this help
HarshBardhan
Star
10118 Points
1749 Posts
Re: Re: How to get Template field control id in silverlight datagrid.
Jul 03, 2009 02:29 PM | LINK
Hi Kargo,
You can try with something like this.
Here i have modified City;provider class only.Here Service is returning data from which property is getting populated.
public class CityProvider
{
public CityProvider()
{
ServiceReference2.WebService1SoapClient client = new SilverlightApplication2.ServiceReference2.WebService1SoapClient();
client.HelloWorldCompleted+=new EventHandler<SilverlightApplication2.ServiceReference2.HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
client.HelloWorldAsync();
}
void client_HelloWorldCompleted(object sender, SilverlightApplication2.ServiceReference2.HelloWorldCompletedEventArgs e)
{
CityList = e.Result;
}
public List<string> CityList
{
get;
set;
}
}
you can access resource in codebehind also and can set its property.
Some thing like below mentined code.
public Page()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
ServiceReference2.WebService1SoapClient client = new SilverlightApplication2.ServiceReference2.WebService1SoapClient();
client.HelloWorldCompleted += new EventHandler<SilverlightApplication2.ServiceReference2.HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
client.HelloWorldAsync();
}
void client_HelloWorldCompleted(object sender, SilverlightApplication2.ServiceReference2.HelloWorldCompletedEventArgs e)
{
CityProvider cprovider = ((CityProvider)(this.Resources["cityProvider"]));
cprovider.CityList = e.Result;
}
Harsh Bardhan
kargo
Member
52 Points
142 Posts
Re: Re: Re: How to get Template field control id in silverlight datagrid.
Jul 06, 2009 10:45 AM | LINK
Thanks HarshBardhan,
Its working, But how can i show the Selected value on page loding time in the grid.
thanks,
kargo
koyot3
Participant
805 Points
177 Posts
Re: Re: Re: How to get Template field control id in silverlight datagrid.
Jul 06, 2009 11:03 AM | LINK
do you want to shwo your selected value in your datagrid ?
if yes, try
ObjectX myObjetX = datagrid.SelectedItem as ObjectX
kargo
Member
52 Points
142 Posts
Re: Re: Re: How to get Template field control id in silverlight datagrid.
Jul 07, 2009 06:58 AM | LINK
Hi koyot3,
Thanks for reply.But i am not clear how to use this code, and also its showing error while using like (The type or namespacename 'ObjectX' could not be found). Please give me any sample code using with WCF service.
koyot3
Participant
805 Points
177 Posts
Re: Re: Re: How to get Template field control id in silverlight datagrid.
Jul 07, 2009 07:22 AM | LINK
Hey Kargo,
ObjectX describes an example of type of your object.... In your case, I guess you have a asynchron method to retrieve an ObservableCollection (or a List) of objects
You must have something like ObservableCollection<typeofObject> myCollect = e.result ;
After, you can bind with your datagrid, using ItemsSources property like myDatagrid.ItemsSource = myCollect. If you want the current row in your datagrid, create a new object (with the same type like in your ObservabeCollection) and then
TypeOfObject myObj = myDatagrid.SelectedItem as TypeOfObject. So you could have access to all the properties of your objet..
For example :
My class :
public class Cat
{
public string sName { get; set; }
}
My WCF call :
public void loadClient(string codends)
{
srFormation.Service1Client myService = new nSLFormationWeb.srFormation.Service1Client();
myService.GetCatCompleted += new EventHandler<nSLFormationWeb.srFormation.GetCatCompletedEventArgs>(myService_GetCatCompleted);
myService.GetCatAsync();
}
void myService_GetCatCompleted(object sender, nSLFormationWeb.srFormation.GetAllClientFor1FormCompletedEventArgs e)
{
myCollect = new ObservableCollection<Cat>();
myCollect = e.Result;
dgCat.ItemsSource = null;
dgCat.ItemsSource = myCollect;
}
private void GetName()
{ Cat myCat = dgCat.SelectedItem as Cat;
MessageBox.Show("Name : "+myCat.sName); //if you want to display the name of the cat
Hope this help you !!
Johan