mouse click event on row in Data Grid in C# - c#

How to handle mouse click on a row in Datagrid in C#
for eg if i m populating a table from my database in a data grid and when i select a row .i should be able to go to a different page and display the contents of that row in text boxes .is it possible to do that in c#

You can handle SelectionChanged event of DataGridView and use DataGridView1.SelectedRows collection to get reference of selected row(s).
if(DataGridView1.SelectedRows.Count!=0)
{
str = DataGridView1.SelectedRows[0].Cells[0].Value;
}

Related

how to get the rows if textbox value has changed inside gridview

After editing the textbox values inside this gridview, i need to get the rows (only edited rows) in button click event (button placed outside the gridview).
Add event listener on the gridview to grab the selected items value on change, and add them to an array. Loop through to use the data.

Make Rows of DATAGRID (NOT DATAGRIDVIEW) Clickable

As the title says, I want to make the rows of a DataGrid clickable.
The DataGrid is populated from a MySQL database and I want a situation where when a row is clicked I can perform action just like you would a button on click. Any help?

Load checked datagridview row to another datagridview in another form

I have a DataGridView1 with data and a checkboxcolumn in the [0]
position.
In the form that contains the DataGridView1 with the checkboxes, I
have a button
Now, what I need is a way that allows me, after I check the rows I
want, get the checked rows to another form creating a small
datagridview with these rows.
I want to associate this function to the button_click event.
It's all about multiple selection, the basic "import the lines you want to a previous form".
Can anyone help me?
BIG THANK YOU
foreach (DataGridViewRow row in YourDgvMain.Rows)
{
if ((bool)row.Cells[0].Value == true)
{
YourOtherDgv.Rows.add(row);
}
}
My solution is a bit messy but should work: bind the row id to the checkbox, store the checked values in a collection, query again the datasource with the condition WHERE [id] IN ([your collection]) and create the second datagridview with the result of the query.
You should specify however what is the source for the gridview and how do you retrieve the data to get a better answer.

To get the row index of a datagrid

Iam new to Silverlight. I have a Data Grid with few Text box Template columns . I have bound the grid to a list so that changes in the text box are reflected in the data source entity .
User would type the data in the text box and in the "onleave" event of the text box template column, and I would save the data typed.
I find that data is getting reflected in the enitity. But I cannot use the dataGrid.SelecedItem or dataGrid.SelecedIndex property of the datagrid as user would have seleced a different row after leaving typing data in one row.
My doubt is , how can we find the index of the current row he has edited inside the onleave event of the text box template column ?
Under dataGrid_RowBound(...) event
use e.RowIndex where e is the parameter ( of type EventArgs class)
Instard of OnLeave event you can use the row edit ended event for where you can get e.Row the edited row object . which can be used to save the entity.

How to solve this combo box issue in datagridview in .net winforms?

i had two combobox(Catogery, product) in my grid.
what i want to do is.
if i select category it will display some data set value based on category,
and if i select product it will bind some values in that datagrid cells.like price quantity..
i don't have idea about how to write event for combo box selected index change event which is inside the grid.
Handle the CellEndEdit event on the DataGridView. You'll have to test that the sender is the correct DataGridViewComboBoxColumn, read the value, and use that to bind the other DataGridViewComboBoxColumn to the appropriate data source.
I'm not sure about that, because I don't have visual studio at the moment. But there must be an event called RowCellValueChanged event, write your code in this event, hand row index with EventArgs e and set your values to row which you have an index of row.

Categories

Resources