|
Hi sir,
Thanks for your reply.
I am trying to use as u suggested but getting more confused.
Actually i have developed code in VC where i store some values in and store in combo after sorting accordingly.
Here is my complete code wt i am doing
CTest1View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
ResizeParentToFit();
m_mapId["Abc"];
m_mapId["aa"];
}
CTest1View::OnEditchangeCombo1()
{
CString strvalue;
CString strTemp;
m_ctrlCombo.GetWindowText(strvalue);
std::map<CString,CString>::iterator it=m_mapId.begin();
m_ctrlCombo.ResetContent();
for(; it!=m_mapId.end();it++)
{
strTemp = it->first;
if(strTemp.Find(strvalue)==0)
m_ctrlCombo.AddString(strTemp);
}
m_ctrlCombo.SetWindowText(strvalue);
m_ctrlCombo.ShowDropDown();
}
I am trying with C#
Dictionary<string, int> d = new Dictionary<string, int>();
d.Add("aaat", 1);
d.Add("aat", 5);
How can i search in map and get the results back in CCombo.
Thanks
Raj
|
|
|
|
|
raju_shiva wrote: How can i search in map and get the results back in CCombo.
OK. then you could use HashSet with string as a type. This stores unique values and don't need to have key/value pair.
HashSet<string> stringSet = new HashSet<string> { "abc", "aa" };
string[] stringList = new string[stringSet.Count];
stringSet.CopyTo(stringList);
string strValue = "a";
string[] matchedStrings = Array.FindAll(stringList, delegate(string p)
{
return (p.Contains(strValue));
}
Array.Sort(matchedStrings);
cmbValues.Items.Clear();
cmbValues.Items.AddRange(matchedStrings);
cmbValues.SelectedIndex = 0;
});
Hope this gives some idea to you.
Knock out 't' from can't, you can if you think you can.
|
|
|
|
|
Hi sir,
I tried this code but getting an error as
HashSet stringSet = new HashSet { "abc", "aa" };
// "A new expression requires () or [] after type"
Thanks
Raj
|
|
|
|
|
Actually written code was correct, but due to incorrect formatting, it was not visible. The code line should be as below.
HashSet<string> stringSet = new HashSet<string> { "abc", "aa" };
You could check my previous post in FireFox as below.
1. Select the code.
2. Do right click.
3. select "View Selection Source".
Knock out 't' from can't, you can if you think you can.
|
|
|
|
|
Hi sir,
Laxman Auti wrote: HashSet<string> stringSet = new HashSet<string> { "abc", "aa" };
I tried the same ,but stilll the same error
Thanks
Raj
|
|
|
|
|
raju_shiva wrote: I tried the same ,but stilll the same error
Why don't you try something like following?
HashSet<string> hashSet = new HashSet<string>();
hashSet.Add("abc");
hashSet.Add("aa");
Knock out 't' from can't, you can if you think you can.
modified on Monday, July 5, 2010 2:45 PM
|
|
|
|
|
<pre>Dictionary<string,string> m_mapId = new Dictionary<string,string>();
Dictionary<string,string>.Enumerator it = m_mapId.GetEnumerator();</pre>
However, it's unusual to deal with enumerators directly in C# - instead just use a 'foreach' loop, which enumerates for you.
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
-- Modified Wednesday, June 30, 2010 5:36 PM
|
|
|
|
|
David Anton wrote: However, it's unusual to deal with enumerators directly in C# - instead just use a 'foreach' loop, which enumerates for you.
Any example that lets unusual deal of C# enumerators?
Knock out 't' from can't, you can if you think you can.
|
|
|
|
|
A breif outline of what I need to is generated a Word Document (2003 format) by appending a series on single (A5) Word Document templates files.
1. Load the Word template
2. Do a number of search/replace operation (driven by data from another file)
3. Insert at the end of the previous document
4. repeat till last file.
Using word interop is dreadfully slow this and takes at least an hour for 20 pages. So I am considering converting the templates to XML and using OpenXML to do the above. The search/replace could then even be done by treating the XML file in plain text format.
What I can't find is info on how I can then insert one XML file at a bookmark in the previous and of course still have a valid Word XML doco at the finish.
Someone must have done something like this before.
Thanking you in advance.
Happy programming!!
|
|
|
|
|
hello,how are you?
please i need you to help me because i'm new programmer in c#.
if don't mind,i do my code in c++ last year but now i need the same code
in my new program by c# but i'm not very good in c# and i don't know how to do it
so can you help me please because it's really important for my program.
thank you for your cooperation
nice to meet you
|
|
|
|
|
Hello, I'm fine - thanks for asking!
I'm glad to hear you are learning something new; it is always worth doing.
We will help if we can, be sure of it.
You are more than welcome - come again soon!
What a nice chap (or chappette) - isn't it a refreshing change to have a polite, pleasant enquiry here?
PS: There is only one detail you forgot, old chap: What was your question?
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Thank you for your cooperation and i really apprecite your help
tomorrow i'll send you the file of the code
nice to meet you
|
|
|
|
|
No, don't email it to me: post what you are having difficulties with as a question.
If you email it to me, no one else can see, or help, and some of them may have more or better knowledge of your exact area than I do.
Start a new question, and describe your problem. Include short code fragments, using the "code block" widget to preserve formatting - don't just post a whole C++ file and say "I need this in c#" because you will get a lot of abuse from various people if you do! Read the bit at the top of the page, where it says "How to get an answer to your question" before you post it.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Why I can't smell the sense of c++ programmer in you ?
I know nothing , I know nothing ...
|
|
|
|
|
I transfered from C++ to C#
Please say what help you need.
|
|
|
|
|
hello ,
Am tring to use Excel SpreadSheet on the Windows form. The datasource is a datatable. While am giving the datasource as Datatable it is not working . It is asking for MSDATASRC. Any one knows how to convert Data Table to MSDATASRC..
|
|
|
|
|
These are some C# class members:
[StructLayout(LayoutKind.Sequential)]
unsafe struct MyStruct
{
public int size;
public byte* data;
}
[DllImport("MyStruct.dll", CharSet = CharSet.Unicode)]
static extern unsafe void MyFunction(MyStruct* myStructs, unsigned int nMyStructs);
How to create such array of MyStruct in C# as in C to pass it to MyFunction from C#?
unsigned int N = 10;
MyStruct* pMyStructs = (MyStruct*)malloc(N * sizeof(MyStruct));
MyFunction(pMyStructs, N);
Чесноков
|
|
|
|
|
you need to rewrite the MyStruct in C# using the MarshalAs attribute at the vars declaration.
something like above its only a example ^^
you need to take a look at the mapping of your C byte* to C#..
<br />
[StructLayout(LayoutKind.Sequential)]<br />
unsafe struct MyCSharpStruct<br />
{<br />
public int size;<br />
public IntPtr data;<br />
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]<br />
public string MyString;
}<br />
<br />
[DllImport("MyStruct.dll")]<br />
static extern void MyFunction(ref MyCSharpStruct myStructs, unsigned int nMyStructs);<br />
|
|
|
|
|
You can allocate the memory whereever you want. A simple solution might be to allocate it in managed memory as .NET array:
MyStruct[] myStructs = new MyStruct[N];
fixed (MyStruct* pMyStructs = myStructs) {
MyFunction(pMyStructs, N);
}
In this case, the GC will take care of freeing the memory.
You can also allocate on the stack (if N is small, for large N you would risk a stack overflow):
MyStruct* pMyStructs = stackalloc MyStruct[N];
MyFunction(pMyStructs, N);
In this case, the memory is freed immediately when leaving the function that allocated it.
If you want to allocate in the unmanaged heap, then use one of the allocation functions in the Marshal class:
IntPtr memory = Marshal.AllocHGlobal(N * sizeof(MyStruct));
try {
MyStruct* pMyStructs = (MyStruct*)memory.ToPointer();
MyFunction(pMyStructs, N);
} finally {
Marshal.FreeHGlobal(memory);
}
You could use Marshal.Copy to copy data from a managed array to an unmanaged pointer - but if you already have a managed array, you can simply use the first approach (fixed statement) to pass that without having to copy anything.
|
|
|
|
|
hi there,
Could anyone please give me a simple example of bluetooth transfer with c#?
i have googled that but no useful results.
my devices which i want to have the transfer are a hand held computer with windows mobile and the common PC with win xp or 7.
|
|
|
|
|
You can use 32feet.net or brecham obex fro transferring files to bluetooth device.
|
|
|
|
|
how to create picture boxes dynamically and display the pictures from sql server 2005.
pls help me.
thanks............
vamsi
|
|
|
|
|
You might want to take a look here[^].
|
|
|
|
|
You know how some website login forms change the color of textboxes you left empty to red?
I want to do that in my application.
Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red.
I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.
|
|
|
|
|
Well,
I haven't done that but I must ask, why not use an error provider?
Just find the Error Provider[^] in your toolbox and drop one on your form.
Then you can use something like this to set the error when they click 'check'.
myErrorProvider.SetError(myTextBox, "Not Valid");
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|