|
I have an XmlTextReader that is reading through a document, I get a start element with the name that I am looking for
call reader.Read to get inside data
and reader.ReadString() to get the text.
This works fine except for a case where I want the text to contain some HTML
the html looks like "firststring <-> secondstring"
I am storing it as XML like "firststring&nbsp;&lt;-&gt;&nbsp;secondstring"
but the reader only gets firststring on the call to ReadString()
is there a way I can get the complete string in a single call, changing the & to &?
Thank You
|
|
|
|
|
I have a page (ASPX) that has a grid on the left side and an embedded web control (ASCX) on the right side. The ascx contains lots of textboxes,labels,etc.
I have added Get/Set properties for each of the controls in the ascx code-behind file. I want to pass data retrieved from the selected row in the grid to the textboxes in the ASCX. Here's a snippet of the code;
ASPX code-behind:
protected DeficiencyReport DeficiencyRpt1; //reference to ASCX
DeficiencyRpt1.SPRTextBox= "value"; // set new value
Property in ASCX:
public string SPRTextBox {
get {return SPR.Text;}
set {SPR.Text=value;}
}
Everything works fine except that the value is not displayed in the textbox. Can anybody tell me what I'm missing?
Tony N
|
|
|
|
|
Your question belongs in the ASP.NET forum.
And next time please be patient when posting instead of posting the same three question three times. The site is slow to repond at times. If you would've been buying something you would've just bought 3 copies of it. The lesson is be patient. If a site is going to err it will tell you (or the browser will tell you).
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 am building a table of about 100 schools and school numbers using dataadapter. The table has three columns: schoool name, school number and index. Index is an identity column and the primary key. This database table is empty when I start.
I create a dataset of the schools and insert rows to the table but when I try to update it, only the first record is inserted and the update fails on the second insert because of duplicate key in the identity column. Here is the code:
DataSet1 ds1 = new DataSet1();
public int AddSchools(string [,] strSchoolList)
{
for (int i=0; i<200; i++)
{
if (strSchoolList[i,0] != null)
if (strSchoolList[i,0] != "")
{
ds1.Schools.AddSchoolsRow(strSchoolList[i,0],strSchoolList[i,1]);
}
}
sqlDataAdapter1.Update(ds1);
return 0;
}
If I configure the dataadapter without the identity column, it cannot autogenerate the update and delete commands. But with the identity column it will not let me add a value to the index column as in:
ds1.Schools.AddSchoolsRow(strSchoolList[i,0],strSchoolList[i,1],i);
I can work around this problem, but someone out there must know the proper way to handle this situation.
|
|
|
|
|
For inserts don't insert values from DataTable s into the database. Instead, insert only non-auto-generated field values and add a SELECT statement (separated by a semi-colon) after your INSERT to make sure the DataTable has the correct data from the auto-generated fields. This is what the command builders do automatically, which the visual designers also make use of. It is also recommend throughout the .NET Framework SDK documentation.
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]
|
|
|
|
|
Heath, I don't understand your advice at all. I'm using Visual Studio to autogenerate most of the code. I drag a dataadapter from the tool box onto a component designer and use the "generate dataset" from the "data" drop down menu. For the insert, I just update the dataadapter after adding new rows to the table with the data to be inserted. I don't even have access to the identity column. The actual code is listed in my first posting.
|
|
|
|
|
If the command builder didn't recognize the identity columns (and that's possible based on what OLE DB driver you're using) then it could include the identity columns in an insert. Just because VS.NET built the code doesn't mean you shouldn't review it. Expand the auto-generated #region in your source file and ensure that no auto-generated columns (like an auto-incrementing ID column) isn't inserted into the database).
If you're using OleDbDataAdapter then it may not work to combine an INSERT and SELECT statement into the InsertCommand property. You'll need to Update the database with the adapter first, then re-Fill the DataSet .
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 have a TreeView with nodes at only two levels. I want to add a ContextMenu and change the contents of the context menu depending on the node that is right-clicked. I am using the Popup event to change the content of the context menu as is common practice.
The problem is that the instant the user right-clicks a node, the node is highlighted, but in reality does not becomes the selected node. In fact, TreeView.SelectedNode contains a reference to whatever the previously selected node is. This is very confusing to the user, because it sure looks like the node he has right-clicked has becomes selected. However, programatically I cannot determine (thru TreeView.SelectedNode) which node was right-clicked.
Has anyone run into this? Any work arounds?
Thanks!
Mark Mokris
|
|
|
|
|
This is the work around I used:
private void tvTreeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
if(e.Button==MouseButtons.Right)
{
TreeNode tn = tvTreeView.GetNodeAt(e.X,e.Y);
if(tn==null)
return;
tvHL7TreeView.SelectedNode=tn;
}
}
catch(Exception Err)
{
throw new Exception("MouseDown: "+Err.Message);
}
}
|
|
|
|
|
Thanks a million! That worked great!
Mark
|
|
|
|
|
how do I have a machine refresh the user policies? I know there's a registry key to do this, but it seems to me there should be a better way, as the system doesn't even rescan that key often enough to know how often to refresh policies.
2ndly: how do I send text to a textBox on the next line of the textBox, without deleting any previous data in it.(this is a multiline textBox) (I'd prefer to not have to send previous contents to a variable and then insert them, as there should be a better way). also, is there a way to add the line numbers to each row of text in a text box.
thanks a bunch,
Stephen
|
|
|
|
|
check out the documentation on secedit.exe, this should allow you to update the Group Policies on a particular machine.
|
|
|
|
|
I couldn't get the thing to refresh my policy settings on my own machine even after changing them with gpedit.msc (I tried disabling regedit and the control panel). this didn't even work plus, I need to be able to incorporate these commands into my c# app. (I don't know how to use the command prompt via a c# program).
|
|
|
|
|
In order to force the refresh of Group Policies, you can call the API functions, defined in UserEnv.dll, RefreshPolicy or RefreshPolicyEx.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
incorporating the comand into your C# app is easy.
Just use the Process class. It has a static method Process.Start("command here") where the string represents the executable to run.
|
|
|
|
|
I have a few questions about Excel automation.
I've added a reference to the 9.0 Excel lib.
1. I'm able to automate Excel quite well but the instance of it will not close when I call the Application.Quit() method as in the following code:
ArrayList ToList = new ArrayList();
Excel.Application XLS = null;
Excel.Worksheet wsWorkSheet = null;
try
{
XLS=new Excel.ApplicationClass();
XLS.Workbooks.Open(FilePath,0, true, 5, "", "",
false, Excel.XlPlatform.xlWindows, "",true, false, 0, true);
...
...
}
finally
{
wsWorkSheet=null;
object missingValue = Type.Missing ;
if(XLS!=null)
{
XLS.ActiveWorkbook.Close(false,missingValue,missingValue);
XLS.Quit();
}
XLS=null;
}
Once my entire application closes the Excel instance closes but not when I call the Quit() method and set the instance varaible to null like I would expect it to.
2. At one point I allow the user to view the Excel Workbook currently being processed, it there any way I can catch the Excel close event, so the user cannot close the instance of Excel ?
3. Finally I was wondering if anyone had a simple way to tell if data is present in a particular WorkSheet. Right now I'm attemping to check the first 10 row of every sheet to see if there is data in them, but I suspect there is an easier way. Can I also interogate the WorkSheet for which Columns are in use ?
|
|
|
|
|
Hi,
I have a window written in a 4GL running, it uses a c# program to handle it's windowsmessages. On WM_PAINT I want some extra painting to happen (after the 4GL default). Just before the extra painting, I need some properties from the 4GL window.
I have seen ocx's used in the 4GL, you can choose ocxevents in the 4GL editor which you can edit, these events can have input, output and ref parameters. Do you have a (short) example of how to write such an ocx (with an event as described)?
I suppose this way of getting info into C# from the 4GL is to be preferred above socketcommunication?
regards,
Stefan.
|
|
|
|
|
I have a text file which contains different properties of a class (like integers, doubles, integer-array (more numbers divided by commas),..)
I want to read and assign.
Well, i managed to read all the key=value Pairs in that textfile and the looping through all the properties of that class. Now I want to assign these values to their appropriate property of the class.
But how can i convert now the values (which are logically strings) to the datatype they have to be?
I need something like
object Convert.FromString(string str)
Or I compare the read in keys with the properties from the class so that I know to which Datatype the string has to be converted, but on this way I need a way to typecast dynamically.
|
|
|
|
|
See the System.Convert class for dynamic casting and the System.Reflection namespace for reading the return type of properties.
|
|
|
|
|
object System.Convert.ChangeType(object value, Type conversionType, IFormatProvider provider);
|
|
|
|
|
that's what i was searching for
thanks
|
|
|
|
|
Hi,
Ive tried a Datagrid datasource bound to a dataview and dataset. I click on the header and it sorts the grid, which i want. After this i want to get the value in the first row, first column of the new datagrid before it has been drawn. Before I sort the grid i get the value either by getting it from the datasource or the dataview and it is what I want. Now i try to get the value after the sort and it gives me the same value as before the sort was done. Ive tried to bind the new dataview after programatically sorting it and getting the value, but with no luck. Please help.
My aim before was to override the Paint method and color the rows I want a different colour. So i need to check the value before it paints.
|
|
|
|
|
There are two different methods that can be used to do this. (Please be sure to check MSDN on the datagrid to get more details about both).
I color the column (not a row) that has just been sorted in an "OnItemCreated" procedure. I check to make sure the item is an Item or an Alternating Item and then I get the back color like this:
e.Item.Cells[m_iSortColumnIdx].BackColor = (System.Drawing.Color) new ColorConverter().ConvertFromString("#CCFFCC");
The other procedure you can use is the "OnItemDatabound" procedure. Again, you have to check to make sure the item is an Item or an Alternating Item.
From this method, you can access each of the cells and a number of attributes for that cell: text, back color, fore color, alignment, columnspan, class, etc. So if you know the column number (zero-based), you can also get the text.
Here's how I format my social security numbers in my very first column of my datagrid.
e.Item.Cells[0].Text = Utils.FormatSocial( (string)DataBinder.Eval(e.Item.DataItem, "social_num") );
I believe if you wanted to color the whole row, you might need to loop through each of the cells and set the color in the loop. (From what I remember of trying to do this in the past, this is how I had to change the style class or the color for an entire row).
You might also try 4 Guys From Rolla which is running an EXTENSIVE examination of the datagrid. You might find some discussion of these methods in that set of articles. The latest is # 17.
Pegmeister
|
|
|
|
|
hi,
Thanks for the help. I will try this out, its something I can do after my grid has been paited but I still need a way of getting the row information before the grid has been painted. What I do is check if something exists in the row and if it does I color it a certain color. My problem is that the paint method has the row number as a parameter but when I get the row from the Datasource bound to the grid using this row it doesnt give me the row that actually displays. This happens after I click the column header to sort the grid.
I cant cast the CurrencyManager Source and check its details because it only shows information for a specific cell in the row (I think its GetValueAtColumn(Source, RowNum)). I need to check the 1st column in that row and determine what colour to paint the cell.
|
|
|
|
|
Hello !
I am about to develop a decisional application that would display a huge amount of data (that is to say cells of grid).
The main principle of this project is that we have one column per day (an horizontal calendar grid in fact) and several rows below displaying different numerical or graphical informations.
We can of course display another range of dates by using the left and right arrow keys for example in order to move by one day (+1 or -1).
Furthermore we must implement a clean usability with navigation, scrolling, collapse/extand of certain rows, painting with mouse on certain rows and so on...
I can be provided with the data that are to be displayed in the shape of a dataset (one ROW per day) or of a custom XML stream.
The amount of data is so large that the grid(s) will cover an entire 1024x780 screen with around 30 visible days.
Now here is my question :
I wonder how to model this application in order to obtain a fast display (not flickering for example) and a easy to use application.
Must I reverse the dataset to get the days as columns and then databind it to the grid ?
Must I implement a collection of instance of a custom Day object and painting over the grid ?....
Please help me so that I will not have to rewrite all my code in a few month ....
Thank you in advance for all pieces of advice !
Guim7
|
|
|
|