Hello,
I am using
this example to get a row number in my gridview:
http://www.telerik.com/forums/how-to-display-the-row-number
I altered the code from the example and added a dependency property to it, which I am binding to a property of an item from the itemssource collection of the gridview.
public class RowNumberPresenter : TextBlock{ private GridViewDataControl _parentControl; public GridViewDataControl ParentControl { get { return this._parentControl; } private set { if (this._parentControl != null) this._parentControl.Items.CollectionChanged -= new NotifyCollectionChangedEventHandler(Items_CollectionChanged); this._parentControl = value; if (this._parentControl != null) this._parentControl.Items.CollectionChanged += new NotifyCollectionChangedEventHandler(Items_CollectionChanged); } } public RowNumberPresenter(GridViewDataControl parentControl, object dataItem) : base() { ParentControl = parentControl; SetText(dataItem); } private void Items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { SetText(this.DataContext); } private void SetText(object dataItem) { if (this.ParentControl.IsGrouping) { var group = this.ParentControl.FindGroupByItem(dataItem); if (group != null) { var items = group.Items as ReadOnlyObservableCollection<object>; if (items != null) this.Text = (items.IndexOf(dataItem) + 1).ToString(); } } if (string.IsNullOrWhiteSpace(this.Text)) this.Text = (this.ParentControl.Items.IndexOf(dataItem) + 1).ToString(); }}
public class RowNumberGridViewColum : GridViewColumn{ private RowNumberPresenter _rowNumberPresenter; public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem) { _rowNumberPresenter = cell.Content as RowNumberPresenter; if (_rowNumberPresenter == null) _rowNumberPresenter = new RowNumberPresenter(this.DataControl, dataItem); CurrentIndex = Int32.Parse(_rowNumberPresenter.Text); return _rowNumberPresenter; } public int CurrentIndex { get { return (int)GetValue(CurrentIndexProperty); } set { SetValue(CurrentIndexProperty, value); } } public static readonly DependencyProperty CurrentIndexProperty = DependencyProperty.Register("CurrentIndex", typeof(int), typeof(RowNumberGridViewColum));}
<cControlsTelerik:RowNumberGridViewColum IsReadOnly="True" TabStopMode="Skip" TextAlignment="Center" CurrentIndex="{Binding Path=OrderRowData.SequenceNumber}"> <cControlsTelerik:RowNumberGridViewColum.Header> <TextBlock Text="No.:"/> </cControlsTelerik:RowNumberGridViewColum.Header></cControlsTelerik:RowNumberGridViewColum>
The binding
is not working and I am I am a little stuck how to bind the rownumber of the
row to my dataobject (a OrderRow object).
I receive
the error that OrderRowData is not a property of OrderViewModel, OrderViewModel is my VM for the whole view?
The
Itemssource of the gridview is set to a Rows property on my OrderViewModel,
this Rows collection contains all the OrderRowData instances visible in the
grid.
Any help would be appreciated.
Regards,
Marcel

Hello,
I am looking a generic solution to import excel to radgridview.
I want to do this at my control(not viewmodel or codebehind,I custimized radgridview)
Is there a way to do that

Hello!
I'm using the "RadRichTextBox" in my project. I'm facing a problem when the control is disabled (i.e. IsEnabled = False). In disabled state the controls turns Grey and the text visibility is very low. I cannot use read-only or any other property as they are being used for other purpose. I need to change the template for Disabled control, so as to not make it Grey but make the Disable mask transparent instead. Need help for the same.
Thanks
Tushar

