|
Okay, I understand. However, could I create an instance of XmlRootAttribute, and potentially set some namespaces also instead of using a dummy class?
|
|
|
|
|
Has a Excel file like that:
Title
Field1 Field2 Filed3
1 AA 1.1
2
3a CC 3.3
4 DD 4.4
I wrote a program in order to import the excel file datas to DataGrid:
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Test.xls; Extended Properties=Excel 8.0");<br />
connection.Open();<br />
DataTable dt = new DataTable("Orders");<br />
OleDbDataAdapter da = new OleDbDataAdapter();<br />
da.SelectCommand = command;<br />
da.Fill(dt);<br />
this.dataGridTest.DataSource = dt;
Why in the DataGrid show as:
F1 Title F2 ------> This is header
(null) Field2 Filed3
1 AA 1.1
2 (null) (null)
(null) CC 3.3 ------> Note this line column 1 is null!
4 DD 4.4
If the Excel file like this:
Title
Field1 Field2 Filed3
1 AA 1.1
2a
3a CC 3.3
4a DD 4.4
That the DataGrid turns to like this:
F1 Title F2 ------> This is header
Field1 Field2 Filed3 ------> Note the Field1 now is not null
(null) AA 1.1 ------> Note this line column 1 is null!
2a (null) (null)
3a CC 3.3
4a DD 4.4
Why? How can i prevent this result? (I had try to make the column 1 is Text format not Generic, but also yet)
=== Game is power! ===
|
|
|
|
|
Hi Libra,
Can you try something with your command object.
Insted of selecting a sheet can you try selecting a range of cells.
command.CommandText = "Select * from [Sheet1$A2:B7]";
Thanks and Regards
Pani.
|
|
|
|
|
Thx for you help.
I try as your said but it's trashy. Select of a part datas is base on the Select of whole sheet.
I wonder if the OleDb Engineer adjust the type of each excel column when transfer, so when the column looks has more numerical value that it make the numerical type, when the column looks has more string value that it make the string type.
=== Game is power! ===
|
|
|
|
|
have a TXT file that contains the word FLAT several times.
I want to read the file and replace the word FLAT by ZAG.
|
|
|
|
|
Read the file into a string , then use StringParser.replaceEvery() . See this[^] article.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
public void FileReplaceString(string path, string find, string replace, bool matchcase)
{
System.IO.TextReader r = new System.IO.StreamReader(path);
string text = r.ReadToEnd();
r.Close();
r.Dispose();
text = System.Text.RegularExpressions.Regex.Replace(text, System.Text.RegularExpressions.Regex.Escape(find), replace, (matchcase)?System.Text.RegularExpressions.RegexOptions.None:System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.IO.TextWriter w = new System.IO.StreamWriter(path);
w.Write(text);
w.Flush();
w.Close();
w.Dispose();
} To call:
<br />
FileReplaceString(@"C:\Document.txt", "FLAT", "ZAG", false);<br />
|
|
|
|
|
Has anyone used C# (or even VB.NET) to display video from an ethernet camera? I am trying to do this in the Compact Framework. Does anyone know of any examples, web sites, tools or the best classes to help with this?
Thanks!!!
|
|
|
|
|
May be this can help you... I used a library from DirectShow.Net[^].
This guy has a sample using a webcam (dxwebcam) look for that one.
daniero
|
|
|
|
|
Thanks - I'll check it out and see if it works with the Compact Framework.
|
|
|
|
|
Here's a good problem.
I'm trying to set up a system where text fields in a database define dynamically-generated controls on the form. In other words, when a user makes a selection on the form, the system will pull all the records that match that selection from a database that contains text information that defines all the controls from one table, and text information that defines each of those controls' properties from a related table.
Now, I could set up switch statements that would satisfy many of the possible permutations. But that would require hundreds of lines of code, and it wouldn't be feasible to predict all the possibilities.
My idea is to use generics (which I'm just learning about) to dynamically define the controls and their properties. In essense, I need to somehow get text from the database into the utilization of the generic.
Conceptually, something along these lines:
****
public class GenericControl<T>
{
**Code to construct the control**
}
class TestGeneric
{
private void BuildControl()
{
//In reality, this string would be retrieved from the database.
string controltype = "System.Web.UI.WebControls.TextBox";
//Then the part that won't work:
GenericControl<controltype> MyControl = new GenericControl<controltype>();
}
}
****
Now, if I understand correctly, generic utilization requires that you use a defined object where I have "controltype" - which is why the above example won't work. Is there any way to take the string "System.Web.UI.WebControls.TextBox" and use it to get a TextBox object type (or the appropriate object type) - without using a switch statement?
|
|
|
|
|
I think that you will have much better luck using reflection instead.
Use the GetConstructors method of the Type class to get an array of ConstructorInfo objects. Use the Invoke method to create the object.
---
b { font-weight: normal; }
|
|
|
|
|
In Generics, types must be known compile-time, not run-time, and do not instance parameters (controltype is an instance of the System.String class). The suggestion from Guffa is very good, but you could still avoid having tons of switches in your code.
Start from the fact that all your controls inherit from the System.Windows.Forms.Control class, which, I would say, contains about 95% of the properties of the built-in controls (Size, Font, Text, Position, Name, Visible, etc.).
So, using reflection, you could, as suggested by Guffa, instanciate your controls in a way similar to the one below:
List<Control> controls = new List<Control>();
foreach (....)
{
Type myControlType = Type.ReflectionOnlyGetType(controltype, true, false);
ConstructorInfo myControlContructor = myControlType.GetConstructor(Type.EmtpyTypes);
Control myControl = myControlContructor.Invoke(null);
controls.Add(myControl);
}
Then, set all the properties common to all controls, I think this would cover much of your cases.
You will need some mechanism (maybe a flag from your database) to indicate properties that are not defined in the System.Windows.Forms.Control class.
Hope this helps,
Michel
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
-- modified at 7:39 Friday 27th January, 2006
|
|
|
|
|
I have a program that uses a custom combobox I wrote. On SOME versions of Windows 2K, when the combobox dropdown closes, the area underneath the dropdown is not redrawn/refreshed. If I add a "Refresh()" call to the code to refresh the display when it closes, nothing happens.
I also notice that, on the same display, if I run a program that has a crystal reports control, when the report is finished, the report is drawn offset to the right (on other displays, it is scaled to fit within the window and centered). If you scroll all the way to the right of the report, then back to the left edge, what went under the left edge of the control display is not redrawn (it is missing), even after forcing a refresh. The only way to get it to redraw is to change the scale/size of the displayed report.
So far, I have only seen this happen on SOME versions of Windows 2K. I have not seen it happen on all Win 2K or even Win XP systems. If I do a windows update on the effected systems, it does not fix the problem.
Is there a corrective action, either in Windows settings or programatically?
-- modified at 15:45 Thursday 26th January, 2006
|
|
|
|
|
Try attatching Invalidate() to the drop down / changing events of the listbox, or on the Form.Enter event
|
|
|
|
|
Since I am calling the parent window's "Refresh()" method, shouldn't that cause it to completely redraw, regardless of whether any part if it is invalidated or not. I know that calling the "Update()" method should only cause a redraw of those parts of the interface that are invalidated, but I thought "Refresh()" said redraw entire... no matter what.
|
|
|
|
|
I think refresh() changes the date, all painting should be in paint / invalidate()
Invalidate() is what tells the system to re-draw the client area - call that whenever focus enters the form or leaves the combobox
|
|
|
|
|
Hi.
How can send my programm to system tray.
I write a clock alarm program and want when running go to system tray.
Best wishes
|
|
|
|
|
You can use the NotifyIcon[^]-Component.
'A programmer is just a tool which converts caffeine into code'
|
|
|
|
|
|
Can someone please tell me how to create the appropriate buffer to hold characters in a LPCTSTR buffer in C#. I have tried using Strings but the results are chaotic to say the least.
For instance, SendMessage, often will use a LPCTSTR in the LPARAM to return a collection of characters. How do I create the appropriate array in C#.
Eric
|
|
|
|
|
I'm sorry to be more clear, How do I get a string safely into an IntPtr since I have defined my SendMessage with LPARAM as an IntPtr?
Thanks,
Eric
|
|
|
|
|
Try System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(Auto/Uni) . This will do the trick.
Andy
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
Thanks Andy, this seems to work!
Eric
|
|
|
|
|
Try casting it to a C# string from a lpcstr
|
|
|
|