i am using a web application gridview on my page...
I want to get the selected(mouse clicked) cell text value & also which event i want to use?..!
use SelectedIndexChanged event.
I am not sure about cell, but you can definitely get the selected row. First of all, set the allow selection property to true. Second, go in events and there should be an event called SelectedIndexChangedThis would allow you to do something when the selected index is changed. Then, using
gridvidew1.Rows[gridView1.selectedindex]
you will be able to get the selected row. User can select the row by using the select link placed automatically against each row.
Hope this helps,
Related
I have created a DataGridView in a forms based application.
I have preselected some some rows based on some conditions using the following code:
DataGridView1.Rows[i].Selected = true;
now I have a button which allows the user to move the focus(record pointer) to the next selected row.
When the user clicks the button I do the following
DataGridView1.CurrentCell = DataGridView1[0,row_number];
but when this happens the previously selected row loses the highlight.
I want to maintain the highlight (selection) of the previous row also but the record pointer should be moved to the next selected row.
How can I acheive this.
When you make DataGridView1.CurrentCell equal to a single cell (row), the multiselection is converted into single selection and thus all the other rows are deselected (Selected property set to False).
There are various options to avoid that:
The most logical option is not relying on DataGridView1.CurrentCell
at all. You can create your own variable to store the current cell
being edited (you might even store it in the DataGridView itself, via
its Tag property).
Another option would be affecting the style (background color) of the rows selected sofar to transmit to the user the impression that they are
still selected. Although this second option is not too recommendable,
as far as all the "associated features" (e.g., Selected property)
would continue behaving as if these rows wouldn't be selected.
I have a DataGridView in which I am binding some records. I have a button Edit on my form. I want to Edit all the rows and column of the datagridview when I click on button Edit, so that user can change the data as per there need, and the data which is changed it should show in different color, so that user can recognizes that this data got changed.
till binding of grid I have done, how to edit and assign the color into changed cell I am unable to find solution.
Please something help me, with some exp. code. or some sugg.
You can try with EditMode and ReadOnly
You set EditMode = DataGridViewEditMode.EditOnEnter.
You set ReadOnly to true for the cell, row, column, and control.
Link : http://msdn.microsoft.com/en-US/library/system.windows.forms.datagridview.editmode(v=vs.80)
There is already a property for that Enable Editing.
And after that you can apply formatting with the help of DataGridView.CellValueChanged Event
I have a DataGridView with checkBoxColumn.When I clicked on checkBoxCell of CheckBoxColumn it adds New Row to dataGridView.But I do not want to add row on click event or checked chang event of DataGridViewCheckBoxColumn.
Please some one suggest me how to do this.
Thanx in Advance.
After binding the rows set AllowUserToAddRows property to false.
Ex:
MyDataGridView.AllowUserToAddRows = false;
It looks like you are clicking the check box on a new created row (normally the last row in your GridView)
This row has not jet been attached to your underlying datasource, but will be attached as soons as you change the value of your checkbox cell.
At this stage I don't think there is a way to prevent it (unless you prevent the user from adding new rows at all).
You could handle DefaultValuesNeeded() to set the checkbox to an appropriate value.
In design view right click on the data grid view. There will be a check box with description "Enable Editing". Please uncheck it. Then there wont be any new row added on click of the checkbox
how to capture event when moving from one cell to another in same row.
You get the CurrentCellChanged event:
[...] when the value of the CurrentCell property has changed.
You'd have to check you were still on the same row, but it should do what you want.
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.