remove items from combobox - combobox

i filled the combobox with the following:
for(var x in z)
{
var tempItem = new qx.ui.form.ListItem(""+arr[x]);
tempItem.model=arr[x];
cbo.add(tempItem);
}
Unfortunately, i didn't find anything, to remove all items from the combobox.
With the following code is this not possible
cbo.getList().removeAll();
or
var childLength = cbo.getList().getChildrenLength();
for (var i = 0; i < childLength; i ++)
{
var childToRemove = cbo.getList().getFirstChild();
cbo.getList().remove(childToRemove);
childToRemove.dispose();
childToRemove = null;
}
Thank you
Mani

Your snippet does not work because the cbo does not have any getList()-method. Performing removeAll() directly on the comboBox should do the trick.
Cheers
Andreas

Related

Putting an object into an array in as3

So I'm trying to create a row of ten buttons using a for loop that create a new button every time it runs, changing the x value each time. However ever each time a button is created i want it to be put into a specific array so i can refer to a specific button later on. However I'm not sure how to put objects into arrays. Is it possible to do this? This is the code I have so far:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class backgound extends MovieClip {
var btnx = 30;
var btny= 20;
var row1:Array = [];
public function backgound() {
// constructor code
var continueBtn:Button;
for(var i=0; i < 10; i++)
{
continueBtn = new Button();
continueBtn.x = btnx;
continueBtn.y = 100;
continueBtn.width = 30;
continueBtn.height = 20;
continueBtn.border = true;
continueBtn.visible = true;
continueBtn.label = "Continue";
addChild(continueBtn);
btnx += 30;
}
}
}
}
in your loop:
myArray.push(continueBtn);
or in your loop:
continueBtn =myArray[i]= new Button();
or many other ways.
now you can access your buttons:
myArray[3]// gets the 4th item in your array
I just wonder, is this ALL you want?
I  H☺P E  this helps !

Loading data from xls-file, comparing it with data from db and displaying result in a datagrid

I have a datatable with data from file - it will be an ItemSource of my datagrid. And i am getting a datatable with the same schema from the database. I want to compare this two datatables and if there are some rows in the file that exist in the DB i need to check that the values of columns are equal. If not - I need to change the Background of the cell to red colour. May be it will be more clear from my code below:
dgrSimcards.ItemsSource = excelCards.Table.DefaultView;
var dbsource = new Tables.ExcelCards();
DBConnection.FillData(dbsource.Table);
if (!dbsource.HasRows) return;
foreach(DataRow impRow in import.Table.Rows)
{
var row = dbsource.Table.AsEnumerable().FirstOrDefault(p =>string.Compare( p[dbsource.card_numberColumn.ColumnName].ToString() ,impRow[dbsource.card_numberColumn.ColumnName].ToString())==0);
if (row != null)
{
if (string.Compare(row[import.comentsColumn].ToString(), impRow[import.comentsColumn].ToString()) != 0)
{
//here is merging problem - i need to change background colour
}
}
}
I found that it's possible to change cell's background via BindingProperty. But I don't know how to do that in my case. Yes, I'm really want to compare data on client-side. Any advices is appreciated.
I used an additional class:
public CardDoubleRow(DataRow mainRow, DataRow otherRow)
{
_mainRow = mainRow;
_otherRow = otherRow;
}
public object card_number
{
get { return _mainRow[ExcelSimCards.CardNumber]; }
}
public bool NumberEquals
{
get
{
return _otherRow != null
&& card_number.ToString().Equals(_otherRow[ExcelSimCards.CardNumber]
.ToString(),
StringComparison.OrdinalIgnoreCase);
}
}
foreach(DataRow impRow in import.Table.Rows)
{
var row = dbsource.Table.AsEnumerable().FirstOrDefault(p =>string.Compare( p[dbsource.card_numberColumn.ColumnName].ToString() ,impRow[dbsource.card_numberColumn.ColumnName].ToString())==0);
result.Add(new CardDoubleRow(impRow, row));
}
datagridcontrol.ItemsSource=result;
Then for each column i bound a special cellstyle with trigger like:
DataTrigger tg = new DataTrigger()
{
Binding = new Binding("NumberEquals"),
Value = false
};

How can I use WPF bindings while printing?

