We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to select a row in a grid by programmation

Hi,

I use a grid of type Syncfusion.Windows.forms.grid.gridControl

I can not figure out how to select a specific row at a specific rowIndex

I have the rowIndex but can not find the way to do this. This is supposse to be very simple but it seams to be complicated

I try something like but it doesnt work
MyGrid.Rows(rowIndex).selected = True

Do you have any ideas?

Thanks in advance!








5 Replies

AD Administrator Syncfusion Team May 7, 2008 11:16 AM UTC


Hi,

You can select a specific row at a specific rowindex with the help of following code snippet.


private void button1_Click(object sender, EventArgs e)
{
this.gridControl1.Model.Selections.Add(GridRangeInfo.Rows(2,3));
}

private void Form1_Load(object sender, EventArgs e)
{
this.gridControl1.AllowSelection = GridSelectionFlags.Any;
this.gridControl1.ListBoxSelectionMode = SelectionMode.MultiExtended;
this.gridControl1.AlphaBlendSelectionColor = Color.Yellow;
}


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F73347/main.htm

Please let me know if you have any questions.

Regards,
Asem.



GC Gilles Carreau May 7, 2008 09:09 PM UTC

Hi,

I tried the exemple that you give me and I can now select the row that I want

The problem is after I select the row that I want when I try to get the new rowIndex of this new row I still get the old rowIndex

This an exemple of a test that I do to verify if the rowIndexof the new row selected has changed

Dim iRowIndex As Int32 = gcTermes.CurrentCell.RowIndex()
' I show the actual row Index of the actual selected row
MsgBox(iRowIndex.ToString)
gcTermes.Model.Rows.RemoveRange(iRowIndex, iRowIndex)
' I select the rows just before the actual row selecteted
gcTermes.Model.Selections.Add(GridRangeInfo.Rows((iRowIndex - 1), (iRowIndex - 1)))
' I show the actual Selected rowIndex
msgBox(gcTermes.CurrentCell.RowIndex.toString)

What i am looking for is to select a specific row in the grid just like when you click on the row with a mouse click

Do you know what I am doing wrong?

Thanks in advance an have a nice day


>
Hi,

You can select a specific row at a specific rowindex with the help of following code snippet.


private void button1_Click(object sender, EventArgs e)
{
this.gridControl1.Model.Selections.Add(GridRangeInfo.Rows(2,3));
}

private void Form1_Load(object sender, EventArgs e)
{
this.gridControl1.AllowSelection = GridSelectionFlags.Any;
this.gridControl1.ListBoxSelectionMode = SelectionMode.MultiExtended;
this.gridControl1.AlphaBlendSelectionColor = Color.Yellow;
}


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F73347/main.htm

Please let me know if you have any questions.

Regards,
Asem.





AD Administrator Syncfusion Team May 8, 2008 06:15 AM UTC


Hi,

You can set the CurrentCell.MoveTo to the selected row. Please refer the following code snippet that shows how we can move the current cell to the selected row.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.GridControl1.Model.Selections.Clear()
Me.GridControl1.Model.Selections.Add(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Rows(5, 5))
Me.GridControl1.CurrentCell.MoveTo(5, 1)
End Sub


Please refer the modified sample in the below link.

http://websamples.syncfusion.com/samples/Grid.Windows/F73347B/main.htm

Please let me know if you have any questions.

Regards,
Asem.



GC Gilles Carreau May 8, 2008 12:58 PM UTC

Hi,

I would like to tanks you for the support that you give me. It is appreciate

Now everything works like I want

It is a simple task but I find it hard to find out the way this grid work.

So thanks again and have a nice day!

GC




AD Administrator Syncfusion Team May 9, 2008 02:28 PM UTC


Hi GC,

We are glad that you have resolved this issue.

Thanks for the interest in Syncfusion Grid.

Regards,
Asem



Loader.
Live Chat Icon For mobile
Up arrow icon