Adnan
asked on
How to jump to next selection in a datagridview.....or jump between seleted rows
Hi
I have a datagridview with checkbox selection rows,every time i select cntrl-J i want to jump to next selection checkd in my datagridview.....
I have a datagridview with checkbox selection rows,every time i select cntrl-J i want to jump to next selection checkd in my datagridview.....
private void ReconManuallyGridView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == (Keys.Control | Keys.Z))
{
UndoLastReconciled(this.myOper);
}
if (e.KeyData == (Keys.Control | Keys.J))
{
JumpToNextReconcildRow();
}
}
private bool nextCell = false;
private void JumpToNextReconcildRow()
{
if (!m_isChangingCell)
{
nextCell = true;
this.ReconManuallyGridView.CurrentCell = ReconManuallyGridView[3, ReconManuallyGridView.CurrentRow.Index];
nextCell = false;
}
}
ASKER
Hi jorgesv13:
I get error on this line if (ReconManuallyGridView[0, i].Value != false)
error: Error 6 Operator '!=' cannot be applied to operands of type 'object' and 'bool'
I get error on this line if (ReconManuallyGridView[0, i].Value != false)
error: Error 6 Operator '!=' cannot be applied to operands of type 'object' and 'bool'
you should do a casting to bool before making the comparison
if ((bool)ReconManuallyGridVi ew[0, i].Value != false)
if ((bool)ReconManuallyGridVi
ASKER
hmm oki, but know i get exeption saying that specified cast is not valid...?
Are you sure yout first column is your checkbox column?
You should replace the "0" for the correct index.
Or maybe you can try specifying the name of the column.
Example:
if ((bool)ReconManuallyGridVi ew["myChec kboxColumn ", i].Value != false)
You should replace the "0" for the correct index.
Or maybe you can try specifying the name of the column.
Example:
if ((bool)ReconManuallyGridVi
ASKER
hmm oki, its working know, but if i hvae more then one row checked i want to loop in selection and stop when it comes to last selection....?
ASKER
i mean dont stop on last selection..!! loop throow
add a break instruction just after the line where you set the CurrentCell
ReconManuallyGridView.Curr entCell = ReconManuallyGridView[3, i];
break;
ReconManuallyGridView.Curr
break;
ASKER
i set the break point as you sayd but know it has stop jumping......it stays on the same selection and not jumping throow....
ah.. maybe it's staying in the first
try adding one to the initial iterator:
for (int i = curr +1; .....
try adding one to the initial iterator:
for (int i = curr +1; .....
ASKER
without break point it jumps to last index and the 2 or 3 index....?
ASKER
and not
ASKER
oki but how can i correct this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi jorgesv13:
*yes i try adding one to intitial iterator it worked fine, but if selection is on last selection it wont jump to first one, how can i jump from last selection to first?
private void JumpToNextReconcildRow()
{
int curr = ReconManuallyGridView.Curr entRow.Ind ex;
//for (int i = curr; i <= ReconManuallyGridView.Rows .Count - 1; i++)
for (int i = curr + 1; i <= ReconManuallyGridView.Rows .Count - 1; i++)
{
//change 0 for the index of your checkbox column
if ((bool)ReconManuallyGridVi ew["recon" , i].Value != false)
{
ReconManuallyGridView.Curr entCell = ReconManuallyGridView["rec on", i];
break;
}
}
}
*yes i try adding one to intitial iterator it worked fine, but if selection is on last selection it wont jump to first one, how can i jump from last selection to first?
private void JumpToNextReconcildRow()
{
int curr = ReconManuallyGridView.Curr
//for (int i = curr; i <= ReconManuallyGridView.Rows
for (int i = curr + 1; i <= ReconManuallyGridView.Rows
{
//change 0 for the index of your checkbox column
if ((bool)ReconManuallyGridVi
{
ReconManuallyGridView.Curr
break;
}
}
}
ASKER
I MADE IT..... ;)
here is the code.....
private void JumpToNextReconcildRow()
{
int counter;
int curr = ReconManuallyGridView.Curr entRow.Ind ex;
for (int i = curr + 1; i <= ReconManuallyGridView.Rows .Count - 1; i++)
{
if ((bool)ReconManuallyGridVi ew["Recon" , i].Value == true)
{
ReconManuallyGridView.Curr entCell = ReconManuallyGridView["Rec on", i];
return;
}
}
for (int i = 0; i <= curr; i++)
{
if ((bool)ReconManuallyGridVi ew["Recon" , i].Value == true)
{
ReconManuallyGridView.Curr entCell = ReconManuallyGridView["Rec on", i];
return;
}
}
}
here is the code.....
private void JumpToNextReconcildRow()
{
int counter;
int curr = ReconManuallyGridView.Curr
for (int i = curr + 1; i <= ReconManuallyGridView.Rows
{
if ((bool)ReconManuallyGridVi
{
ReconManuallyGridView.Curr
return;
}
}
for (int i = 0; i <= curr; i++)
{
if ((bool)ReconManuallyGridVi
{
ReconManuallyGridView.Curr
return;
}
}
}
ASKER
thanks
Open in new window