I am replacing a TreeView control with a RadTreeView control however I have run in to a issue. I want the user to be able to click on the body of the TreeView (instead of a node) and have it deselect the item in the tree view.
With the original TreeView I would do
<TreeView Grid.Row="0" MouseDown="TreeView_OnMouseDown"> <TreeViewItem Header="Item 1"/> <TreeViewItem Header="Item 2"/></TreeView>Then in the code behind I would have
private void TreeView_OnMouseDown(object sender, MouseButtonEventArgs e){ var treeView = (TreeView)sender; var items = treeView.Items.Cast<TreeViewItem>(); foreach (var treeViewItem in items) { treeViewItem.IsSelected = false; } }
And this would work correctly. However if I do
<telerik:RadTreeView Grid.Row="1" MouseDown="RadTreeView_OnMouseDown"> <telerik:RadTreeViewItem Header="Item 3"/> <telerik:RadTreeViewItem Header="Item 4"/></telerik:RadTreeView>and
private void RadTreeView_OnMouseDown(object sender, MouseButtonEventArgs e){ var treeView = (RadTreeView)sender; treeView.SelectedItem = null; MessageBox.Show("RadTreeView_OnMouseDown fired!");}the OnMouseDown event never fires.
Looking at the OnMouseDown event with Snoop it appears to be getting marked as handled by the ScrollViewer inside the RadListView.
What is the correct way to deselect the node when clicking on the body of the tree view? Attached is a simple example program that shows the two controls side by side with their different behaviors.
Hi,
At the moment I'm facing an issue, I have a RadGridView which can show different tables with different definitions(not at the same time)
So AutoGenerateColumns is set to True.
now it can happen that some columns have an FK to another table.
Before I replaced those columns in the DataLoaded event but because of performance reasons I would like to do those replaces in the CurrentCellChanged event.
The problem when I do this is that the new GridViewComboBoxColumn misses the link to the actual datasource, and while reading the value for saving in the database, the value is DBNULL.
the gridview in de Xaml looks like this
<DataTemplate x:Key="AdminViewMainSectorTemplate"> <Grid Margin="10"> <Grid> <telerik:RadBusyIndicator x:Name="BusyIndicator" Grid.Row="2" > <telerik:RadGridView x:Name="gridViewAdminData" ItemsSource="{Binding DataRecords, Mode=TwoWay}" RowEditEnded="EditRecord" Deleted="deleteRecord" AddingNewDataItem="AddingNewDataItem" MinColumnWidth="100" ColumnWidth="*" NewRowPosition="Top" AutoGeneratingColumn="AutoGeneratingColumn" DataLoading="LoadData" DataLoaded="DataLoaded" CurrentCellChanged="CurrentCellChanged" SelectionUnit="Cell" > <!--DataLoading="LoadData" DataLoaded="DataLoaded"--> <telerik:EventToCommandBehavior.EventBindings> <telerik:EventBinding Command="{Binding HandleAddingNewRecordToDevicesGridCommand}" EventName="AddingNewDataItem" PassEventArgsToCommand="True"/> </telerik:EventToCommandBehavior.EventBindings> </telerik:RadGridView> </telerik:RadBusyIndicator> </Grid> </Grid> </DataTemplate>and my code behind looks like this:
private void CurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs e) { RadGridView rgv = (RadGridView)sender; GridViewCell cell = rgv.CurrentCell; if (cell != null && typeof(GridViewDataColumn) == cell.Column.GetType()) { Models.MyEntities db = new Models.MyEntities(); string tableName = Helpers.GlobalParameters.currenTableName; if (tableName =="batches") { string fieldname = cell.Column.UniqueName; if (fieldname == "ProductieOrderId") { int index = cell.Column.DisplayIndex; GridViewComboBoxColumn cbb = new GridViewComboBoxColumn(); cbb.DataMemberBinding = new System.Windows.Data.Binding(fieldname); //cbb.DataMemberBinding = cell.DataColumn.DataMemberBinding; cbb.ItemsSource = db.productieorder.ToList(); cbb.SelectedValueMemberPath = fieldname; cbb.DisplayMemberPath = "Id"; //cbb.Name = fieldname; cbb.UniqueName = fieldname; cbb.DisplayIndex = index; rgv.Columns.Remove(cell.Column); //rgv.Columns.Remove(cell.DataColumn); rgv.Columns.Add(cbb); } } else if (tableName =="artikel")cbb.SelectedValueMemberPath = "Id";what I would say is logical, the shown value in the combobox stays empty.
does anyone know where to look to fix this issue?
Hi,
I am using a DataTemplateSelector and DataTemplates to show and interact with Custom Appointments in the schedule.
The Custom Appointment has a field called BindingItem added which holds a reference to my data.I then have checkboxes and drop down boxes that bind to fields within the BindingItem.
Everything works great until I refresh the entire appointments collection.
It seems like DataTemplates are being reused (by the container?) and any interaction seems to be with the old BindingItem not the new one, even though the appointment collection is brand new and each appointment has a new BindingItem set.
I can get this resolved in 2 ways, the first is to scroll the offending appointments off the screen and back again which must be forcing some kind of container refresh. Not very useful for end users.
The second is to use the following code to force a container refresh, note that AddIdleAction adds the code onto the dispatcher at application idle priority:
private void RefreshAppointmentBindingItem(CustomAppointment appt)
{
if (appt != null)
{
object item = appt.BindingItem;
AddIdleAction(() =>
{
appt.BindingItem = null;
});
AddIdleAction(() =>
{
appt.BindingItem = item;
});
}
}
Both ways are messy, do you have any better suggestions?
Thanks
Anthony