Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
703
Issues while using XamWebgrid
posted
Hi I have few problems while implementing xamwebgrid. I am using VB as code-behind. 1. I need a easy way to bind xamweb grid. I dont find any helpful resource either on your documentation of local samples. I have WCF service returning list, now i want to bind the grid from this list in xaml/vb both but with lesser code. I want it some what this way , like in my earlier WPF apps, i used to create a object dataprovider of the collection/class and then it is called as itemsource for the grid / grid elements. 2.My second problem is that whenever i add new rows to the grid , my values get lost from the grid. Please have a look at the xaml.txt file. Its my xaml snippet of grid. The first three columns of project , milestone and class looses their values. They have textbloxk in their datatemplate and combobox in editor template. I am using here four different collections. The item source of the grid is from collection of class TaskModel which holds Project/Milestones/Class and all other columns While in the Editor template, Project/Milestone and Class dropdown are binded from 3 different lists. While selection they are displaying fine but as soon as they are entered they looses their value. 3. I have few elements out side the grid but these needs to be inserted/updated to db. Help me in achieveing this. 4. I have 7 columns in my grid , i am adding their values and displaying in a dynamically generated column on cell exit edit eevent. But not able to get any method/property to set value in their respective total cell. That is 8th column is of total for 5 rows. so total of row[0]from col[0]to col[7] will be displayed in col[8] which is dynamic and is readonly too. 5. Also when i am adding new row, my new row index show -1 , which throws object refence error as my calculation for totaling starts from 0. Even if i use not nothing condition, it still happening Please , help me asap.
Parents
No Data
Reply
  • 9694
    posted

    Hello Amit,

    I apologize that no one has yet repsonded to this post. In case you can still use the help you were looking for, I hope to answer all your questions.

    I have attached a sample Silverlight project that loosely mimics the XAML you have attached. It utilizes a ViewModel, sample data generated by Expression Blend, and is written in Silverlight 4 and VB. It illustrates how to bind a ViewModel to a XAML UserControl.

    1. Binding to the XamGrid is simple. Since you have data being returned from a WCF service, you need to copy the data to a collection that the XamGrid can be bound to. The convention I prefer is to create a ViewModel class. If you look at the attached sample, the ViewModel constructor gets the data. If you bind the ViewModel to the XAML you can display sample data for design mode and access your service when not in design mode.

    Here is a sample of a shared property that returns if the application is in design mode (running in the Blend or Visual Studio Designer):

    Public Shared Property InDesignMode() As Boolean
            Get
                If Application.Current Is Nothing Or
                   
     Application.Current.RootVisual Is Nothing Then
                    Return True
                Else
                    Return DesignerProperties.GetIsInDesignMode(
                                                           Application.Current.RootVisual)
                End If
            End Get 
            Private Set(ByVal value As Boolean
            End Set
        End Property

    And here is the code for instantiating the ViewModel, Binding it to the DataContext of the layout and binding the collection in the ViewModel to the XamGrid:

    <UserControl.Resources>
            <local:MainViewModel x:Key="ViewModel"/>
    </UserControl.Resources>
        
    <Grid x:Name="LayoutRoot" Background="White" 
        DataContext
    ="{Binding Source={StaticResource ViewModel}}">

            <igGrid:XamGrid
                Name="dgTimeSheet"
                ItemsSource="{Binding TaskCollection}">

    ...

    XamGridVBSample.zip
Children