Editing control inside Row Edit Template - c#

Hello, I'm currently trying to load data into one of the RowEditTemplate's controls.
I have a regular ASP.NET DropDownList inside said template. This list should be loaded with data from a List, where MyObject has an Id and a Name.
I've been searching for quite some time now and I don't seem to be able to find a way to get this list from the code behind and load said data.
Any help is welcome, thank you

Ok, as expected coming from lady luck(?), a little while after asking this I found the answer.
In order to get a control from inside the RowEditingTemplate you first need to get access to the Template in question. So, to answer my own question, in order to get my list I did:
DropDownList ddlMyObjects = (DropDownList)WebDataGrid1.Behaviors.EditingCore.Behaviors.RowEditTemplate.TemplateContainer.FindControl("control_MyObject");

Related

Creating an item based on text in a cell of a DataGrid

In a LightSwitch application I have the following three tables:
These tables are part of a bigger, already existing database that cannot be modified for this application.
I also have the following grid on the details page of a Post:
What's shown is the 'Tag' property of PostTag, filtered for just one Post.
So far so good. However, because there can be a lot of different tags, I want to allow users to create a new tag by simply typing in a non-existing tag into the AutoCompleteBox and then, in some way, create a new tag with the entered value.
I have found this blog post by Beth Massi explaining how one could do something like this, but the solution is for just a single AutoCompleteBox. It looks absolutely terrible in a DataGrid, because the button will be shown in all rows and I have not managed to find a way to disable them conditionally (in a DataGrid).
Another acceptable solution would be this one using a message box and LostFocus, but it, too, does not seem to play nice with a DataGrid.
Is there a way to get what I want, or do I have to add some other way of easily creating new Tags?

Getting the SelectedItem as DataContext for a completly independent Uielement

I began to make a program in c# using wpf and the mvvm pattern to learn this program language. I feel sorry that I finally have problems I can't solve using Google. But I try being precise.
At first I present you the GUI, so I can explain my problems more easily.
The xaml file of the MainWindow comes here.
As you see, it's not a serious and important program, I just made it to learn some techniques.
Now comes my main question:
I need the SelectedItem Property of the second ListView(Consumables) in the footer. I thought this wouldn't be a serious problem cause I can just bind it to the selected item using relative path and the name of the listview. This didn't work and caused a null reference error as soon as I added an item to this listview. I double checked the code and I am sure I haven't made something wrong there. So I thought the problem is, that it's kind of a descendant ui element.
My next try was to create a new property in my main view model which is bound to the selected item. You can find this in line 136. But as I found out, this causes me a System.NullReferenceException too if i click on an item. I think it's because this property is read only. I don't know what to do. Isn't there any other possibility to bind the SelectedItem as DataContext for the footer?
My Second Question is about line 27. The TabControl should always select the first Tab automatically. But it makes it only every second time. It's quite funny. If I scroll down the Champion Combo Box, the first tab goes: selected - unselected - selected - ...
My third and last Question is about 72 which is similar to line 50 (The DataContext is the same too) But the ICommand of the ContextMenu of the itemtemplate you see line 50 works, whereas the contextmenu (l. 72) does not call the Icommand. Weird.
It's a fun project, so I can provide you the source code if my information are not enough.
--Sorry, only two hyperlinks allowed--
Please help me. I am just a bit confused by this unsuspected behaviour. I haven't found anything that could help me and I'm sorry if the answers of these questions will be simple :P
Just to emphasize it: The main question is the only one I really need an answer for. The second one could be solved programatically. And to solve the third one, I could just remove this feature.
I'm happy for EVERY HINT!
Haven't gone through the entire question but you should bind selected item to your view model property (two way binding) and then bind another UIElement to this view model property (probably one way binding or check for value equality as to not cause stackoverflow exception)

list view problem with respect to my problem

I have a listview in wpf and i am swapping two items index..
the swapping must be visible to the user.
i tried giving thread delay..
it didnt work
How to do that..
If I was going to do this I would delete the list view and lock it up where you can't use it again. Then code whatever your list view was outputting in C# using whatever you use to query your database(I think LINQ to SQL is the most robust solution right now) and then use a string builder to construct the html. This way you can assign a id to each div and append an incrementing number to the end of the id. Finally you could write your javascript and use the id's. Here is a link that shows how to build a gridview without using a gridview control.
See the first answer to the question in this link: How to show pop up menu from database in gridview on each gridview row items?
I am not sure whether it will work for your problem or not.
I think you need some kind of animation there. If it is web project, you can use jQuery animation to do that.

Getting the bound field name at runtime

If you bind a control in a FormView using two way binding (such as Text='<% #Bind("FieldName") %>'), how do you retrieve the field name "FieldName"? There are several things I want to do with this information; for example, I have a database table that contains a dump of all the field definitions from ERWin and I want to programmatically create some sort of context-sensitive help for each individual field (there are hundreds spread across dozens of forms).
This is pretty much an exact duplicate of a question asked a year ago but the answer didn't make much sense to me. First, the answer seemed to be for a GridView and not a FormView (e.Row.Cells[0] gave it away). Second, what does SortExpression have to do with anything? Third, it mentions an event argument, but for what event? In OnDataBound, EventArgs e is empty.
There does not appear to be any way to get at this information from a FormView, as the column name is not stored at the level you want it.
However, I must admit that I do not understand why you want to retrieve at runtime something that you know at compile time. Why is it not possible to just write the code you need? Even if you want your code to be more generic, you can create a dictionary of control names and their associated bound column names to pass to your class that does whatever it needs to do.
Regarding the answer to your last question - the GridView stores the column name in the SortExpression property, so that it knows what column to sort by when the user resorts the grid. Hence, in a GridView, you can access the column name through the SortExpression.
An easy way of doing this is to programatically assign the name of the data field to the Tooltip property of your Formview controls, then the data field names will be shown to the user as they mouse over these controls. If you want a more specific answer, please specify if this is what you are trying to accomplish.

C# dropdownmenuitem clicked and listview editing

I have 2 questions concerning C#.
1) I have a dropdown menu with several items in them. They are clickable, but when I click one, the older clicked one stays selected. Click another and the 2 original ones stay selected, and so on. I don't want this. What I want is that when I click one of the dropdownitems, that one is that selected one and the others are not.
2) I have a listview items on a winform. I loaded some string elements into it from a file. Now what I want to do is to be able to edit those strings and even add strings, just by clicking on the rows in which the data goes.
I've checked google and MSDN for these problems, but nothing helps, so I turn here.
2) The ListView does not support that type of action. You can roll your own (pain in the #$$), or perhaps a DataGrid would be better suited to your purpose.
EDIT:
This link may help
This one too
For #1 I'm a little confused. If the DropDownStyle isn't set to simple something strange is occuring. It's not much but maybe you could try recreating the control.
For #2 the easiest solution I can think of is to set a TextBox to be equal to the selected text value from your listview. After that write a little function to update the selected index of the listview with the edited text from the listview.
Please comment if you have any more information about #1.

Categories

Resources