It seems not all bindings are to evaluated when printing. For example, in the code below, only the first button has content = "100", other buttons have content = "0".
var doc = new XpsDocument("test.xps",FileAccess.Write);
var writer = XpsDocument.CreateXpsDocumentWriter(doc);
var collator = writer.CreateVisualsCollator();
collator.BeginBatchWrite();
for (int i = 0; i < 3; i++)
{
var button = new Button();
button.SetBinding(ContentControl.ContentProperty,
new Binding
{
RelativeSource = new RelativeSource(RelativeSourceMode.Self),
Path = new PropertyPath("ActualWidth")
});
button.Measure(new Size(100, 100));
button.Arrange(new Rect(0, 0, 100, 100));
button.Width = 100;
button.Height = 100;
collator.Write(button);
}
collator.EndBatchWrite();
doc.Close();
Is there a workaround?
For example, is there a way to force the binding to evaluate?
Have you tried making sure the dispatcher is idle before the call to collator.EndBatchWrite().
Something like:
Dispatcher.CurrentDispatcher.Invoke(
new Action( delegate { } ), DispatcherPriority.ApplicationIdle, null );

wpf toolkit datagrid performance

i am porting my application from windows forms to WPF. I have found that datagrid is available only through the WPF Toolkit. However i have some issues with performance. This could be because something that performed alright in windows forms does not in wpf since it has to be implemented differently. Anyhow, i am doing something like this:
// XAML
<toolkit:DataGrid x:Name="dataGrid" ItemsSource="{Binding Path=.}"/>
// C#
DataTable dataTable = new DataTable();
MyViewModel viewModel = new MyViewModel();
this.dataGrid.AutoGenerateColumns = false;
this.dataGrid.CanUserAddRows = false;
this.dataGrid.CanUserDeleteRows = false;
this.dataGrid.CanUserReorderColumns = true;
this.dataGrid.CanUserResizeColumns = true;
this.dataGrid.CanUserResizeRows = false;
this.dataGrid.CanUserSortColumns = true;
this.dataGrid.IsReadOnly = true;
this.dataGrid.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
this.dataGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
this.dataGrid.ColumnHeaderHeight = 18;
this.dataGrid.RowHeight = 18;
this.dataGrid.DataContext = vm.dataGrid;
List<string> s = new List<string>();
for (int i = 0; i < 80; ++i)
{
s.Add("col" + i);
}
for (int i = 0; i < s.Count; ++i)
{
dataTable.Columns.Add(new DataColumn(s[i], typeof(string)));
Binding items = new Binding();
PropertyPath path = new PropertyPath(dataTable.Columns[i].ColumnName);
items.Path = path;
DataGridColumn dc = new DataGridTextColumn()
{
Header = dataTable.Columns[i].ColumnName,
Width=70,
Binding = items
};
this.dataGrid.Columns.Add(dc);
}
viewModel.dataGrid = dataTable;
this.dataGrid.DataContext = viewModel.dataGrid;
for (int i = 0; i < 1000; ++i)
{
var row = dataTable.NewRow();
for (int j = 0; j < s.Count; ++j)
{
row[s[j]] = "text" + s[j] + j;
}
dataTable.Rows.Add(row);
}
The above is a sample of simply generating same number of columns by binding each header.
When this loads, i get all the elements displayed correctly, but scrolling is really slow. I know that someone might say that i am rendering 80 columns and 1000 elements, but i had more than 10000 displayed in my windows forms application and had no issues with it.
The only difference with Windows Forms is that instead of using Binding i was setting the dataGridView's dataSource to the DataTable each time i was updating it.
Any ideas? What am i doing wrong?
Try setting EnableRowVirtualization=True

How can I get an ListView item from the (X,Y) position?

I am dropping something in a ListView in WPF. I need to know the item in the (X,Y) position I am dropping. How can I do this?
The WPF ListView doesn't have GetItemAt. I return to my original problem.
Done! Thanks to this article
http://www.codeproject.com/KB/WPF/WPF_Drag_And_Drop_Sample.aspx
private int GetCurrentIndex(GetPositionDelegate getPosition)
{
int index = -1;
for (int i = 0; i < clasesListView.Items.Count; ++i)
{
ListViewItem item = GetListViewItem(i);
if (this.IsMouseOverTarget(item, getPosition))
{
index = i;
break;
}
}
return index;
}
private bool IsMouseOverTarget(Visual target, GetPositionDelegate getPosition)
{
Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
Point mousePos = getPosition((IInputElement)target);
return bounds.Contains(mousePos);
}
delegate Point GetPositionDelegate(IInputElement element);
ListViewItem GetListViewItem(int index)
{
if (clasesListView.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
return null;
return clasesListView.ItemContainerGenerator.ContainerFromIndex(index) as ListViewItem;
}
Hoops, sorry. This should work fine:
FrameworkElement element = (FrameworkElement)e.OriginalSource;
ListViewItem lvi = (ListViewItem)listView1.ItemContainerGenerator.ContainerFromItem(element.DataContext);
You want to use the GetItemAt function. You may also need to call the PointToClient function before the GetItemAt since you need to work with client coordinates.

Resources