I have a CheckedComboBoxEdit that's bound to a TableAdapter that populates it with a list of items.
I have a separate query that returns a dataset that lists the items that need to be checked.
I need to iterate through the CheckedComboBoxEdit items to check them as needed.
How can I make the CheckedComboBoxEdit reflect the data from the query which returns a list of items that need to be checked?
I'm using C# in Visual Studio 2010 with DevExpress 10.2.9.
Any help on this would be greatly appreciated, and any other solutions to this issue would be great too.
Items state of the CheckedComboBoxEdit tied to its EditValue. You can check items by setting an appropriate editor value: a list of values (each item has the value and display text) delimited with a separator sign. The separator sign is specified via the RepositoryItemCheckedComboBox.SeparatorChar property.
Here is how to
checkedComboBoxEdit1.Properties.SeparatorChar = ';';
// Set the edit value, assuming you have items named "one",and "two"
checkedComboBoxEdit1.SetEditValue("one; two");
Here is the complete example
Short code snippet.
string str = "first;second";
string[] array = str.Split(';');
char separator = checkedComboBoxEdit1.Properties.SeparatorChar;
string result = string.Empty;
foreach (var element in array){
result += element + separator;
}
checkedComboBoxEdit1.SetEditValue(result);
Related
In c# how would I best handle this scenario, a form contains a large number of checkboxes 100+ which map to columns/fields in the data store, and the user can select any of them. Depending on those they choose when they submit the form I will generate a csv output of the data but only showing the fields(columns) they have requested.
list myData = getAllTheData
var fieldstheychose = "name, mileage, address"
foreach (var item in mydata)
{
var somedata = new StringBuilder();
// make decision to include field or not
somedata.Append(item.name.formatvalue() + ",");
// make decision to include field or not
somedata.Append(item.mileage.GetCSVEncodedValue() + ",");
// make decision to include field or not
somedata.Append(item.address.ToDisplayString() + ",");
// make decision on 100+ fields that might be in the fieldstheychose list depending on their choices
}
return somedata;
I need to at runtime decide which fields will be appended above but I wanted to avoid 100+ if blocks to decide weather to append the data.
I did look at dynamic objects and expando objects but I'm not sure it helps in this scenario.
Any views appreciated.
List<ListItem> selected = new List<ListItem>();
foreach (ListItem item in YourCheckBoxListID)
if (item.Selected)
selected.Add(item);
This will store the ListItems that have been checked assuming you are using a CheckBoxList. From there you can iterate through your selected list and convert the entries into proper csv format.
Give the name of the checkboxes same to what you have in the list mydata. Loop through the list and find your check-boxes using the findControl() function to get the checkbox checked Boolean value. Add it to the list.
I'm having trouble matching textboxes using linq.
I have to populate a textbox with a collection that I converted from an array.
The conversion looks like this.
List<string> animalList = new List<string>(animals);
The list contains items such as "Dog", "Cat", "Snake", "Rat", "Mouse", "Duck"
I can populate the first textbox (there are 3 textboxes, one for the collection, one for a word to be input, and one to display whether or not the input word matches the collection).
I don't know much about Linq. Please help point me in the right direction. I've looked all over online, and I can't find an example for something that should be as simple as matching 2 textboxes using Linq.
Should be as simple as textbox1.Text == textbox2.Text
I'm not sure Linq is the way you want to go here. List<T> has a contains() method that should do what you want. Where is the Linq requirement coming from?
Also, I think you mean a Listbox for the collection (as they're designed to hold multiple items), a textbox for entering new values and then a textbox (or label) to display the result after you test the entered value against the contents of the collection, right?
In your event handler you'll want to use a statement like this:
animalList.SingleOrDefault(a => a == textbox1.Text);
That assumes that the textbox where the name of your new animal is typed into is named textbox1.
I'm a student learning C#, with previous experiences with VB. I'm trying to use a list view to display three pieces of information in three separate columns. The Item is a decimal (Object = 3.50m), and the subItems are the quantity and a price. I have managed to get the first two columns showing the data with:-
var item = lsvstarter.Items.Add(cmbStarter.Text);
item.SubItems.Add(cmbStrQuantity.Text);
The third column should show the worth of the item multiplied by the quantity, so it would be
1st Column "3.50"
2nd Column "3"
3rd Column (3.50 * 3) "10.5"
But the method I used for the first subitem will not work for the variable that should be displayed by the third column. This being
item.SubItems.Add(Startertotal);
The ListView includes 3 columns. I had this program working on VB since the scenario is the same but using translators didn't work successfully. All of the objects in the Design view are the same.
Also the calculation for the "Startertotal" variable has already been calculated in a loop beforehand. Does anyone know what I'm doing wrong and the fix?
MSDN: SubItems.Add takes either a string or a SubItem as its first parameter.
So you need to change the numeric value to a string in one way or another:
item.SubItems.Add(Startertotal + " ");
item.SubItems.Add(Startertotal + "");
item.SubItems.Add(Startertotal.ToString());
item.SubItems.Add(Startertotal.ToString("###0,00"));
item.SubItems.Add(String.Format("Sum: {0} ", Startertotal));
or whatever formatting you want..
I am trying to get the value at selected indicies in a ListBox using ASP.net C#
MakeListBox.SelectionMode = ListSelectionMode.Multiple;
int [] indicies= MakeListBox.GetSelectedIndices();
I am going to dynamically building a select statement for a database query to an SQLDataSource. What I had hoped to be able to do was get all the selected indexes go through a loop to for the array that it returns and add each value at the specified index to a string.
I have looked through this and this but can't find what is needed to do what I have talked about.
Basically I am looking for the opposite of the IndexOf command. Or a technique that would have the same results.
It's not clearly obvious when looking at the ListBox control properties, but this is the best way to do it:
foreach(ListItem li in MakeListBox.Items)
{
if(li.Selected)
{
// Append to your string list
}
}
Consider the ListView item Having two columns with more than 35,000 rows inserted already. Now the user selects the any 30,000 rows from the ListView. I want all the Selected Items data let's Say (Item,Subitems)
Here is my code.
ListView Name : lstViewData
List<string> l_lstData = new List<String>();
for(int l_nItem =0;l_nItem<lstViewData.SelectedItems.Count;l_nItem++)
{
l_lstData.Add(lstViewData.SelectedItems[l_nItem].Text+
lstViewData.SelectedItems[l_nItem].SubItems[1].Text);
}
It Will take more than Half an hour in my PC(Configuration - IntelCore2Duo #2.40GHZ).Since the no. of selected items is morethan 30,000 in ListView
Kindly tell me the solution If any one knows?
You are using the + operator:
l_lstData.Add(lstViewData.SelectedItems[l_nItem].Text+lstViewData.SelectedItems[l_nItem].SubItems[1].Text);
you should NEVER in a case where there is a lot of operations use the + operator on strings, as they are immutable. You should use a StringBuilder.
l_lstData.Add(sbuilder.Append(lstViewData.Seleteditems[l_nItem].Text).Append(lstViewData.SelectedItems[l_nItem].SubItems[1].Text).ToString());
sbuilder.Remove(0, sbuilder.Length);
where sbuilder is an instance of StringBuilder