Hello,
please have a look at the follwing scenario:
*I have a DataGridView to show a list of DataRows (bound to a DataSource).
*Some Textboxes ans other controls show the current-selected row.
The Problem: If there is NO DataRow in the DataSource, or none is
selected the Textboxes are enabled! Users could think of inserting
text, even if there is no row.
How could I bind the Enabled/Disabled property of controls to "is a row selected /is there a bindingsource.current "
thank you!!

Enable/Disable Textbox on Current-BindingSource-Item
matt_uk
Did you create a HasRowsChanged method If you don't provide change notification then the databinding won't read the property again.
-mark
Program Manager
Microsoft
This post is provided "as-is"
Thomas82
the help file is wonderful. . .
BindingSource.Current Property
BindingSource.CurrentItemChanged Event
BindingSource.DataSourceChanged Event
Gordon Hogenson
Is there any possible solution for this
I did not find any, yet.
Please help me on this one!
thank you!
brunic
Check out the docs: http://msdn2.microsoft.com/en-us/library/xz45s2bh.aspx and http://msdn2.microsoft.com/en-us/library/ms229615.aspx
-mark
Program Manager
Microsoft
This post is provided "as-is"
Mubarak
i created the following class:
class myBindingSource : BindingSource
{
public object mxtest = false;
public EventHandler testChanged;
public object test
{
get
{
return mxtest;
}
set
{
if (test != value)
{
mxtest = Convert.ToBoolean(value);
OntestChanged();
}
}
}
private void OntestChanged()
{
if (testChanged != null)
{
testChanged(this, new EventArgs());
}
}
}
Mehfuz Hossain
Instinct was telling me that you could do this -
add a property "HasRows" to your form where it returns true if the datasource is not null and the datsource has rows
in your constructor add -
myTextBox.DataBindings.Add("Enabled", this, "HasRows");
I tried it, though, and it doesn't work. Typically, I wouldn't post a non-working response, but I think it needs to be explained why this doesn't work.
shajahan
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.DataBindings.Add("Enabled", this, "HasRows");
}
public bool HasRows
{
get { return fooBindingSource.Count > 0; }
}
private void button1_Click(object sender, EventArgs e)
{
fooBindingSource.Add(new foo());
}
private void button2_Click(object sender, EventArgs e)
{
fooBindingSource.Remove(fooBindingSource.Current);
}
}
public class foo
{
int _i = 0;
public int I
{
get { return _i; }
set { _i = value; }
}
}
but I think back to the original poster's question, it isn't as simple as handling it via an event (one line of code vs. a property, a method, and a DataBindings.Add statement)
Lakshan Fernando
thank you for your answers!
as far as i can see, all of that means, I can bind to a property. But there has to be a changed event.
but in that case i have to write one for bindingsource.current. how is that possible
Blair, ok, this might be a bit oversized for my sample, but i think something generic could be implemented. extending the bindingsource-class or whatever.
This situation (described in the first post) is very often in my application. So i dont want to implement the same events for every bindingsource.
thank you for any further tips!
Richard Grant
thank you for your answer.
But thats not what I am looking for.
I tought of something like "bind" this property to something. Not set it in some event(s).
perhaps there is a way to do this like that
thank you.
sachin.pithode
"Cannot bind to property or column test on DataSource.
Parametername: dataMember"