Open a form based on row selection from datagrid

Out of curiosity, can I open a form based on row selection in a datagrid? I also need a form to display information based on the username in the datagrid. The username of the users is included in the data row.

+3
source share
3 answers

You can handle this at the next event

 dataGridView1_CellClick

Get value CurrentCellfor datagridiview

Check availability usernameor not according to your request and show the corresponding form

Code example:

if (this.dataGridView1.CurrentCell != null) 
{
    string strusrname=dataGridView1.CurrentCell.Value.ToString();
    //Here find out for the user name from the string as you get the currentcell value of the datagridview
    // Raise the corresponding form as per you required
} 
+2
source

You will need to code this, but yes, it is possible.

First, populate the DataGrid with data that you can process.

DataGrid Changed , , ( ), Show().

.

+4

, , , , , . , , , , datagrid, :

<asp:HyperLinkcolumn DataNavigateUrlField="Username" 
                     DataNavigateUrlFormatString="PersonForm.aspx?Username={0}"     
                     HeaderText="More Details" 
                     Text="View Person Details" />

PersonForm . , , itemcommand, .

, .

: winforms : DataGridViewLink MSDN

:

DataGridViewLinkColumn links = new DataGridViewLinkColumn();

links.UseColumnTextForLinkValue = true;
links.HeaderText = ColumnName.ReportsTo.ToString();
links.DataPropertyName = //Set your field here.
links.ActiveLinkColor = Color.White;
links.LinkBehavior = LinkBehavior.SystemDefault;
links.LinkColor = Color.Blue;
links.TrackVisitedState = true;
links.VisitedLinkColor = Color.YellowGreen;

DataGridView1.Columns.Add(links);

After you added the link, you can catch it using DataGridView1_CellContentClick and do what you want with it, that is, open a new form or change the current one.

0
source

All Articles