Hello guys sorry if this question was posted many times but i searched and so far no answer satisfactory enough.I a bit new to infragistics.I'm using the version .NETAdvantage 2007 vol 2 CLR 2.0 and this is my first project.
here is my problem.
I've tried using the ultragrid with an objectdatasource or a webservicedatasource collecting an array of an object and it's works very well.so to access an activerow data i use
private void utAllUsers_AfterSelectChange(object sender, AfterSelectChangeEventArgs e) { try { selected = (IUser)utAllUsers.DisplayLayout.ActiveRow.ListObject; } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
Now the problem is that i've created a simple table (Id | Name | Description) with primary key Id (identity)
i bind the grid to a datatable and when i try to access the id of the active row, it Gives me Compleley other ids and i don't get it at all
here are codes
private void utgrRights_AfterSelectChange(object sender, AfterSelectChangeEventArgs e) { UltraGridRow rightrow; rightrow = utgrRights.Rows[utgrRights.DisplayLayout.ActiveRow.ListIndex]; rightid = (int)rightrow.Cells[0].Value; Name = rightrow.Cells[1].Value.ToString(); }
How do i get the correct Id no matter how Sorted is the table? Thanks for reading this!!
You're confusing active and selected row. Active row is the row that has the focus, hence there is only one active row. Any row can be selected and there can be more than one.
If you want to get the active row when it is changed, use AfterRowActivate and get its object by grid.ActiveRow.ListObject
If you want the selected row(s) use grid.Selected.Rows[]
Thanks for reading and for replying.I think what i want is activerow since i want to edit it by giving it the focus.There is a second aspect of the question i'll like some few help.Supposing i use the selected property that you suggested ,how do i know the exact index of the row which is selected in order to get that UltraGridRow t o extract it value since i don't use object this time?Thanks again
thanks for the reply.let's take some real example.i have a table(id| Name | Description-- id identity ).i use a simple stored procedure to fetch the data into a datatable that i bind to the ultragrid.Now i want to edit the name of the user whose role has the focus.How would i do that.(Please refer to my second post to see my actual implementation).What i did is to try to get the id(database id) pass it to the edit form and do the rest from there.I needed to get the activerow and then get it's Cell[0] to extract the id i'm interested in.
Comparing to what i did how would you do that?
please take note that when the grid sorting order changed my implementation becomes so wrong.That is my worries.Thanks :) people here are nice
Instead of:
UltraGridRow rightrow; rightrow = utgrRights.Rows[utgrRights.DisplayLayout.ActiveRow.ListIndex]; rightid = (int)rightrow.Cells[0].Value; Name = rightrow.Cells[1].Value.ToString();
Write:
var rightrow = utgrRights.DisplayLayout.ActiveRow
rightid = (int)(rightrow.Cells[0].Value); Name = rightrow.Cells[1].Value.ToString();
Pay attention that using row.Cells is not recommended. Look here:
http://forums.infragistics.com/forums/p/15306/56104.aspx#56104
Thanks Man! it solved my problem.I took time to test it before.Thanks for the tips
i just did this
rightrow = utgrRights.DisplayLayout.ActiveRow; rightid = (int)rightrow.GetCellValue(utgrRights.DisplayLayout.Bands[0].Columns[0]); right = rightrow.GetCellValue(utgrRights.DisplayLayout.Bands[0].Columns[1]).ToString();
The API is so Huge man.I just wonder if i'll find my way on day.Thanks!
It is huge indeed. I'm using it for 5 years and I still learn new staff every day.
Add this code somewhere and you'll be able to use GetCellValue with column name or index:
public
{
/// Returns the data value for a cell from the database
/// <param name="row">The row contains the cell</param>
}
thanks for the tips.very handy