|
i have a function that populates a combobox from a database and returns a table that i set as the datasource for the combobox, then a user select a value and on the Selection change event i populate another combobox based on the selected value, but the first combobox needs to have blank text so as the user is fprced to select a value from the first combobox but as i am populating the first combobox in the windows form LOAD it show the text of the first record from the database ie the first row of the table returned how can i add a blank row to my table and still populate the first combobox??
|
|
|
|
|
After you assign the DataSource property, do something like:
comboBox1.Items.Insert(0, string.Empty);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
a big thank you i will try after the easter break
|
|
|
|
|
private void LScheme()
{
Customer c = new DGIBO.Customer();
DataTable list = c.getSchemes();
ddlScheme.Items.Insert(0, string.Empty);
this.ddlScheme.DataSource = list;
this.ddlScheme.DisplayMember = "SchemeName";
this.ddlScheme.ValueMember = "PhaseName";
tried my example above and it does not work, tried putting your code after datasource and got an error because the databind
|
|
|
|
|
Inserting before data binding won't work, of course, because when you data bind the control all the data-bound properties - like Items - are cleared.
The example I gave would still change the underlying data source, so you need to make sure that the data you're adding to the Items collection property doesn't violate any constraints (like a null key) in the DataTable .
Note, this isn't the case with ASP.NET and data-bound controls.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have a ClassA (extends Component) with some properties.
I have a ClassB (extends CollectionBase) that implements collection of ClassA objects.
In my main app, I use a ClassB collection, add some ClassA objects to it, and databind a property X of ClassA to a textbox:
textBox.DataBindings.Add("Text", ClassBCcollection, "PropertyX");
This works well, changes in the textbox are reflected in the collection.
EXCEPT when at startup the ClassB collection is empty, then databinding does not work.
So; databinding works when databindings are set after collection is filled with items; databinding does not work when databindings are set when collection is empty.
Do I miss something...?
Thanks!
|
|
|
|
|
lustuyck wrote:
Do I miss something...?
Nope. The reason is you read deep into the data-binding topics is because when you use a CurrencyManager to bind against a collection of unknown object types, the collection or list must contain all the same type (or base types that must come before their derivative types) and contain at least one of those types for the data-binding mechanism to discover the Type information correctly.
Even if you use typed parameters and return values, this still won't help since it uses the IList interface, which always returns and accepts the Object type. An object must be present in order to discover the actual Type information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, thanks for the answer.
What I do now as a 'workaround', is wait until an item is added to the collection the first time; and when that happens I add the databindings (only once).
It works now, but I don't know if this is common practice. Are there better ways to do something like this?
Kind regard,
Ludwig
|
|
|
|
|
Yes, but it's not simple. You need to extend the CurrencyManager class and override GetItemProperties to return the properties of the Type. You can do this simply by returning something like the following:
public override PropertyDescriptorCollection GetItemProperties()
{
return TypeDescriptor.GetProperties(typeof(MyClass), new Attribute[] {
new BindableAttribute(true) });
} Then, extend the Control classes that you want to data-bind and override the BindingContext property, return an instance of a derivative BindingContext that you must create. In your derivative class, override Add and when the BindingManagerBase is of type CurrencyManager , add your CurrencyManager derivative by calling base.Add with your type (which should copy information from the BindingManagerBase if available).
This should work, though it's untested.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a way to preview a report as you build it? I know you can do the viewer to show it at runtime but i was wanting to preview what it would look like as i'm building so i don't have constantly make changes to get it exactly how i want it to look.
thanks
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
win32newb wrote:
Is there a way to preview a report as you build it? I know you can do the viewer to show it at runtime but i was wanting to preview what it would look like as i'm building so i don't have constantly make changes to get it exactly how i want it to look.
thanks
I don't believe so. I think you need the full version to be able to preview during design mode.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
Thanks for the reply. I guess it's like everything else its all about the money. I just figured since i paid the ungodly price for visual studio .net that EVERYTHING in it would be a full version guess not.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
i do not know how to write out a program that allow to import data from excel files to SQL Server
Help Me.
Thanks
Mr Duc Linh Nguyen
|
|
|
|
|
try to connect to the excel file by using ole connection the read data to a Dataset or you can read data then write it to sql database be using sql conncetion
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
Is this programming question? If you want to do it with SQLServer you can use Import and Export Wizard , follow it and it will do it automaticlly.
Mazy
"I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein
|
|
|
|
|
hai there,
Is it possible to a C# .exe file to contact/communicate/get & pass value to another .exe files (may or maynot created using C# language)?.
except com con:-Dcept.
hai, feel free to contact
Sreejith SS Nair
|
|
|
|
|
You can use TCP Sockets communication between the tow applications to do that
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
hai there,
thnaks for your nice information . See, i have an C# exe file which willl accept one integer value and it will store that value to an xml file. this is oneside. The other side is i want that value from my calculator(windows). How this communication is possible
hai, feel free to contact
Sreejith SS Nair
|
|
|
|
|
Check out the FileSystemWatcher class
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
It's not... not by normal means anyway. The Calc application doesn't expose any kind of communication interface. It doesn't even take command line parameters.
RageInTheMachine9532
|
|
|
|
|
You can P/Invoke the Windows Management APIs and send Windows messages to applications, whether they were written in C/C++, VB, any .NET languages, or practically anything, actually, so long as they use the Windows subsystem. You do this using APIs like FindWindowEx to get an HWND (window handle) to a particular window (you can get the main application handle by enumerating the running processes with Process.GetProcesses then use the Process.MainWindowHandle from each if its a process you want to communicate with). One you get the handle to the control you want (most likely using the Windows class of the window/control), you can use P/Invoke PostMessage or SendMessage to send a Windows message (with the appropriate params) to it.
See the following article for an example and additional links to more information: http://www.codeproject.com/csharp/wmp_pinvoke.asp[^].
Also, read the Platform SDK for more Windows Management API documentation at http://msdn.microsoft.com/library[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm writing a couple of custom controls in the .NET compact framework.
I have two controls, one called "Target" derived from System.Windows.Forms.ContainerControl the other called "Arrow" from System.Windows.Forms.Control. I can successfully add Arrows to the Target's Controls collection.
I have overriden the OnPaint method on both controls and they work correctly as stand-a-long instances. What I want to know is the "correct" way of causing the Paint event of the target to raised the Paint events on each of it's contained arrows.
TIA
Phil
|
|
|
|
|
The WM_PAINT Windows message is not typically sent by an application (unless you want to force immediate repainting). It is send by the window manager (Windows in this case) when a window (which includes controls) needs repainting. If you want to force the child controls to repaint, then call the Refresh() method on the instance of your controls.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
first time
For the people.For the public.
|
|
|
|
|
Yes! CodeProject's posting interface really does work!
RageInTheMachine9532
|
|
|
|