Telerik Forums
UI for WPF Forum
0 answers
119 views
Hi,

I have referred  the sample( http://www.telerik.com/community/forums/wpf/gridview/can-t-use-celledittemplateselector-amp-celltemplateselector-together.aspx) for setting CellTemplate by using CellTemplateSelector.

I modified this sample to use DataTable as source instead of List<Item>(). In this case, i am not able to see any data in the second column of the Grid.

The code i have changed is:
public MainWindow()
{
InitializeComponent();
//List<Item> items = new List<Item>();
            //items.Add(new Item() { PropertyName = "Property1", PropertyType = typeof(string), PropertyValue = "blabla" });
            //items.Add(new Item() { PropertyName = "Property1", PropertyType = typeof(Visibility), PropertyValue = Visibility.Visible });

            DataTable items = new DataTable();
            items.Columns.Add("PropertyName");
            items.Columns.Add("PropertyType",typeof(Type));
            items.Columns.Add("PropertyValue");
            DataRow row1 = items.NewRow();
            row1[0] = "Property1";
            row1[1] = typeof(string);
            row1[2] = "blabla";
            items.Rows.Add(row1);
            row1 = items.NewRow();
            row1[0] = "Property1";
            row1[1] = typeof(Visibility);
            row1[2] = Visibility.Visible;
            items.Rows.Add(row1);         
this.dataGrid1.ItemsSource = items;
}

class PropertyValueDataTemplateSelector:
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
           var r= item as System.Data.DataRow;
           Type value= r["PropertyType"] as Type;
           if (value == typeof(string))
                return this.TextTemplate;
            else
                return this.EnumTemplate;
}

Not able to figure out what is the issue.
Please give updated sample using DataTable as ItemSource.
Thanks for your help.

Thangalskhmi
Top achievements
Rank 1
 asked on 25 May 2011
0 answers
274 views
Hi,
I am using RadGridview which Itemsource is Observablecollection<CustomObject>
While editing particular cell, i want to change the another cell's content which is read only.
For Example:
Public class CustomObject
{
 public string Identifier{get;set;} 
 public string  DisplayName{get;set;}
}

My requirement is when i change the Identifier, need to change the "DisplayName" value.
I tried to change the "DisplayName" value in both CellValidated and CellValidating event. But not able to see the updated value in the UI.
I tried grid.Rebind() in both CellValidated and CellValidating event, the current cell (i.e Identifier) modification is getting lost and the updated DisplayName  value is shown in the UI.
How to modify the other column value based on some cell value changes and refresh the GridView?

code snippets:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            grid.CellValidated -= new EventHandler<Telerik.Windows.Controls.GridViewCellValidatedEventArgs>(grid_CellValidated);
            grid.CellValidated += new EventHandler<Telerik.Windows.Controls.GridViewCellValidatedEventArgs>(grid_CellValidated);
            grid.ItemsSource = GetObservableList();         
        }      

        void grid_CellValidated(object sender, Telerik.Windows.Controls.GridViewCellValidatedEventArgs e)
        {
            Telerik.Windows.Controls.RadGridView g = e.Cell.DataColumn.Parent as Telerik.Windows.Controls.RadGridView;
            //Modify the DisplayName cell  value.
            var currentObj = e.Cell.DataContext as CustomObject;
            currentObj.DisplayName = "Test";
            var list = g.ItemsSource as ObservableCollection<CustomObject>;
            CustomObject p = list.Where(obj => obj.UniqueKey == currentObj.UniqueKey).FirstOrDefault();
            p = currentObj;
            p.DisplayName = "Test";
        }   
        private static ObservableCollection<CustomObject> GetObservableList()
        {
            ObservableCollection<CustomObject> table = new ObservableCollection<CustomObject>();
            for (int i = 0; i <= 3; i++)
            {
                CustomObject p = new CustomObject();
                p.UniqueKey = "aa" + i;
                p.Identifier = "des" + i;
                p.DisplayName = "arfea" + i;
                table.Add(p);
            }
            return table;
        }

        public class CustomObject
        {
            public CustomObject() { }
            private string _key = null;
            private string _identifier = null;
            private string _displayName = null;
            public string UniqueKey { get { return _key; } set { _key = value; } }
            public string Identifier {get { return this._identifier; } set { this._identifier = value;}}
            public string DisplayName { get { return this._displayName; } set { this._displayName = value; } }
        }
    }

