I'm very new to C# programming, so am hoping this is something simple that I'm overlooking.
I have a XtraGrid.GridControl on my form which I want to apply a CustomRowFilter against.
I am not explicitly defining any views for the grid, so I thought I'd be adding my CustomRowFilter method to an event handler against the MainView on my GridControl - however I can't find how to access the event I'm after?
Is this the right approach or am going about this the wrong way?
private void gridControl1_CustomRowFilter(object sender, RowFilterEventArgs e)
{
GridView view = sender as GridView;
DataView dv = view.DataSource as DataView;
if (1==1) //Temp - this should hide everything
{
e.Visible = false;
e.Handled = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
//Bind the datasource etc...
gridControl1.MainView.CustomRowFilter += gridControl1_CustomRowFilter //"Base view does not contain a definition for "CustomRowFilter"
}
The CustomRowFilter event belongs to the GridView and not to GridControl, You can access the event with :
private void Form1_Load(object sender, EventArgs e)
{
(gridControl1.MainView as GridView).CustomRowFilter += gridControl1_CustomRowFilter;
}
Related
private void OnDoubleClick(object sender, MouseButtonEventArgs e)
{
DataGrid dataGrid = (DataGrid)sender;
DataRowView row_selected = dataGrid.SelectedItem as DataRowView;
var s = row_selected["Nome"].ToString();
MessageBox.Show(s);
}
I'm trying to make a cell value message box when selected
I don't know what exactly you want to achive but I assume that your trying to pop a message box on double click on selected value on the grid view.
This is done by DataGridView Event.
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
}
Then you can use the DataGridViewCell.Value Property to retrieve the value stored in a particular cell.
MessageBox.Show(dataGridView1.SelectedCells[0].Value.ToString());
So the final code would look like this.
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
MessageBox.Show(dataGridView1.SelectedCells[0].Value.ToString());
}
NOTE change the Gridview name as you datagrid name
I am having some difficulty getting a form to refresh when another form is closed. This is what I have so far, but it doesn't seem to trigger the refresh. I am very to new to programming, so any assistance is appreciated!
private void button2_Click(object sender, EventArgs e)
{
AddNewCourse ANCform = new AddNewCourse();
ANCform.FormClosing += new FormClosingEventHandler(this.ANC_FormClosing);
ANCform.Show();
}
private void ANC_FormClosing(object sender, FormClosingEventArgs e)
{
this.Refresh();
}
Rebind the datasource of your DataGridView in ANC_FormClosing
For example, if I were rebinding using a method that fetches data, I might write
private void ANC_FormClosing(object sender, FormClosingEventArgs e)
{
DataGridView.DataSource = GetFromDB();
}
This refreshes the grid with new data fresh from the DB
I have a DX grid view and it has 2 bool columns. My purpose is when I check for ex 2nd row in column1, column2 2nd must be changed immediatly, but not. It changes after clicking another row. Here is my rowcellvaluechanged event code :
void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
//button1.PerformClick();
if (e.Column.Name == "col1")
{
var x = gridView1.GetRowCellValue(e.RowHandler, col1);
gridView1.SetRowCellValue(e.RowHandler, col2, x);
}
}
I looked for in DX website and there is no solution. How can I handle on it ?
You can use the GridView.PostEditor method to immediately pass the changed value from the editor into the Grid's underlying data source. The best place for doing this is the EditValueChanged event of real cell editor. You can handle this event as follows:
gridView1.PopulateColumns();
var checkEdit = gridView1.Columns["Value1"].RealColumnEdit as RepositoryItemCheckEdit;
checkEdit.EditValueChanged += checkEdit_EditValueChanged;
//...
void checkEdit_EditValueChanged(object sender, EventArgs e) {
gridView1.PostEditor();
}
Then you can implement all needed dependencies:
gridView1.CellValueChanged += gridView1_CellValueChanged;
//...
void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) {
if(e.Column.FieldName == "Value1")
gridView1.SetRowCellValue(e.RowHandle, gridView1.Columns["Value2"], e.Value);
}
The Grid posts an editor value when you switch to another cell. To force it, call the PostEditor method. But, in this case, you will need to use the EditValueChanged event of the active editor. To get it, use the ActiveEditor property. To catch the moment, when an editor is created, use the ShownEditor event.
gridView1.ShownEditor += gridView1_ShownEditor;
private void gridView1_ShownEditor(object sender, EventArgs e) {
GridView view = (GridView)sender;
view.ActiveEditor.EditValueChanged += editor_EditValueChanged;
}
private void editor_EditValueChanged(object sender, EventArgs e) {
if (!gridView1.FocusedColumn.Name == "col1")
return;
gridView1.PostEditor();
var x = gridView1.GetRowCellValue(e.RowHandler, col1);
gridView1.SetRowCellValue(e.RowHandler, col2, x);
}
I have a datagridview (dataGridView1) pulling information out of a mdb datasource called rentBindingSource, how can I pull information out of hireBindingSource on a button click i.e.
private void viewHire_Click(object sender, EventArgs e)
{
// refresh datagrid view to load stuff from hireBindingSource
}
Try this:
private void viewHire_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = hireBindingSource;
}
Is there any way to prevent changing the selected item in a ComboBox only if for certain conditions? I want to allow update the selected item's displayValue in the ComboBox. But I don't want user to change the selected item when it's being updated. This is a windows application.
Inside your class:
private int _selectedIndex = 0;
Inside your form load method:
comboBox1.Enter += new EventHandler(comboBox1_Enter);
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
Then the rest of the code:
protected void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
if (true) { // Add your validation or certain condition here.
(sender as ComboBox).SelectedIndex = _selectedIndex;
}
}
protected void comboBox1_Enter(object sender, EventArgs e) {
_selectedIndex = (sender as ComboBox).SelectedIndex;
}
Try setting set the Enabled property to false. (Or some third-party toolkits like Telerik have a ComboBox with a ReadOnly property.)