Accessing grid columns in same sequence in which they are visible - asp.net

I need to access columns of infragistics ultragrid in same sequence in which they are being displayed in grid. If i can get the index of column in same sequence as they are visible on grid, i can fix my issues.
Thanks in advance.
Lalit

UltraGridColumn column = this.ultraGrid1.DisplayLayout.Bands[0].Columns[0];
Debug.WriteLine( "Columns in visible order: ");
// Get the first visible column by passing in VisibleRelation.First.
column = column.GetRelatedVisibleColumn( VisibleRelation.First );
while ( null != column )
{
Debug.WriteLine( " " + column.Key );
// Get the next visible column by passing in VisibleRelation.Next.
column = column.GetRelatedVisibleColumn( VisibleRelation.Next );
}
http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v8.2~Infragistics.Win.UltraWinGrid.UltraGridColumn~GetRelatedVisibleColumn.html

I suppose you could try to handle the event that is fired when the order is changed and keep track of all the changes, but this seems like it is asking for subtle bugs to creep in.
I considered looping through all the columns and trying to use some property that would tell me their current position (maybe the TabOrder?) and use that to compile an inorder list of the columns. I guess you might have to loop through each colum using the Column.GetRelatedVisibleColumn() method.
I have not actually implemented it yet as I have other higher priority issues but that may be the road I end up going down.

This is an old question, but I recently had same issue and solved it this way:
var selectedCells = this.Selected.Cells;
List<int> columns = new List<int>();
foreach (var cell in selectedCells)
{
if (!columns.Contains(cell.Column.Index))
columns.Add(cell.Column.Index);
}
columns.Sort((x, y) => this.DisplayLayout.Rows.Band.Columns[x].Header.VisiblePosition.CompareTo(this.DisplayLayout.Rows.Band.Columns[y].Header.VisiblePosition));
You can then use columns to access columns in order they are shown.

Related

Is there way to change column values of selected rows through Propel?

Rows are selected like that:
$book->getBookGenreToBooks()->???()
I want to change the column «checked» of all selected rows.
Your given solution in your answer is very inefficient since it creates for each update a new query. A better way is to do all changes in one query:
BookGenreQuery::create()
->filterByBookId($book->getId())
->update(array('Checked' => 1));
I don't know how exactly your relations and fields are named by you should get the idea behind it.
$genresToBook = $book->getBookGenreToBooks();
foreach ($genresToBook as $genreToBook) {
$genreToBook->setChecked(1); //Set any data here
}
$genresToBook->save();
This isn't exactly what I want, but that works fine to me.

How to check specific column exist in datarow?

I came across situation,where columnname for datatable is dynamic.While fetching a data I want to check existence of column.
DataTable table = ds.Table["Sample1"]
if(table.Row.Count > 0)
{
foreach(DataRow dr in table.Rows )
{
if(dr.Table.Column.Contain("DateInfo"))
{
// store value in variable
// first approach
}
if(table.Column.Contain("DateInfo"))
{
// store value in variable
// second approach
}
}
}
Which one is best approach?
Will this be enough:
1st Approach: Which will simply check in an entire DataTable.
datatable.Columns.Contains("column")
2nd Approach: which will check for each row collection in DataTable
dr.Table.Columns.Contains("column")
3rd Approach: Which fetch each columns in DataColumnCollection object and then check if it contains the specific field or not.
DataColumnCollection columns = datatable.Columns;
if (columns.Contains(columnName))
So these all approaches are better in their own way. you can use whatever you find it better.
This is best one
dr.Table.Column.Contain("DateInfo")
foreach loop get single row at a time sometimes if any conditional is possible in this method

Cant get ExtededDataGrid in Flex to filter with ComboBox on multiple columns