XMAL:
 <Grid>
        <telerik:RadGridView  x:Name="grid" x:FieldModifier="public"  AutoGenerateColumns="False" ItemsSource="{Binding}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding UniqueKey}" Header="UniqueKey" UniqueName="UniqueKey"  />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Identifier, Mode=TwoWay}" UniqueName="Identifier" Header="Identifier"  />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding DisplayName, Mode=OneWay}" UniqueName="DisplayName" Header="DisplayName" IsReadOnly="True" />               
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>        
    </Grid>

Thanks,
Thanga
Thangalskhmi
Top achievements
Rank 1
 asked on 24 May 2011
24 answers
1.3K+ views
Hi,

How do I define a checkbox column in WPF GridView control?

Thanks

Miroslav
sarag
Top achievements
Rank 1
 answered on 24 May 2011
8 answers
545 views
I created a Windows WPF project and am using the RadGridView that has a child table using a TableRelation. I want to be able to hide the expand/collapse image if there are no child records. I saw an example or two that were similar to what I wanted, but populate the grid by adding records within a loop. I am assigning the ItemSource of the grid and DataSource of the GridViewTableDefinition and haven't been able to find an example of what I want that populates the grid in this way. I tried using the "PreviewDataRecordCreate" event, but it doesn't seem to fire when assigning the ItemSource. I would really like to avoid adding records by looping through the data. I looked through the API and didn't see anything obvious, but will continue to look. Have I just overlooked something or is there not a simple way to do this? Thanks.
Daryl
Top achievements
Rank 1
 answered on 24 May 2011
6 answers
207 views
Dear Sir,


I m binding the observable collection of the object having properties like attachment, isUnread , priority, id  having values either {true/False}, {true/False}, {1,2, or 3} respectively. Assuming attachment = true, isUread = false, priority = 1  , id is autoincrement .

Now when i update it from user form  : attachment = false , isUread = true, priority = 3 .... recording displayed is not update in GridView. For updating the same i need to load again and again gridview with observable collection just for 1 record i m loading 100 record or even more which not desirable. how to solve this problem.  can i only change gridview UI part. 


Thanks in advance.

Miral Shah 
Jon
Top achievements
Rank 1
 answered on 24 May 2011
5 answers
661 views
I am trying to find out if there is the link where I can download themes source for WPF controls. I want to be able to customize default theme templates. 
Milan
Telerik team
 answered on 24 May 2011
3 answers
246 views
Hi,

I need a ColorPicker (or some other wat to select and show a color) in a column, the value is a string (html/hex as color values).

How do make this, code please...

Thanks!
Vanya Pavlova
Telerik team
 answered on 24 May 2011
1 answer
103 views
Hello

I have 2 gridviews and one of them is empty. When i drop a row to second grid, it is not even firing DropInfo event. Is there a solution for dropping to an empty Grid?

Thanks
Ram
Tsvyatko
Telerik team
 answered on 24 May 2011
10 answers
408 views

Hi,

I want the user to be able to navigate through the tree and actively select one or several nodes by the use of the keboard.

I have tried the all kinds of different options on the RadTreeListView. Added the GridViewSelectColumn, set the SelectionMode to Extended, set the CanUserSelect to false.
When I try to navigate with the keyboard I get unexpected behaviour.

What settings should I use?

Best regards
Erik

 

 

 

 

Erik
Top achievements
Rank 1
 answered on 24 May 2011
