This is a migrated thread and some comments may be shown as answers.

How to sync Grid with a Textbox?

9 Answers 159 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andi
Top achievements
Rank 2
Andi asked on 20 Oct 2010, 02:01 PM
Hi there,

I try to syncronisize the Grid with one Textbox. Everytime I click on a other cell, the Textbox should show the value of the cell. Now when I change the value of the cell, the text in the Textbox have to change too. (Like MS-Excel do)
The datasource of the Grid is a DataTable and dependending to this DataTable the Grids Rows and Columns where build by Runtime. The Datatable will get his Data from various Textfiles so it should be different each time its loaded.

I hope someone understand what I want to say and can help me.

9 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 21 Oct 2010, 04:26 PM
Hi Andi,

Please find attached a sample project. When you type in the textbox - the change is immediately applied to the underlying object and the gridview. When you edit a cell in the gridview - the change is immediately applied to the textbox.

Hope this helps.

Kind regards,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andi
Top achievements
Rank 2
answered on 22 Oct 2010, 08:35 AM
Thank you for your sample. The problem with the sample is, the programm knows how much columns are in the grid and how they be named. In my case, I don't know the columns by design-time. So the binding like in your sample will not work for me. The same problem happens when you try to add new columns by Run-Time. The ViewModel doesn't know the new column and the binding will not work.
0
Pavel Pavlov
Telerik team
answered on 22 Oct 2010, 09:47 AM
Hi Andi,

As an alternative I may offer to read the value from the visual element in the cell within a CellEditEnded event handler. This way you may avoid hardcoding the bindings.

I have modified the project to demonstrate this approach. Please find it attached.


Sincerely yours,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andi
Top achievements
Rank 2
answered on 22 Oct 2010, 11:35 AM
I have tried like in your first sample and create 200 properties for the columns.
Every time I try to test the application I get a errormessage which says: "The Sequenz has no Elements" and then the application shut down.
I can't find the error :(
I can't attache my projektfiles to this post. so I can't shw you, what I've done.
0
Pavel Pavlov
Telerik team
answered on 22 Oct 2010, 12:24 PM
Hello Andi,

Without having the project to have a look,  I can not be of much help here. Maybe you can paste some stack trace at least ?