LATEST UPDATE: Issue answered here. Some one else at stackoverflow had a similar issue and it was resolved. Solution provided for convenience. This is the line of code I was missing:
comboHeaderColumn.useLabelFunctionForFilterCompare = true;
that line is followed by these:
comboHeaderColumn.filterComboBoxBuildFromGrid = true;
comboHeaderColumn.labelFunction = formatState;
where formatState is a local method that formats the data for the combobox.
UPDATE: I've now got the combobox's loading with the correct data, but when I select a value nothing happens. The combo boxes load only data that is in the column, and when you select a value in the combobox, it's supposed to filter the rows on that value. It doesn't.
Thanks for looking. I'm having trouble getting multiple filters to work in Flex in Flash Builder 4 using the ExtendedDataGrid and ComboBox's. Here is an image of part of the grid:
The User Name and City filter properly if you type text into the box's above the column header and the Request Date lets you select date ranges if you click on the Custom bar, but the Request Reason and State ComboBoxes do not list anything. I've created them using comboHeaderColumn.filterComboBoxBuildFromGrid = true; but all it does is put "[object Object]" as the only other selection under All.
I've used this article but it will only allow you to use a single filter for the entire grid.
My finished grid will have about 20 columns and from 20,000 to 450,000 rows of data so the filters are really important and I'll need more than one.
The code is very straight forward and loops through all the returned data and if the column is identified as a filter column it does this:
comboHeaderColumn.filterComboBoxDataProvider = codeValuePairs;
comboHeaderColumn.filterComboBoxLabelField = "Value";
comboHeaderColumn.filterControl = "ComboBox";
comboHeaderColumn.filterOperation = FilterExpression.FILTER_OPERATION_TYPE_EQUALS;
comboHeaderColumn.headerText = ac.Header;
comboHeaderColumn.dataField = ac.Name;
if( ac.Header == "State" || ac.Header == "Request Reason" )
{
comboHeaderColumn.filterComboBoxBuildFromGrid = true;
}
ProfileDataColumns.push(comboHeaderColumn);
This creates 2 entries in the combo box: All and [object Object]
What am I missing??? Anyway, after half a day searching I decided to reach out.
Any suggestions or direction to an article would be very much appreciated.
Thanks.

Flex mobile - How do I move to the next data in List.selectedItem when moving to next page?

When I move page01 to page02, I pass the same data along with it using the following code:
navigator.pushView(Page02, data);
How do I move to page02 with passing the next row of data (instead of the same data)?
In other word, how to increment to the next row of data with pushView?
Thanks.
If you have access to the List component which displays the data you want to pass into views, you can do something like this:
myList.dataProvider[myList.selectedIndex+1]
You'll want to do some checking to make sure that you're trying to reference an index that actually exists:
var mySelectedObject :Object;
if(myList.selectedIndex+1 < myList.dataProvider.length){
mySelectedObject = myList.dataProvider[myList.selectedIndex+1]
} else {
// do some other behaviour; such as selecting the first one in the list
mySelectedObject = myList.dataProvider[0]
}
navigator.pushView(page02, mySelectedObject );

Flex - sorting a datagrid column by the row's label

I'm creating a table that displays information from a MySQL database, I'm using foreignkeys all over the place to cross-reference data.
Basically I have a datagrid with a column named 'system.' The system is an int that represents the id of an object in another table. I've used lableFunction to cross-reference the two and rename the column. But now sorting doesn't work, I understand that you have to create a custom sorting function. I have tried cross-referencing the two tables again, but that takes ~30sec to sort 1200 rows. Now I'm just clueless as to what I should try next.
Is there any way to access the columns field label inside the sort function?
public function order(a:Object,b:Object):int
{
var v1:String = a.sys;
var v2:String = b.sys;
if ( v1 < v2 ){
trace(-1);
return -1;
}else if ( v1 > v2 ){
trace(1);
return 1;
}else {
trace(0);
return 0;
}
}
One way to handle this is to go through the objects you received and add the label as a property on each of them based on the cross-referenced id. Then you can specify your label property to display in your data grid column instead of using a label function. That way you would get sorting as you'd expect rather than having to create your own sort function.
The way that DataGrids, and other list based classes work is by using itemRenderers. Renderers are only created for the data that is shown on screen. In most cases there is a lot more data in your dataProvider than what is seen on screen.
Trying to sort your data based on something displayed by the dataGrid will most likely not give you the results you want.
But, there is no reason you can't call the same label function on your data objects in the sortFunction.
One way is to use the itemToLabel function of the dataGrid:
var v1:String = dataGrid.itemToLabel(a);
var v2:String = dataGrid.itemToLabel(b);
A second way is to just call the labelFunction explicitly:
var v1:String = labelFunction(a);
var v2:String = = labelFunction(b);
In my experience I have found sorting to be extremely quick, however you're recordset is slightly larger than what I usually load in memory at a single time.

Resources