This project is read-only.

Get row index

Oct 19, 2010 at 8:55 AM

Hi everybody,

i've a datagrid with selectionmode=row, multiselection=false, the datasource is a bounded list of List<Carpeta>. 

private List<Carpeta> carpetas;
private BoundList<Carpeta> carpetasB;


carpetasB = new DevAge.ComponentModel.BoundList<Carpeta>(carpetas);
carpetasB.AllowEdit = false;
carpetasB.AllowNew = false;
dataGrid1.DataSource = carpetasB;

Well, when i need edit in a dialog form the current row, what i mind to do is:

1- get the selected object

Carpeta c = (Carpeta)dataGrid1.SelectedDataRows[0];

2- call beginedit in carpetasB, but i need the index of object inside bounded list. I mind IndexOf could be the solution, but it would result slow for a big resultset, isn't it? Is there any other solution to put carpetasB in edit mode?



Juan Pedro Rubio

Oct 19, 2010 at 8:56 AM

Of course, dataGrid1.Selection.ActivePosition always returns -1;-1

Oct 25, 2010 at 8:56 AM

>> Of course, dataGrid1.Selection.ActivePosition always returns -1;-1>

This looks like a bug,


There is also sample 54, which shows how to programaticaly  edit cell, but it does not work also. Looks like the same ActivePosition -1, -1 reason

Oct 25, 2010 at 9:11 AM

Ok, here's some results:

frmSample54 was almost correct :)   The only chnages i had to make to make it work is define what focus style i want for a selection.

grid1.Selection.FocusStyle = FocusStyle.None;

This line above prevents removing ActivePosition value upon losing focus.   The code is in bitbucket, please update and check this example. Maybe this will help you somehow