Using Dvexpress Gridcontrol

Asked

Viewed 409 times

-2

I’m developing an application using Devexpress, where the user clicks on a line in Gridcontrol, when this happens the data of this line are placed in some Textbox, the difficulty has been in finding out the name of the event that I should use every time the user clicks a line, and how I search for this information from Gridcontrol.

2 answers

1

Although confusing the question, I believe you want to get a certain datagrid field value and send it to a textbox, the event is called Row.Selected, I will explain better:

Suppose we have a table called Gridclientes and it contains 2 columns "id" and "name", to send the value of "id" to a textbox, we must use the following code:

idclient.Text = GridClientes.CurrentRow.Cells[0].Value.ToString();

the cell value is counted from 0, so... if I have 2 fields, they are Cells[0] and Cells[1].

This code can be called inside a button event:

    private void button1_Click(object sender, EventArgs e)
    {

        idClient.Text = GridClientes.CurrentRow.Cells[0].Value.ToString();
    }

When a cell in the table is selected:

    private void GridClientes_CellEnter(object sender, DataGridViewCellEventArgs e)
    {
        idClient.Text = GridClientes.CurrentRow.Cells[0].Value.ToString();
    }

Or when an entire row of the table is selected (you need to configure this feature):

    private void GridClientes_RowEnter(object sender, DataGridViewCellEventArgs e)
    {
        idClient.Text = GridClientes.CurrentRow.Cells[0].Value.ToString();
    }

I hope I’ve helped.

  • In the case was used the Devexpress Gridcontrol, so some options are different, besides the goal was that every time the client clicks on a Gridview record appears in a Textbox

  • 1

    In this case my answer is useless, but the logic is still the same, you must follow the grid.rowselected event

0


The correct one was to use the Gridview events, instead of the Gridcontrol. So I used the Focusedrowchanged event so every time the user clicks another Grid option will run the code.

With dtbTabela.Rows.Item(GridView1.GetFocusedDataSourceRowIndex)
        txtCampo.Text = .Item("dtcCampo")
        txtCampo2.Text = .Item("dtcCampo2")

End With

This code takes the index of the line the user is clicking and then showing in two Textbox the value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.