I want to build a DataGridView, which if I choose one of the item of a DataGridViewComboBoxCell, then the other cells in the same row which should be TextBoxes in other rows will turn into ComboBoxes,does anyone knows how to do that?
It is like:
TextBox1|TextBox2|ComboBox1.Item1|TextBox3 |TextBox4 |TextBox5 |TextBox6
TextBox1|TextBox2|ComboBox1.Item3|TextBox3 |TextBox4 |TextBox5 |TextBox6
TextBox1|TextBox2|ComboBox1.Item2|ComboBox3|ComboBox4|ComboBox5|ComboBox6
If you want to do something when the Value in a DataGridViewCell changes then you should handle the CellValueChanged event of the grid.
If you want to place a cell of a specific type in a specific location in a DataGridView then you can do so using the grid's indexer, e.g.
myDataGridView[columnIndex, rowIndex] = new DataGridViewComboBoxCell();
In summary, handle the CellValueChanged event, use an if statement to test whether the Value is one that corresponds to a text box or combo box and, if the types of the other cells are not what they should be, replace them.
Related
How to make a Row select highlight specific Cells and not all the Row in a Grid View. I have explored all the questions on SOF, but there is nothing is available.
Set the SelectionMode property of the Grid to CellSelect
You need the set the selection mode on the Grid to cell selection.
If you want it to act like a row select but keep a few cells un-highlighted you should use CellSelect as the selection mode. Then register on row selection changed and set the cell.Selected = true; for the ones you want selected, and false for the rest.
I found the solution !! If you want to control the highlight of a row to a certain range of cells, then you need to control the behavior of the cells in question and make them behave differently when the a row is selected.
YourGridviewInstance.GetCellRange(int topRow,int leftColumn,int buttomRow,inr RightColumn)
in other words
YourGridviewInstance.GetCellRange(YourCurrentRow, The column you want to affect,YourCurrentRow, The Same Column you want to affect)
I want to hide specific cells in gridview. I have a view that is generated that has a delete column. I want the delete column there so I cant hide the entire thing using:
Gridview.Columns[3].Visible = false;
But if the row was generated before a certain date I don't want the delete cell to show up in that row. I already have the logic to check this but how do I hide the actual specific cell?
Assign empty string to cell, you can not hide single cell with server code.
Gridview.Rows[3].Cell[index].Text = "";
OR, clear all controls in the cell.
Gridview.Rows[3].Cell[index].Controls.Clear();
Add some logic into the GridView's RowDataBound event handler to make the cell's content visible or not.
A Good example on MSDN Link
You don't need to hide the cell. Just make the content invisible.
So, you could set the content to an empty string, or you could set the IsVisible (or similar) property on whatever control you may have in the cell.
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.