Skip to content

Replies

0
Amiram Korach
Amiram Korach answered on Mar 15, 2009 12:14 PM

Attached

0
Amiram Korach
Amiram Korach answered on Jan 13, 2009 12:31 PM

Each row has a property named "Selected".

Active row is the row that has the input focus, hence there is only one active row. Selected row is a row that was selected by the user or by code and there could be more than one.

If you want to get all selected rows use grid.Selected.Rows

If you want to select all rows, don't go over them and set Selected = true because this can be very slow, but use grid.Selected.Rows.AddRange(grid.Rows)

0
Amiram Korach
Amiram Korach answered on Jan 5, 2009 2:52 PM

ValueChanged is fired only when the user changes the value, not when you bind and the binding changes the value.

We already solved the problem like that:

public

partial class MyComboEditor : UltraComboEditor

{

/// <summary>

/// Occurs when the value is about to be changed

/// </summary>public event EventHandler<CancelNewEventArgs> ValueChanging;

/// <summary>

/// Holds the previous value in order to allow rollback

/// </summary>protected object m_OldValue;

private bool m_SkipValueChanging;public MyComboEditor()

{

InitializeComponent();

m_OldValue = null;

}

/// <summary>

/// Rollbacks the value changing if ValueChanging was cancelled

/// </summary>

/// <param name="args"></param>protected override void OnValueChanged(EventArgs args)

{

if (!m_SkipValueChanging)

{

CancelNewEventArgs e = new CancelNewEventArgs();

OnValueChanging(e);

if (e.Cancelled)

{

m_SkipValueChanging = true;

if (m_OldValue == null)this.SelectedItem = null;

else

Value = m_OldValue;

m_SkipValueChanging = false;

}

}

base.OnValueChanged(args);

}

protected virtual void OnValueChanging(CancelNewEventArgs args)

{

if (ValueChanging != null)

{

ValueChanging(this, args);

}

}

public override object Value

{

get

{

return base.Value;

}

set

{

base.Value = value;

m_OldValue = Value;

}

}

}

0
Amiram Korach
Amiram Korach answered on Dec 27, 2008 4:12 PM

That's make sense, since you can't select text unless you're in edit mode. You can get into edit mode grid.PerformAction(EnterEditMode).

0
Amiram Korach
Amiram Korach answered on Dec 25, 2008 1:42 PM

My code still has a problem. If the control is bound, the OldValue should get the value of "Value", but ValueChanged is not fired as a result of binding change, so you always get a null value if you cancel the change. I'm using the combo editor inside a UserControl so I have a property that explicitly sets the Value property, but whoever want to use this need to fix it.

0
Amiram Korach
Amiram Korach answered on Dec 25, 2008 8:34 AM

I can cache the old value and make my own ValueChanging event like that: (sample attached)

public event EventHandler<CancelNewEventArgs> ValueChanging;

protected object oldValue;

private bool skipValueChanging;

protected override void OnValueChanged(EventArgs args)

{

if (!skipValueChanging)

{

CancelNewEventArgs e = new CancelNewEventArgs();

OnValueChanging(e);

if (e.Cancelled)

{

skipValueChanging = true;

 

if (oldValue == null)

this.SelectedItem = null;

else

 

Value = oldValue;

 

skipValueChanging = false;

}

}

oldValue = Value;

base.OnValueChanged(args);

}

protected virtual void OnValueChanging(CancelNewEventArgs args)

{

if (ValueChanging != null)

{

ValueChanging(this, args);

}

}

ComboEditorRollback

0
Amiram Korach
Amiram Korach answered on Dec 24, 2008 3:29 PM

What is the event that I should use? The control is bound so I need an event which when it happen the value in the data is different than the control value.