7 answers
105 views
I have auto generated columns on (I want that so the code can be generic, I don't want to specify table names and layout).
I am binding to 3 tables in a DataSet by an Id (PROPERTY_ID) , so there are three levels of nesting.

 

 

 

 

 

 

 

 

 

 

 

// start code snippet...
x_GRID.AutoGenerateColumns = true
  
dd.Tables.Add(t); // PARENT TABLE 
dd.Tables.Add(t0); // CHILD TABLE A
  
dd.Tables.Add(t1); // CHILD (CHILD) TABLE B - This is a child of table A
  
dd.Relations.Add(new DataRelation("Prop_Params", dd.Tables[0].Columns["PROPERTY_ID"], dd.Tables[1].Columns["PROPERTY_ID"])); 
  
   
dd.Relations.Add(new DataRelation("Section_Params", dd.Tables[1].Columns["PROPERTY_ID"], dd.Tables[2].Columns["PROPERTY_ID"]));
  
x_GRID.ItemSource = dd;
  
// end code snippet...
  
A few questions - I am in the DataLoading event (see questions in comments below)
void wpfgv_DataLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs e) 
{
   var dataControl = (GridViewDataControl)sender; 
  
// 1. ParentRow != null tells me that it is a child table,
// but I need to know which CHILD TableName it is
// So that I can do different things for child table A and child (child) table B
// (like hide a column that child table A has but child table B does not.  
// How do I get the TableName of what dataControl is referring to
// (I could not seem to find it in my debugging watches)???
   if (dataControl.ParentRow != null
   {
      dataControl.ShowGroupPanel = false ;
  
// 2. I "think" because I have AutoGenerateCols = true, datacontrol.Columns = null
// so this crashes if left uncommented...
// just trying to verify my thinking on why it is null. 
  
dataControl.Columns["PROPERTY_ID"].IsVisible = false// will crash
  
// 3. x_GRID is the name of my GridView Control.  
// While this works, it only hides the PROPERTY_ID of the
// PARENT table column called PROPERTY_ID 
// and does NOT hide child columns of the same name (which is exactly
// the opposite of what I want to do).
// Is there a way without setting x_GRID.AutoGenerateColumns = false
// and binding each column
// in code or xaml to hide just columns of the children???
  
    x_GRID.Columns["PROPERTY_ID"].IsVisible = false ;  
   }
}

 

Thanks,

Daryl

 

 

 

Tsvyatko
Telerik team
 answered on 24 May 2011
Narrow your results
Selected tags
Tags
GridView
General Discussions
Chart
RichTextBox
Docking
ScheduleView
ChartView
TreeView
Diagram
Map
ComboBox
TreeListView
Window
RibbonView and RibbonWindow
PropertyGrid
DragAndDrop
TabControl
TileView
Carousel
DataForm
PDFViewer
MaskedInput (Numeric, DateTime, Text, Currency)
AutoCompleteBox
DatePicker
Buttons
ListBox
GanttView
PivotGrid
Spreadsheet
Gauges
NumericUpDown
PanelBar
DateTimePicker
DataFilter
Menu
ContextMenu
TimeLine
Calendar
Installer and Visual Studio Extensions
ImageEditor
BusyIndicator
Expander
Slider
TileList
PersistenceFramework
DataPager
Styling
TimeBar
OutlookBar
TransitionControl
FileDialogs
Book
ToolBar
ColorPicker
TimePicker
MultiColumnComboBox
SyntaxEditor
VirtualGrid
Wizard
ExpressionEditor
NavigationView (Hamburger Menu)
WatermarkTextBox
DesktopAlert
BarCode
SpellChecker
DataServiceDataSource
EntityFrameworkDataSource
RadialMenu
ChartView3D
Data Virtualization
BreadCrumb
LayoutControl
ProgressBar
Sparkline
TabbedWindow
ToolTip
CloudUpload
ColorEditor
TreeMap and PivotMap
EntityFrameworkCoreDataSource (.Net Core)
HeatMap
Chat (Conversational UI)
VirtualizingWrapPanel
Calculator
NotifyIcon
TaskBoard
TimeSpanPicker
BulletGraph
Licensing
WebCam
CardView
DataBar
FilePathPicker
PasswordBox
SplashScreen
Callout
Rating
Accessibility
CollectionNavigator
Localization
AutoSuggestBox
Security
VirtualKeyboard
HighlightTextBlock
TouchManager
StepProgressBar
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?