|
Hi,
I've got a combobox to which I add objects.
I would like to have one specifiec object selected.
Some of the objects contain the same DisplayMember but differ in other aspects = index.
When the objects that do not have dublicates are selected there is no problem in selecting correct item as selected, but when the object has DisplayMember dublicates the first displayed items is always selected no matter what SelectedIndex or SelectedItem is assigned.
Any tip?
ToDo
|
|
|
|
|
I looked at DisplayMember under the ComboBox entry in MSDN for VS2005 and there was an example program (for ListBoxes) which I subtley changed to be a ComboBox. I also modified the sample data to contain duplicate DisplayMember values. It seems to work perfectly as far as I can tell, but maybe I am missing your point?
Just copy and paste all this code into a WindowsApplication.
HTH - Des
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
//private ListBox ListBox1 = new ListBox(); // Just for our test
private ComboBox ListBox1 = new ComboBox();
private TextBox textBox1 = new TextBox();
public Form1()
{
this.ClientSize = new Size(292, 181);
this.Text = "ListBox Sample3";
ListBox1.Location = new Point(24, 16);
ListBox1.Name = "ListBox1";
ListBox1.Size = new Size(232, 130);
textBox1.Location = new Point(24, 160);
textBox1.Name = "textBox1";
textBox1.Size = new Size(240, 24);
this.Controls.AddRange(new Control[] { ListBox1, textBox1 });
// Populates the list box using DataSource.
// DisplayMember is used to display just the long name of each state.
ArrayList USStates = new ArrayList();
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(new USState("Washington", "W1")); // Duplicate DisplayMember
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI")); // Duplicate DisplayMember
USStates.Add(new USState("Wisconsin", "W1"));
USStates.Add(new USState("Wyoming", "WY"));
ListBox1.SelectedValueChanged += new EventHandler(ListBox1_SelectedValueChanged);
ListBox1.DataSource = USStates;
ListBox1.DisplayMember = "LongName";
ListBox1.ValueMember = "ShortName";
}
private void ListBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (ListBox1.SelectedIndex != -1)
textBox1.Text = ListBox1.SelectedValue.ToString();
}
}
public class USState
{
private string myShortName;
private string myLongName;
public USState(string strLongName, string strShortName)
{
this.myShortName = strShortName;
this.myLongName = strLongName;
}
public string ShortName
{
get
{
return myShortName;
}
}
public string LongName
{
get
{
return myLongName;
}
}
public override string ToString()
{
return this.ShortName + " - " + this.LongName;
}
}
}
|
|
|
|
|
Hi,
thanks for the reply.
Try chaning this code part, I get the the first Washington selected.
// Populates the list box using DataSource.
// DisplayMember is used to display just the long name of each state.
ArrayList USStates = new ArrayList();
USState defaultSelection = new USState("Washington", "W1"); //New
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(defaultSelection); // Duplicate DisplayMember //Changed
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI")); // Duplicate DisplayMember
USStates.Add(new USState("Wisconsin", "W1"));
USStates.Add(new USState("Wyoming", "WY"));
ListBox1.SelectedValueChanged += new EventHandler(ListBox1_SelectedValueChanged);
ListBox1.DataSource = USStates;
ListBox1.DisplayMember = "LongName";
ListBox1.ValueMember = "ShortName";
ListBox1.SelectedItem = defaultSelection; //New
Regards,
ToDo
|
|
|
|
|
Now I see what you mean, I originally thought that no matter which of the duplicates you selected, you were only getting the object mapped to the first duplicate returned, but I think what you are saying is that when you go to the ComboBox, the selected object is the first of the duplicates in the list.
I haven't a way around this yet, but at least I now understand the problem.
|
|
|
|
|
Hello,
I'm new to .net 2.0 and have the following problem:
I have multiple tables in a MSSQL database.
I use DataGridViews to display or enter Data to this tables
Visual Studio has put some things automatically in:
DataSet<->BindingSource<->BindingNavigator<->TableAdapter<->DataGridView
I have the problem to find a starting point for doing something. I have added after
InitializeComponent();
a few lines to display the table.
try<br />
{<br />
this.xyzTableAdapter.Fill(this.testDataSet.xyz);<br />
}<br />
catch (System.Exception ex)<br />
{<br />
System.Windows.Forms.MessageBox.Show(ex.Message);<br />
}<br />
this.xyzDataGridView.Columns[0].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic);<br />
Also I used the SaveItem_Click-event to save the data back to the database
<br />
try<br />
{<br />
this.Validate();<br />
this.xyzBindingSource.EndEdit();<br />
this.xyzTableAdapter.Update(this.testDataSet.xyz);<br />
}<br />
catch (System.Exception ex)<br />
{<br />
MessageBox.Show("Update failed" + ex.ToString());<br />
}<br />
This works, but i don't have a clue if this is the best method of doing this.
That is not the main problem.
What i really want are 2 thing:
I want to combine to tables in one DataFlexGrid.
Example:
One table may be car.
A car could have tires which are in another table.
So table "car" should contain a link to table "tire" as foreign key.
What i want in the DataGridView is a DataGridViewComboBox-column, where a user could just choose the "tire" for the "car" from.
Where I have problems doing this:
I have no starting point.
In the designer i can change the column value to DataGridViewComboBox. But I don't know how to fill the ComboBox (one other thing that i search is how to prefil cells if a new row is added, e.g. adding a new DateTime).
Selects could be written easy (Like SELECT car.carID, car.name, tire.name FROM car, tire WHERE car.tireID = tire.tireID or for the Combobox SELECT tire.name, tire.tireID FROM tire), but I don't know where to put these to.
The second problem would be the other was round: How could i alter the insert so that the tireID would be written to the car table?
Under DataSource "Edit DataSet with Designer" I could enter additional Insert Statements to the tableAdapter. But i have no clue how to use them. Whatever I do, they seem to be ignored.
Can anybody help? If there exists something like a tutorial or HowTo it would also help.
Regards
Wolfgang Schmidt
-- modified at 16:20 Thursday 23rd November, 2006
|
|
|
|
|
Have you found a solution to the problem?
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
|
|
|
|
|
Yes, I did not find the data source properties for the dropdown the first time. Wanted to do it manually, but it is also fine using the designer
|
|
|
|
|
hi is there any way to run a batch file from c# application
hello
|
|
|
|
|
Hi,
you can launch all kinds of commands, including opening Word documents, or executing
DOS batch files, using the Process and StartInfo classes.
Put the batch file name into StartInfo.FileName, and optional arguments in StartInfo.Arguments.
Luc Pattyn
|
|
|
|
|
Does anyone have any links to resources that may help me. I've been asked to come up with a proposal for an intercom type system, LAN based only.
The problem over normal VOIP is that the voice communication is a simulation of radio traffic, so the users on system may all be on different channels, only when connected to the same channel can they communicate.
To simplify, I'm willing to have a limited number of preset channels which users can join/leave. When two or more people are on the same channel, they can talk to each other in a half-duplex method.
I was thinking about having a "server" machine and using some form of remoting allowing users to call a common Talk() method on a remote instance (thus allowing the blocking others from talking if required).
My questions really are related to the "streaming" of the transmit from the "talker" out to the "listener".
I should have time to do a good implementation, but need to present the posposal at the start of next week!
Any links, ideas would be welcome.
Regards,
Ray
|
|
|
|
|
Convinced there are good products out there! and probabely very cheap
|
|
|
|
|
~~~Johnny~~~ wrote: Convinced there are good products out there! and probabely very cheap
I'd love it if there were... and money isn't that big an object for the right product (it's an important component of an 8 figure project).
The latest spanner added to the design is that listeners need to be able to listen to multiple independant channels at the same time! I'm convinved we'll end up creating the framework but I'd still love an API/library to do the comms/audio side of things!
In the mean time, I'm presenting the solution without going into programming/implementation specifics -- since that is actually inappropriate at this early stage of my project!
Regards,
Ray
|
|
|
|
|
hi
Is there any way that we could shut down and restart our system through our c# applicaiotn ? thanks in advance
hello
|
|
|
|
|
Use this :-
System.Diagnostics.Process.Start("Shutdown", "-s ");
To know more about other command write shoutdown /? at command prompt.
Regards,
Bhupi Bhai.
|
|
|
|
|
Thanks
but this code goes into abnormal execution ,, forms statrs opening countless
so amazing ,, why is that? i am using dont net v 2
thanks in advance
hello
|
|
|
|
|
It can probably be done through API calls. I know their are methods that allow you to show the ShutDownDialog. Try looking for API Guide and API Viewer on Google, and look through their listing of API commands.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Hi all
I have a c# application which sends a singnal through com port on some device attatched on the local system com port , every thing goes ok when i run this application from the local system (workgroup)and i can send and receive singal from local system's com port,, but the problem is that when i run this application on a system which is client of a central server(win2003 server) , it doesnot detect device on its local com port it searches device on the com port of server computer and because there is no device on the com port of remote server so my application does not work , thoug it is network isuue ,, but any idea > what to do ?
thanks in advance
hello
|
|
|
|
|
What do you mean by "on a system which is client of a central server"? Are you saying that this local machine is running a Terminal Server instance on the Win2K3 box? If so, this arrangement won't work since your actually running the application on the server, not the local workstation.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
yes its an instance ,, but there is also a RFID card(ps2)attatched ,, but this machine detects this and respond,, so why it cant detece its local com port ?
i thing i am wrong not cleared with the concept somewhere plz help me
thanks in advance
hello
|
|
|
|
|
Terminal Services run an instance of a workstation on the SERVER, not the local workstation. The local workstation just shows you the display of the remote Windows session. The TS Session will NOT interact with the local machines hardware devices. It's just like your keyboard and mouse are connected to the server itself.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi friends, am trying to build an interface for web service using http post method. Actually i have little knowledge about making this. I had done xml connectivity using post method and i know that. But i little idea about making the interface 4 web service. Please help me by sending any suggetions, example urls or example projects.
Thank u
|
|
|
|
|
|
Hi Ganesh, This nithin, thank u 4 sending this urls and much helpful for me.
One request is that these r all refers web service using SOAP method, can u guide me how to make an interface which can access using HTTP Post method.
Thanks,
Rgds
Nithin
-- modified at 0:23 Wednesday 29th November, 2006
|
|
|
|
|
Hi, here is my scenario...
i have the following in my solution...
App1 - normal application
App2 - normal application
CoreApp - library containing classes and 'core' functionality
App1 and App2 talk to each other via their sql server databases.
now, sometimes app1 and app2 may be installed on the same server, sometimes they are not.
so, if they are installed on the same box there will be a connection string to the other apps db in their web.config file.
if the connection string does not exist then i must call the other apps web service which will perform the db insert for me.
i made an interface, lets says its called IComms
it defines the method signature that allows app1 to put something in app2s database.
so to send a message i write this code in App2..
<br />
<br />
dim proxy as IComms<br />
'see if we have connection string for app1 database<br />
<br />
if getConfigSetting("App1ConnectionString").length = 0 then<br />
'use web service<br />
proxy = new app1.webservice<br />
else<br />
proxy = new CoreApp.dbCalls<br />
end if<br />
<br />
proxy.sendmessageToApp1("hello")
this is all very well, but the reference to app1s web service in app2 does not create an implementation of the interface on the proxy class.
is there any way round this or should i just design the app without the use of an interface?
---Guy H ( ---
|
|
|
|
|
hi,
when sending mails using SmtpClient, does it open connection each time I do .Send()
if yes how can i avoid it?
If no what is the mechanism used to send Email.
cheers
------------------------------
Its not the fall that kills you; it's the
sudden stop at the end.
|
|
|
|
|