|
I have a combobox populated from a DataTable setting the DispalyMember and Value member properties. I want to set the selectedText to a text value i get from a table in a database which is one of the values of my Displaymembers in the comboBox?
|
|
|
|
|
Programmatically set it. After setting your data source and binding your control, you can set the SelectedIndex to 0 or whatever index you want (based on where your would-be text is stored in the DataTable ). This also depends on the DropDownStyle for the ComboBox . For the default - ComboBoxStyle.DropDown - SelectedText is only text that is selected - it does not necessary represent text in the ComboBox as an item. For example, if you typed some arbitrary text in your ComboBox and selected it, that would be the SelectedText . If you only want choices available to the user that are in your DataTable , then you should set ComboBox.DropDownStyle to ComboBoxStyle.DropDownList .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for the reply very useful as i was wondering whate the difference between selected text and selected item. I finally solved my problem by using the find FindExactText method for my dropdown list.
|
|
|
|
|
If you were wondering what the difference was, you should've read the property documentation for ComboBox.SelectedItem and ComboBox.SelectedText in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear All,
I'm newer to C#. Now I plan to write a program to export dataset to excel file. I found that I could export the data cell by cell. But it is not efficient and the exporting progress is very slow because my data is huge.So I want to know if there is other efficient way to do so. Thanks.
Sincerely,
Jim
|
|
|
|
|
You might want to check this[^] article on MSDN. I think your best bet IS you go through and add each cell through code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for your reply. I follow the step and use writexml method to export dataset to xml file.But unfortunately my data are too huge.So when I open the xml file, it waste me about one hour to complete opening the file by Excel.Could you tell me another way to expoert?Thanks.
Sincerely,
Jim
|
|
|
|
|
I just did! And it didn't have anything to do with XML!
Read my previous post, and click on the link. You'll find the code to do what you want. If you really want to compare methods for speed here[^] is another document that covers a number of different methods for getting data into Excel. But, using the Automation method is the most direct, so it's going to be the fastest, no matter which file method you choose...
If you have this huge amount of data (I hope it FITS into an Excel sheet!), why would you want to read this data from a file, reformat it and write it back out, then have Excel read it again? Seems like your doing 3x the file work compared to reading the data once and parsing and plugging the data directly into the worksheet.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for your reply again. In my situation I have to transfer the data out from SQL server,but the users in my office don't understand the SQL syntax.They only want to deal with excel file.So I have to write a program to faciliate thier work and export the data to excel.However, thanks for your replay and it really helps me lots.
Sincerely,
JIm
|
|
|
|
|
Hi,
I need to highlight the ListViewItem during dragOver operation. Since C# does not seem to be support this feature, I am acheiving the same by changing the BackColor and ForeColor as follows:
if (highlight){
listViewItem.SubItems[0].BackColor = Color.Navy;
listViewItem.SubItems[0].ForeColor = Color.White;
}
else {
listViewItem.SubItems[0].BackColor = Color.White;
listViewItem.SubItems[0].ForeColor = Color.Black;
}
This causes the entire listView to refresh making it look very ugly. I tried to control the refresh by invalidating only the listViewItem as follows.
listView.Invalidate(listViewItem.GetBounds(ItemBoundsPortion.Label));
But this too did not help. Also, the listViewItem is getting higlighted more than the Text area. It seems to be higlighting the Column's width.
Any thoughts on how I can acheive the highlighting in a better fashion?
Thanks.
Kiran
|
|
|
|
|
Kiran Kamath wrote:
Any thoughts on how I can acheive the highlighting in a better fashion?
Just select it. You would already have the ListViewItem so set its Selected property to true . After it's dropped, you can set that property to false .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I did not want to highlight by selecting the item, as on "Selection" I perform host of other actions. But I guess this is the only way to avoid the flickering of the ListView. Thanks for the reply.
Regards,
Kiran
|
|
|
|
|
I am using a remoting program in which i have a server and a client. I want the client's computer name and ip at the server. How can i get it in c# .net 2003.
Please explain...
Rahul
|
|
|
|
|
Environment.UserName to get the user name of the client, you could get the IP address of the client using something like System.Net.Dns.GetHostByName(Dns.GetHostName()).AddressList[0]
#include "witty_sig.h"
|
|
|
|
|
The simplest way would be to have the clinet send it own Machine Name and IP address(es). Or the client could send its own Machine Name and the server works out the list of addresses for the client using System.Net.Dns.GetHostByName(clientMachineName) .
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Do you know how can I make DefaultButton in C# as in MFC?
Thankx
Wizard_01
|
|
|
|
|
Simply juust set the AcceptButton propoert of your form to your button name.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Hi Judah
Thanks for the reply.
I can do all of that, that is not a problem.
The problem arises when multiple fonts are selected such as..
Font one font two font three
and all of this is selected.
There is no font object for the selection in that case so it is impossible to modify the bold (or other attribute) property without changing the selection to a common font.
If you go into word for example, you can type in multiple words in multiple fonts.
Then when you select the multiple words, the font dropdown goes blank (as it should).
You can still click on the bold button and all your selection will change to bold (or from bold) without modifying the fonts of the selected words.
|
|
|
|
|
Ah I see your problem then. I'll bet you can P/Invoke this one somehow - ask Heath, he should be able to help you better than I can.
Otherwise, yeah you could go character by character through the selected text, find the different fonts, and set the bold property on each, but that would be a big pain the ass to do. Sorry I can't help you more.
#include "witty_sig.h"
|
|
|
|
|
Hi Judah
Judah Himango wrote:
I'll bet you can P/Invoke this one somehow
Hadnt thought of this.
Was thinking of subclassing the RichTextBox and adding the props back in using regex as a back end.
Judah Himango wrote:
Sorry I can't help you more.
Thats fine, thanks for trying
Cheers
JB
|
|
|
|
|
now,i want to contorl the checkbox of the application(c#),
in vc++ ,i send the message to BM_SETCHECK message to the c# application,
but the C# application is not respond the message BM_SETCHECK,
so that ,how can i get it?
Thanks!
just do it!
|
|
|
|
|
How do you check the meaage? See Application.AddMessageFilter() method in MSDN and use the technique in it for controling the message. I think that should be work but not sure.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
thanks Mazdak.
i want to control the check box of a c# application,
by that way ,send a message from C++ to C#.
if i send BM_SETCHECK message from MFC to MFC,it's right,
but from MFC to C#,it's wrong,
why?
just do it!
|
|
|
|
|
I think thats because C# handle then automaticlly and if you want to access them you should do the thing that I told you in my first reply.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
thanks Mazdak,
but i have no source code of the C# application,hehe.
it's really a question.
just do it!
|
|
|
|