Click here to Skip to main content
15,892,059 members
Home / Discussions / C#
   

C#

 
QuestionError casting delegate in non-generic class PinPopular
Kalvin @ Work9-Jun-10 4:19
Kalvin @ Work9-Jun-10 4:19 
AnswerRe: Error casting delegate in non-generic class [modified] PinPopular
Dimitri Witkowski9-Jun-10 8:05
Dimitri Witkowski9-Jun-10 8:05 
QuestionLogin dialog on Page loads Pin
Ramkithepower9-Jun-10 3:59
Ramkithepower9-Jun-10 3:59 
QuestionC# datagridview cell focus Pin
jojoba20119-Jun-10 3:09
jojoba20119-Jun-10 3:09 
AnswerRe: C# datagridview cell focus Pin
Henry Minute9-Jun-10 7:17
Henry Minute9-Jun-10 7:17 
QuestionRe: C# datagridview cell focus Pin
jojoba20119-Jun-10 7:48
jojoba20119-Jun-10 7:48 
AnswerRe: C# datagridview cell focus Pin
Henry Minute9-Jun-10 12:57
Henry Minute9-Jun-10 12:57 
AnswerRe: C# datagridview cell focus Pin
Henry Minute10-Jun-10 3:24
Henry Minute10-Jun-10 3:24 
I have a (sort of) solution. It is not perfect and that bothers me but I cannot spend any more time on this.

I hope that it will at least give you a starting point for a solution of your own.

I tested this using a DataGridView with four text columns. The second column (columnIndex 1) should contain "Home" to be considered valid and cause a jump to the fourth column, and the third (columnIndex 2) should when editing reaches there should contain "Business" to be valid.

C#
private bool IsValidColumn1Response(DataGridViewCell dgvCell)
{
    return (dgvCell.Value == null) ? false : dgvCell.Value.ToString() == "Home";
}

private bool IsValidColumn2Response(DataGridViewCell dgvCell)
{
    return (dgvCell.Value == null) ? false : dgvCell.Value.ToString() == "Business";
}

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
    // base on code from http://stackoverflow.com/questions/751981/bypass-read-only-cells-in-datagridview-when-pressing-tab-key
    DataGridView dgv = sender as DataGridView;
    if (dgv != null)
    {
        // **NOTE** when this event fires, CurrentCell is the cell being moved FROM.
        DataGridViewCell currentCell = dgv.CurrentCell;
        if ((currentCell != null) && (currentCell.ColumnIndex == 1))
        {
            int nextRow = currentCell.RowIndex;
            int nextCol = currentCell.ColumnIndex;
            if (this.IsValidColumn1Response(currentCell))
            {
                dgv[nextCol + 1, nextRow].Value = "N/A";
                nextCol += 2;
            }
            DataGridViewCell nextCell = dgv.Rows[nextRow].Cells[nextCol];
            if (nextCell != null && nextCell.Visible)
            {
                dgv.CurrentCell = nextCell;
            }
        }
        else if ((currentCell != null) && (currentCell.ColumnIndex == 0))
        {
            int nextRow = currentCell.RowIndex;
            int nextCol = currentCell.ColumnIndex;
            if (this.IsValidColumn2Response(dgv[currentCell.ColumnIndex + 2, currentCell.RowIndex]))
            {
                nextCol++;
                dgv[nextCol, nextRow].Value = "N/A";
            }
            DataGridViewCell nextCell = dgv.Rows[nextRow].Cells[nextCol];
            if (nextCell != null && nextCell.Visible)
            {
                dgv.CurrentCell = nextCell;
            }
        }
    }
}


As you will see, if you try this out, there are some problems particularly with going back and changing already entered text. It is, however, a start.

Good luck! Smile | :)
Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.

AnswerRe: C# datagridview cell focus Pin
dan!sh 9-Jun-10 7:55
professional dan!sh 9-Jun-10 7:55 
QuestionRe: C# datagridview cell focus Pin
jojoba20119-Jun-10 8:27
jojoba20119-Jun-10 8:27 
GeneralRe: C# datagridview cell focus Pin
Henry Minute9-Jun-10 10:06
Henry Minute9-Jun-10 10:06 
AnswerRe: C# datagridview cell focus Pin
Dr.Walt Fair, PE9-Jun-10 10:46
professionalDr.Walt Fair, PE9-Jun-10 10:46 
GeneralRe: C# datagridview cell focus Pin
Henry Minute9-Jun-10 11:37
Henry Minute9-Jun-10 11:37 
GeneralRe: C# datagridview cell focus Pin
Dr.Walt Fair, PE9-Jun-10 13:36
professionalDr.Walt Fair, PE9-Jun-10 13:36 
QuestionC# how to keep datetimes independent of regional settings Pin
MayukhSen9-Jun-10 2:01
MayukhSen9-Jun-10 2:01 
AnswerRe: C# how to keep datetimes independent of regional settings Pin
DaveyM699-Jun-10 2:05
professionalDaveyM699-Jun-10 2:05 
AnswerRe: C# how to keep datetimes independent of regional settings Pin
OriginalGriff9-Jun-10 2:16
mveOriginalGriff9-Jun-10 2:16 
AnswerRe: C# how to keep datetimes independent of regional settings Pin
Pete O'Hanlon9-Jun-10 2:36
mvePete O'Hanlon9-Jun-10 2:36 
AnswerRe: C# how to keep datetimes independent of regional settings Pin
Luc Pattyn9-Jun-10 3:30
sitebuilderLuc Pattyn9-Jun-10 3:30 
GeneralRe: C# how to keep datetimes independent of regional settings Pin
MayukhSen9-Jun-10 23:48
MayukhSen9-Jun-10 23:48 
Questionhandle of parent window containing windowless content Pin
rakesh54549-Jun-10 1:33
rakesh54549-Jun-10 1:33 
QuestionBuild exe dynamically Pin
kasraa000980009-Jun-10 0:57
kasraa000980009-Jun-10 0:57 
AnswerRe: Build exe dynamically Pin
OriginalGriff9-Jun-10 1:01
mveOriginalGriff9-Jun-10 1:01 
AnswerRe: Build exe dynamically Pin
datenkabel9-Jun-10 1:51
datenkabel9-Jun-10 1:51 
GeneralRe: Build exe dynamically Pin
ostad_mrn9-Jun-10 1:58
ostad_mrn9-Jun-10 1:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.