How to get EditValue which is unique and Binded using DataSource ValueMember with RepositoryItemLookUpEdit in gridColumn and on changing value fill the other fields retrieved from database.
You can handle the RepositoryItemLookUpEdit's EditValueChanged event, in which you can obtain the current editor's value
private void repositoryItemLookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
object value = (sender as LookUpEdit).EditValue;
/// your code here
}
Related
I have gridcontrol that has a RepositoryLookupEdit in one of the columns. I can get the value of RepositoryLookupEdit after changed, but I dont know how to get the which row's RepositoryLookupEdit value changed. How can I get the Row ID?
With the code below, I can get the RepositoryLookupEdit value.
private void repositoryItemLookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
LookUpEdit edit = sender as LookUpEdit;
var row = edit.Properties.GetDataSourceRowByKeyValue(edit.EditValue);
}
Since repositoryItemLookUpEdit isn't restricted to GridControls you cannot get the row handle from this event. You however have other possibilities.
First, if the edit is done by the user, you can use the ColumnView.GetFocusedRow() method to get the current grid row.
If however the edit value is changed via code it will also be changed in the grid so you can now use the ColumnView.CellValueChanged event.
private void repositoryItemLookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
LookUpEdit edit = sender as LookUpEdit;
var row = edit.Properties.GetDataSourceRowByKeyValue(edit.EditValue);
gridRow = gridView.GetFocusedRow() as MyDataRow
}
In my application, I give the user the option to search the database. When they click edit, I want the GridView to only show the row they are updating by storing its ID.
I'm trying the following code, but it is not returning anything other than the Control.
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
string value = GridView1.Rows[e.NewEditIndex].Cells[3].ToString();
}
Any ideas on how to store the value that I'm looking for?
Use the cell's Text property
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
string value = GridView1.Rows[e.NewEditIndex].Cells[3].Text;
// or
string value = GridView1.Rows[e.NewEditIndex].Cells[3].Value;
}
Or If you have declared the control as <TemplateField> for which you are trying to get the value for then try
string value = ""
Label lblID = (Label)GridView1.Rows[e.NewEditIndex].FindControl("lblID");
value = lblID.Text;
Another alternative would be to add DataKeyNames="ID" for the gridview which you can retrieve using
// assuming that the value of your datakey is numeric value
long Id = long.Parse(GridView1.DataKeys[e.NewEditIndex].Values["ID"].ToString());
Note you can add multiple comma separated values to DataKeyNames property.
I have DataGridView to load some data programmatically. After inserting my data I am showing the DataGridView . Here by default the 1st row 0th column cell is selected. But I don't need that. I have tried to disable that option.
datagridviewname.currentcell=null
But it will not work. Any body can help me to solve my problem.
Set CurrentCell Selected property to False like:
dataGridViewName.CurrentCell.Selected = false;
On the DataGridView create an event for DataBindingComplete then add this method datagridview1.ClearSelection()
private void datagridview1_DataBindingComplete(object sender, EventArgs e)
{
datagridview1.ClearSelection();
}
Why u set it null? It should be like following. I think it will work
dataGridViewName.Rows[0].Cells[0].Selected = false;
if it is 1st row 0th, then
dataGridViewName.Rows[1].Cells[0].Selected = false;
The only way is this:
private void dataGridView_SelectionChanged(object sender, EventArgs e)
{
dataGridView.ClearSelection();
}
You should perform clear selection inside form load event of the form instead of constructor.
private void Form1_Load(object sender, EventArgs e)
{
// You will get selectedCells count 1 here
DataGridViewSelectedCellCollection selectedCells = dataGridView.SelectedCells;
// Call clearSelection
dataGridView.ClearSelection();
// Now You will get selectedCells count 0 here
selectedCells = dataGridViewSchedule.SelectedCells;
}
MSDN
You can set this property to null to temporarily remove the focus rectangle, but when the control receives focus and the value of this property is null, it is automatically set to the value of the FirstDisplayedCell property.
So looks like setting it to null only works if it wasn't the first row first column cell.
I'm working with radGridView and I'm building the data assigned to it, I mean I'm creating the columns and the rows (not assigning to datasource). After adding the data to the grid I add a checkbox column that should be used to check multi rows (same as muti-select idea but using checkboxcolumn),
so this column is not bind to any data, its value should be assigned during runtime.
When I try to retrieve this checkbox column value it turned out to be null even if it's checked, I used this method to update its value, but it didn't work out:
private void radGridView1_ValueChanged(object sender, EventArgs e)
{
if(radGridView1.CurrentCell!=null)
if(radGridView1.CurrentCell.ColumnInfo is GridViewCheckBoxColumn)
radGridView1.TableElement.Update(GridUINotifyAction.DataChanged);
}
What should I do to get the value of the checkbox column not on valueChanged but on another button click?
I am not sure how you are getting null value, however, in my tests the check boxes always have values if they are assigned:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
radGridView1.Columns.Add(new GridViewCheckBoxColumn() { Name = "CheckBoxCol" });
radGridView1.Rows.Add(false);
radGridView1.Rows.Add(true);
radGridView1.Rows.Add(false);
radGridView1.Rows.Add(true);
}
private void button1_Click(object sender, EventArgs e)
{
foreach (GridViewRowInfo row in radGridView1.Rows)
{
Console.WriteLine(row.Cells["CheckBoxCol"].Value);
}
}
}
Can you please provide a small sample and information how to reproduce the issue?
I try to use combobox in winforms project.
Here is my code:
private void ShowContoursForm_Load(object sender, EventArgs e)
{
cbxSelectShape.DisplayMember = dataSetObject.ObjectShapes.ShapeNameColumn.ColumnName;
cbxSelectShape.ValueMember = dataSetObject.ObjectShapes.ShapeIDColumn.ColumnName;
cbxSelectShape.DataSource = dataSetObject.ObjectShapes;
}
private void cbxSelectShape_SelectedValueChanged(object sender, EventArgs e)
{
var id= (int)cbxSelectShape.SelectValue;
}
When I choose item from ComboBox SelectedValueChanged is fired,and id variable gets null.
I need to get value of selected item but I always get null in id variable.
Any idea why do I get wrong result and how to fix this code?
You can get the index of ComboBox this way:
private void cbxSelectShape_SelectedValueChanged(object sender, EventArgs e)
{
var id= ((ComboBox)sender).SelectedIndex;
}
You should use SelectedValue property of combobox to get value, associated with ValueMember (ShapeID in your case):
var id = ((ComboBox)sender).SelectedValue;
SelectedIndex returns index of item selected in combobox. Also if this handler used for one combobox, you don't need to cast sender - simply use your combobox variable:
var id = cbxSelectShape.SelectedValue;