DevExpress XtraGrid problem setting value - c#

I wonder if someone can help.
I have a LookupEdit within a Devexpress Xtragrid which is populated from a list of filenames, as well as an empty option, and a "new" option.
If the user selects the "new" option, it goes off to an upload form (which is fine), uploads to the new directory and returns to the form.
The problem is that I want to set the form to the new value, but I can't get it to work.
In the EditValueChanging for the lookupedit, I repopulate the lookup and then use GetKeyValueByDisplayText, but the value returned is null for some reason. Yet I've defined an object for uploadfile with a property of Filename and set both the displaymember and valuemember to Filename.
If anyone can help, as I've exhausted my options.

The problem might appear because the new list hasn't been loaded by the editor yet. Please try to call the
(gridView.ActiveEditor as LookupEdit).Properties.ForceInitialize();
method. Does this work for you?

Related

Objectlistview TextMatchFilter Filter and not Highlight

i try to use TextMatchFilter for my ObjectListView.
I do not know why, but instead of Filterung (what i want), the function only highlights the words.
So i want the whole ObjectListView to show only the Rows where the Filter is true.
This is my Code:
this.fastoLV_Clean.ModelFilter = TextMatchFilter.Contains(this.fastoLV_Clean, "Test");
fastoLV_Clean.Refresh();
Does anyone know, what i have to do to really Show only the rows and not to only highlight the ones in which it was found?
Regards and thank you,
You need to set the UseFiltering property of your ObjectListView to be True
If you don't set this, then it will just highlight your text. When set, then it will filter and only show the relevant rows.
BTW: You don't need to call fastoLV_Clean.Refresh()
A Refresh is normally only needed in some cases, such as when you change the columns programmatically. It is not needed for simple things such as this when you model data is updated. (I noticed this also in your other post, but forgot to mention it!)

Adding event in code to Drop-down list box in InfoPath

I'm trying to add the OnChange or Changed or IndexChanged event to the "Drop-down list box" control in InfoPath using VS Tools for applications.
If found the following code how this is done with buttons:
((ButtonEvent)EventManager.ControlEvents["ButtonName"]).Clicked += new ClickedEventHandler(FormCode_Clicked);
I would think this is also possible with other controls, but I can't seem to find the cast object to be able to add the event to my drop-down list.
((?)EventManager.ControlEvents["Project_x0020_Number"]).SelectedIndexChanged += new EventHandler(FormCode_SelectedIndexChanged);
I tried the object ComboBox, but then their was an error that this object could not be casted to the type ComboBox.
I hope someone can give me some advice. All I want to do is basically run a Query that filters my data depending on the selected value in my "Project Number" box.
maybe also good to mention: I'm changing the form that will go in a word document (used as template in SharePoint). I don't really think this matters, but thought I mention it any way.
Thanks in advance
Oxillery
You can approach this problem without writing code. I dont have Infopath in this machine to give you a sample. But I think you can solve this with the method described here in point 26:
http://www.bizsupportonline.net/infopath2003/avg-function-infopath.htm
Instead of calculating the average as in the example above you will set some parameters in your datasource and perform a refresh based on the value set in your dropdown.

C# How to set default value of a string collection in Design

