0

I am making payment screen with c# winform, the ODEMEID in gridview1 is registered in the ODEMEBELGETID field in the gridview2 record,

when I recall the record, the first ODEMEID value I select in gridview1 is not automatically checked in gridview2, but if I select the second record, the corresponding record in grid2 is checked, then if I select the first record, grid2 is checked.

When the form is loaded, the first ODEMEID is automatically transferred to memory. When the records are loaded into the form, if the ODEMEID value is -1, my problem is solved.

private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
    try
    {
        object odemeIdValue = gridView1.GetFocusedRowCellValue("ODEMEID");

        if (odemeIdValue != null && odemeIdValue != DBNull.Value)
        {
            int odemeID = Convert.ToInt32(odemeIdValue); 
            SelectAndFocusGridView2Rows(odemeID); 
        }
        else
        {
            DeselectGridView2Rows(); 
        }
    }
    catch (Exception ex)
    {
        Mesajlar.Hata(ex); 
    }
}

private void SelectAndFocusGridView2Rows(int odemeID)
{
    //DeselectGridView2Rows(); 
            
    for (int i = 0; i < gridView2.RowCount; i++)
    {
        var rowValue = (int)gridView2.GetRowCellValue(i, "ODEMEBELGEID");

        if (rowValue == odemeID)
        {
            gridView2.SelectRow(i);

            gridView2.FocusedRowHandle = i;
        }
    }
}

private void DeselectGridView2Rows()
{
    for (int i = 0; i < gridView2.RowCount; i++)
    {
        gridView2.UnselectRow(i); 
    }
}
3
  • so your exact problem is what ? Commented Sep 28, 2024 at 8:40
  • If there is only 1 record in gridview1, when the selection process is performed, it does not select the matching records in gridview 2. Commented Sep 29, 2024 at 13:20
  • 1
    I imagine that in this case the focusedrowhandle never changes, you will have to call your subroutine manually in that case maybe Commented Sep 30, 2024 at 11:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.