Greetings,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andi
Top achievements
Rank 2
answered on 22 Oct 2010, 12:30 PM
this is the stacktrace
bei System.Linq.Enumerable.Last[TSource](IEnumerable`1 source)
bei Telerik.Windows.Data.PropertyPathDescriptor..ctor(String propetyPath, IList`1 childDescriptors) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Data\ItemProperties\PropertyPathDescriptor.cs:Zeile 36.
bei Telerik.Windows.Data.PropertyPathDescriptor..ctor(String propertyPath, Type componentType) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Data\ItemProperties\PropertyPathDescriptor.cs:Zeile 31.
bei Telerik.Windows.Data.ItemPropertyPathInfo..ctor(String propertyPath, Type elementType) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Data\ItemProperties\ItemPropertyPathInfo.cs:Zeile 8.
bei Telerik.Windows.Data.ItemPropertyInfoHelper.GetItemProperty(String propertyPath, Type elementType) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Data\ItemProperties\ItemPropertyInfoHelper.cs:Zeile 24.
bei Telerik.Windows.Controls.GridViewBoundColumnBase.TryInitializeItemPropertyInfo() in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Controls\GridView\GridView\GridView\Columns\GridViewBoundColumnBase.cs:Zeile 981.
bei Telerik.Windows.Controls.GridViewBoundColumnBase.InitializeItemPropertyInfo() in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Controls\GridView\GridView\GridView\Columns\GridViewBoundColumnBase.cs:Zeile 964.
bei Telerik.Windows.Controls.GridView.GridViewDataControl.InitializeNotGeneratedColumnsItemPropertyInfos() in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:Zeile 2927.
bei Telerik.Windows.Controls.GridView.GridViewDataControl.RefreshColumns() in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:Zeile 3816.
bei Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsPropertyChanged(Object sender, PropertyChangedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:Zeile 3807.
bei Telerik.Windows.Data.DataItemCollection.RaisePropertyChanged(PropertyChangedEventArgs args) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Data\Collections\DataItemCollection.cs:Zeile 1661.
bei Telerik.Windows.Data.DataItemCollection.set_CollectionView(QueryableCollectionView value) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Data\Collections\DataItemCollection.cs:Zeile 118.
bei Telerik.Windows.Data.DataItemCollection.CreateCollectionView(IEnumerable source) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Data\Collections\DataItemCollection.cs:Zeile 760.
bei Telerik.Windows.Data.DataItemCollection.SetItemsSource(IEnumerable source) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Data\Collections\DataItemCollection.cs:Zeile 665.
bei Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass48.<Bind>b__47() in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:Zeile 3759.
bei Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Core\Controls\CursorManager.cs:Zeile 16.
bei Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue) in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:Zeile 3725.
bei Telerik.Windows.Controls.GridView.GridViewDataControl.OnApplyTemplate() in c:\Builds\WPF_Scrum\Release_WPF_2010_Q2_SP2\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.cs:Zeile 3020.
bei System.Windows.FrameworkElement.ApplyTemplate()
bei System.Windows.FrameworkElement.MeasureCore(Size availableSize)
bei System.Windows.UIElement.Measure(Size availableSize)
bei System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
bei System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
bei System.Windows.Controls.Grid.MeasureOverride(Size constraint)
bei System.Windows.FrameworkElement.MeasureCore(Size availableSize)
bei System.Windows.UIElement.Measure(Size availableSize)
bei MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
bei System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
bei System.Windows.FrameworkElement.MeasureCore(Size availableSize)
bei System.Windows.UIElement.Measure(Size availableSize)
bei System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
bei System.Windows.FrameworkElement.MeasureCore(Size availableSize)
bei System.Windows.UIElement.Measure(Size availableSize)
bei System.Windows.Controls.Border.MeasureOverride(Size constraint)
bei System.Windows.FrameworkElement.MeasureCore(Size availableSize)
bei System.Windows.UIElement.Measure(Size availableSize)
bei System.Windows.Window.MeasureOverrideHelper(Size constraint)
bei System.Windows.Window.MeasureOverride(Size availableSize)
bei System.Windows.FrameworkElement.MeasureCore(Size availableSize)
bei System.Windows.UIElement.Measure(Size availableSize)
bei System.Windows.Interop.HwndSource.SetLayoutSize()
bei System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
bei System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
bei System.Windows.Window.SetRootVisual()
bei System.Windows.Window.SetRootVisualAndUpdateSTC()
bei System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
bei System.Windows.Window.CreateSourceWindow(Boolean duringShow)
bei System.Windows.Window.CreateSourceWindowDuringShow()
bei System.Windows.Window.SafeCreateWindowDuringShow()
bei System.Windows.Window.ShowHelper(Object booleanBox)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
bei System.Windows.Threading.DispatcherOperation.InvokeImpl()
bei System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
bei System.Threading.ExecutionContext.runTryCode(Object userData)
bei System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Windows.Threading.DispatcherOperation.Invoke()
bei System.Windows.Threading.Dispatcher.ProcessQueue()
bei System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
bei MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
bei System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
bei System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
bei System.Windows.Threading.Dispatcher.Run()
bei System.Windows.Application.RunDispatcher(Object ignore)
bei System.Windows.Application.RunInternal(Window window)
bei System.Windows.Application.Run(Window window)
bei System.Windows.Application.Run()
bei GridViewTest.App.Main() in G:\Projekte\GridViewTest\GridViewTest\obj\x86\Debug\App.g.cs:Zeile 0.
bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()
0
Andi
Top achievements
Rank 2
answered on 22 Oct 2010, 02:24 PM
ok, I have found the failure.
For the first column, which has no Header, I have to define a property.

Now I have a small problem with this first column. I want to prevent this first column from changes by the User.
I have tried this:
grid.Columns[0].Focusable = false;
grid.Columns[0].IsEnabled = false;

but it doesn't have any effect.
0
Accepted
Pavel Pavlov
Telerik team
answered on 26 Oct 2010, 12:19 PM
Hi Andi,

Please try setting the IsReadOnly property of the column to false . this should do the trick .

Best wishes,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andi
Top achievements
Rank 2
answered on 26 Oct 2010, 02:31 PM
That's it.
Thank you!
Tags
GridView
Asked by
Andi
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Andi
Top achievements
Rank 2
Pavel Pavlov
Telerik team
Share this question
or