In WinForm, I have a combobox with DropDownStyle set to DropDownList (so can't enter a Text). In the properties window, there is the Items property which is a string collection. I enter all my values.
But now, I would like to set one of these value by default (instead to have the empty entry at run-time). I know how to do this via coding, but I am pretty sure (damn memory) that it was possible to set one of the value in the string collection as default by adding a special symbole in front of the line.
Anybody know that symbole? Or my memory is playing me trick and it is not possible to do it via the designer?
Doesn't look like it can be done when using a DropDownList. From here it is suggested that you can set the text property to the default value you want, but this will only works in a DropDown rather than DropDownList style.
I'm sorry but that is not possible within the Designer only, since the Text property is used for this feature and that property is ignored/cleared when the using a DropDownList.
If you don't mind having your data values outside of the Designer, you could probably use DataBinding to accomplish this since the DisplayMember and ValueMember properties of ComboBox can be used in the Designer and would set the display value. I don't normally use DataBinding so unfortunately I cannot provide code examples - perhaps another user can chime in?

C# - Using a ListBox to populate other fields

I'm trying to use the selected value of a ListBox control to populate a TextBox with its Text property, and a HiddenField with its value property. It sounds simple enough, and I went with this:
currentGroupTextBox.Text = currentSiteGroupList.SelectedItem.Text;
currentGroupHiddenField.Value = currentSiteGroupList.SelectedValue;
But upon execution, ASP.NET returns an error:
Object reference not set to an instance of an object.
And highlights the first line. currentGroupTextBox and currentGroupHiddenField are two controls which are enabled in the ASPX file so I'm not too sure why ASP.NET would complain about instancing them.
I'm going to try and pull together answers to all of your questions, including those in the comments.
Even if SelectionMode="Single", the listbox starts out without anything being selected, unless you specify which item should be selected in your code.
To test if the SelectedItem is null, use the following code:
if (currentGroupSiteList.SelectedItem != null) {
currentGroupTextBox.Text = currentSiteGroupList.SelectedItem.Text;
currentGroupHiddenField.Value = currentSiteGroupList.SelectedValue;
}
What does your Page_Load code that loads the listbox look like? Is it wrapped with a if (!Page.IsPostBack) check? If not, pressing the button and initiating a postback will reload the listbox, thus losing the SelectedItem that the user selected.
I'd be willing to bet that your first line is choking on referencing currentSiteGroupList.SelectedItem, as that seems the most likely candidate for being a null reference. Make sure your code is executing in the right place within the ASP.NET page lifecycle, such that the SelectedItem is set properly behind the scenes.
SelectedItem from your currentSiteGroupList.SelectedItem is likely to be null (what represents no selection). You need to test it before assigning it to currentGroupTextBox.Text
Is it currentGroupTextBox or currentGroupTextBox that is null?
In debug if stop on that line..is it one or both that are not existing?
A common issue I find is that controls are placed on an asp formview or similar and so the reference to that control is not actually its id/name, but more likely you need to do;
TextBox myTextBoxReference = (TextBox) formName.FindControl("currentGroupTextBox")
string theValue = myTextBoxReference.Text
Another often issue is the page life cycle. So if your object is not on a form but maybe you are referencing it before it exists in the postback.
hth

FindControl() returning copy?

I'm trying to use FindControl() to SET the values of some DropDownLists on a page.
for some reason, it appears that FindControl() is returning a copy of the control object as opposed to a reference, I was under the impression that this would not be the case due to the lack of a copy constructor for Controls?
<EDIT>
Ok, it apparears that it is not in fact returning a copy, it's simply not letting me set the visibilty of a control, the other properties I'm setting work fine.
Does anyone have any insight as to why this might be the case?
I've tried setting it in quick-watch mode then looking at the value straight away, and that isn't actually changing the value either!
</EDIT>
<EDIT> (two)
Ok, I'm doing this in Page_Load, and it's not in a gridview (I like how you guys assumed that one cus I was using FindControl()).
I'm doing this as there is a set of operations I have to perform on a dynamic number of similarly named lists, and it's MUCH better to do it in a loop than to hard code it.
</EDIT>
Can anyone help?
Cheers, Ed
Edit:
Whoa, wait... are you setting the Visible property to true rather than false?
In your comment, you mention it changes back instantly. The Visible property will evaluate to false if it's parent is set to be invisible, no matter how often you tell it the value should be true.
Where are you calling FindControl() and setting the Visible property?
For info, FindControl() gets a reference to a control in the current naming container, based on a string id and does not copy the control. In order to work with the control, you should cast it to the type of control that you expect -
DropDownList ddl = (DropDownList)e.Row.FindControl("myDropDownList");
this example would allow you to work with a DropDownList control in the OnRowDataBound event of a GridView.

Categories