|
|
When you update a row, the row state is set to DataRowState.Modified and the DataAdapter derivative you're using will use the UpdateCommand along with the primary key to update the row in your data store. If you change the primary key, the UpdateCommand will fail because there is no row (most likely) that contains that key (now that you've changed it).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hi
Well i am using Microsoft Internet Explorer Tree view WebControls.
I am working on ASP.net with C# as the language.
Well i want to Have no node selected or Hide Tree view first Node when we load the tree.
how do we go abt doing this?
plz rely ASAP
if any body can help it will be gr8.
Regrds
Tejas
|
|
|
|
|
|
Yes tried that dose not work
still the Selected node index=0 when the tree is rendered
Thanx
|
|
|
|
|
Both the above ways return the line spacing that includes the blank space between lines along with the height of the character itself.
When I use the return value to calculate number of text lines to be inserted in the document that I am creating, lets say it is 74 lines per page. But after creating the page only 54 text lines get inserted in a page and rest of the text lines get passed to next page.
In other words, word processor inserts its page break after 54 lines.
The font I am using is MS Gothic, size 11.0. When I convert it in Twips its is 225 and Lenght of A4 size paper is 16833 Twips.
Thus to insert 54 lines per page the font height should be 311 Twips, where as I get 225.
Please guide.
|
|
|
|
|
Measuring a font without regard to a device context (HDC in native code; encapsulated by the Graphics class in managed code or an IntPtr if you P/Invoke native Windows APIs) can yield invalid results.
Instead, either use a Graphics object passed to you (if provided; for example, from PaintEventArgs.Graphics in your Paint event handler or your OnPaint override) and call MeasureString to measure the font height for a line of text (with plenty of hanging glyphs).
You can also P/Invoke native functions like GetDeviceCaps (which hopefully you're doing already to make sure you're calculating twips correctly and not assuming 96 DPI; if you are, search for GetDeviceCaps in this forum and you'll find a handy little class I posted for correctly converting without taking a dependency on Microsoft.VisualBasic.Compatibility.dll) and use GetFontData . You can also get an HDC (as an IntPtr from the Graphics class for a control. If you need the HWND (window handle) for a control use its Handle property.
You can also create a Graphics class for a control at anytime using Control.CreateGraphics . Just be sure in that case to call Dispose on the Graphics object when you're done, otherwise it'll handle around in memory until the GC decides to clean it up.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
Is there any way possible that I can use the same hotkeys on different pages of a tab control (for example, both pages having a button that responds to Alt+S)?
The thing is that my two tab pages share some identical controls and I would like the UI to be consistent between the pages.
I tried having the same hotkeys but the results were not as expected. Im hoping that I am missing something though
Thanx,
-Flack
|
|
|
|
|
I suspect you'd have to manually switch the hotkeys in code every time the user clicks on a different tab
Either that or instead of having duplicated controls, just have a single set, and put them as children of the form, rather than children of the tab page (you'll have to manually show/hide them when the tabs change, though)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Im new to using Excel with C# and I ccant seem to get this seemingly simple task done.
What I want to do is get a range of cells from an Excel sheet and put the resulting cell values in a string array. (I know that the values are all strings).
The code I have that gets the job done is this:
<br />
string workbookPath = fileName_;<br />
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,0,true,5,"","",true,Excel.XlPlatform.xlWindows,"",false,false,0,true,false,false);<br />
Excel.Sheets excelSheets = excelWorkbook.Worksheets;<br />
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(1);<br />
Excel.Range excelCells = (Excel.Range)excelWorksheet.get_Range("A1","H1");<br />
System.Object[,] result = (System.Object[,])excelCells.EntireRow.Value2;<br />
Now, this code gives me a two-dimensional array with all of the values included, along with every other null item in that row (giving me an array with a second dimension length of 256).
I tried doing:
<br />
System.String[] result = (System.String[])excelCells.Value2;<br />
because I can see that excelCells.Value2 is an array. Unfortunately, this line gives me an invalid cast exception.
Is this way the only way I can get an Excel row into an array (without going through each cell manually, getting its value, and adding it to an array)?
How about if I wanted to multiple rows, like ("A1","H7")?
Thanks,
-Flack
|
|
|
|
|
Value2 - as well as many other properties and methods - return a VARIANT or single- or multi-dimensional arrays of VARIANT s (a native struct). These marshal as object s. Casting an object to a string (BTW, use the type aliases like object and string instead of Object or String for more readable code, and don't qualify all your types; use the using Namespace; statement at the top of your source file) is possible, but casting an array of variants to a string[] array isn't valid (unless you write a custom marshaler that does it for you). You're also assuming that the cells in such a range will all marshal as strings. Depending on what type you set the type format of in Excel, it may marshal as different types of data.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Does anyone know a software that converte VB to C# code ???
|
|
|
|
|
|
|
VB to VB.Net or C# . Thanks
|
|
|
|
|
|
If you're talking about VB6 or older (it uses a completely different runtime and relies on COM - not the .NET base class library and third-party assemblies), then a better question to ask yourself is "Why should I convert?"
If you're doing it just to jump on the .NET bandwagon you're doing it for the wrong reasons. You need trained staff to maintain the code and build upon it. Just converting the code doesn't gain you much (besides a 20+ MB runtime that now has to be installed on your clients' machines before your application can even run). There's a lot more power wrapped up in the .NET Framework and more efficient code and better application designs can be written using .NET. Just converting your VB6 code will end up using a lot of inefficient code accessing COM objects (and you'll take a marshaling performance penalty more so than with VB6) for which there's probably replacements for in the .NET BCL and third-party libraries (no marshaling, just direct access).
There's a lot of other reasons besides those I've listed above. Googling for such topics I'm sure will uncover more reasons.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I've been searching all over the web for this, and have tried numberous things, however, there is simply no evident way to print a machine's ip (the remote ip!!!, not the local ip). the only way left is to retrieve it from a website running php or something. How would I retrieve this from a web page?
thanks a ton,
Stephen
|
|
|
|
|
Did you try the Dns.GetHostByName method?
If that doesn't help, please give some more information. What information do you have about the machine whose ip you want to retrieve? For what do you need the IP?
www.troschuetz.de
|
|
|
|
|
Hi guys
Is it possible in C# .Net to assign your own "custom" shortcuts to MenuItems? I want to have a shortcut like the following:-
- Alt + Left Arrow
- Alt + Right Arrow
- Alt + Home
The problem is that MenuItem.ShortCut property accepts only enumerated values from the ShortCut enumeration. Is it possible to convert the text to an enumeration and then assign the new value to the property?
Thanks in advance
|
|
|
|
|
I think you can in .NET2 (at least you get a window that actually lets you define the shortcut, rather than picking from a list), but in .NET1.x it seems you're stuck with the built in enum
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Not with the MenuItem.Shortcut property - or the MenuItem class itself, for that matter. You can use the Keys enumeration (which is a 1-1 mapping of the VK native enumeration) for the ToolStripMenuItem.ShortcutKeys property, which is part of the new WinBars implementation.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Unless the implementation that accepts the enumeration validates the value, you can cast any numeric expression to the enumeration type. The set accessor for the MenuItem.Shortcut property is one such implementation, as are most implementations that deal with enumerations in the .NET BCL.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
In C++\STL i can create pairs of values using make_pair so I could, for example, look up a value in a map/dictionary using a 2 value key:
XXX::iterator it = m_map.find(make_pair(x,y));
Is there an equivalent in C# or if not a way around it?
TIA
|
|
|
|
|
A Hashtable stores key/values pairs that are both object s, meaning that you can store anything (since every Type in .NET extends System.Object ). This means that you can store, for example, a class (best to use reference types to avoid boxing and unboxing performance penalties) with a couple of properties like so:
public class Person
{
string name, DateTime birthday;
public string Name
{
get { return name; }
set { if (value == null) throw new ArgumentNullException(); name = value; }
}
public DateTime Birthday
{
get { return birthday; }
set { birthday = value; }
}
} Then create an IComparer implementation to compare whatever property or properties you want, or have your class implement IComparable so that the default Comparer can juse use your implementation (this option is often best when defining your own types as it works without implementing and using a separate Type).
If you read the documentation for the Hashtable , however, you'll notice that if you don't pass an IComparer to the constructor the default comparer it uses will use the Equals override. So, you could also override Object.Equals (which implies you should override Object.GetHashCode ) and not pass a comparer, or implement IComparable on your class and pass Comparer.Default to the Hashtable constructor, or implement IComparer and pass your implementation to the Hashtable constructor. This will allow you to compare keys, not values, though. For that, enumerate the Hashtable.Values collection or enumerate (using the IDictionaryEnumerator ) the entire Hashtable to compare values so that you have both the key and value.
As far as whether to override Equals or implement IComparable , you could do both.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|