In telerik Rad GridView (2014) Winform, i have a gridview with a disabled column but if i type an especific text in another column i want that column to be enabled to write, but only the cell for that specific row
Since you want to some cells editable, you should not disable the whole column. For the purpose of your case, you can use the CellBeginEdit event, which you can cancel if your condition is not met, hence the user will not be able to edit the specified cell:
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
if (e.Column.Name == "columnAtHand" && e.Row.Cells["DependantColumn"].Value == "disallowEdit")
{
e.Cancel = true;
}
}
Related
My Question is about to disable and Enable focused cell of Grid View and change disable cell to color on Key press
but i don't have any idea how to do that I Have done specific row Enabled False using row state helper class But now i want to disable cell How can i do that?
You can use GridView's ShowingEditor event:
private void gridViewTest_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
GridView gridView = sender as GridView;
if(gridView.FocusedColumn.FieldName == "Product Name") // && <PUT OTHER CONDITIONS HERE>
e.Cancel = true;
}
I want my DataGridView to highlight row headers for any rows that have selected cells. Any way to do that?
(Standard behavior seems to be only to highlight the row header if the entire row of cells is selected).
What I've tried:
I've looked at the decompiled source for DataGridView and from what i can tell (which definitely may be wrong) it highlights the header based upon whether the DataGridViewRow is selected. I can't figure out how to set the row selected without the whole row actually being selected
The way I've done this before is to handle the CellStateChanged event, check the cells in the effected cell's row, and set the row header accordingly.
private void DataGridView1_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e)
{
bool selected = false;
foreach (DataGridViewCell cell in e.Cell.OwningRow.Cells)
{
if (cell.Selected)
{
selected = true;
break;
}
}
e.Cell.OwningRow.HeaderCell.Style.BackColor = selected ?
this.dataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor :
this.dataGridView1.RowHeadersDefaultCellStyle.BackColor;
}
You'll need to set the following snippit to enable these changes, as explained here:
this.dataGridView1.EnableHeadersVisualStyles = false;
Not shown: also consider coloring the header cell for Row[0] when everything is initialized.
I'm working in RadGridView where i need to copy the cell content.
As part of the application functionality, i want the Grid SelectionUnit to always be of type Row. In addition to this, we also want to expose a mechanism where the user can select a cell value for copy to clipboard.
Is there a way to do this? For example, double clicking a cell copies the cell value where as single click always selects the row.
Try this,
Not a perfect one, but for your requirement it suits.
void testGridView_CopyingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e)
{
if (grdName.CurrentCell != null && grdName.CurrentCell.Column == e.Cell.Column)
{
e.Cancel = false;
}
else
e.Cancel = true;
}
Where replace your GridView name with "grdName".
Here I have a column name "Status" in which I am using ComboBox whose values are "Pending" and "Delivered" now I want that when a user selects the delivered from the ComboBox then the entire row or this control should be disabled so user could not change it again and by default its value should be "Pending" how can i do it? Is it possible to disable a single row in gridview?
You cannot disable an individual row. However you can make it readonly:
DataGridView1.Rows[rowIndex].ReadOnly = true;
(This makes row with index of rowIndex set to readonly).
For your specific example, you would want to handle the CellValueChanged event of the datagridview and have code along the lines of:
void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4 && DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "Delivered")
{
DataGridView1.Rows[e.RowIndex].ReadOnly = true;
}
}
You can handle the RowChanged event and do something like
if (Status == 'Delivered')
{
e.Row.Enabled = False;
}
I have a DataGridView where each row has a checkbox in it. I only want the selected row to change when the user clicks on one of the text cells. However, if a checkbox is clicked I would still like to have the checkbox change its state and catch this event.
I have searched everywhere and found a couple of solutions that fix half of the problem, but I haven't found anything that 100% prevents the selected row from changing when I click on my checkboxes.
Figured out a work around.
Instead of listening for SelectionChanged events, I listened for CellMouseClick events and then toggled my own flag for which row is selected.
I also changed the default row style so that there is no indication of which row is selected. Then i added some code to change the row style of whichever row was selected according to my own row.
Below is the code just for listening to CellMouseClicks on certain columns, the rest is very specific to my application.
void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
// Make sure it is a left click
if(e.Button == MouseButtons.Left)
{
// Make sure it is on a cell
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
// Only allow certain columns to trigger selection changes (1 & 2)
if (e.ColumnIndex == 1 || e.ColumnIndex == 2)
{
// Set my own private selected row index
setSelectedRow(e.RowIndex);
}
else
{
// Actions for other columns...
}
}
}
}