|
I have a fairly standard forms-based application with a lot of data-bound combos (DropDownList style) in it. Everything works fine except when the form is used to edit a 'new' object. In that case, all the form fields should be cleared. But combos dont show in cleared state, they just keep displaying the first value in the list. So now the user thinks that a value is already selected for him, but the application doesnt actually update the bound property of the object unless some other value is selected in the combo.
Lets say I have these two classes in my app.
<br />
class SelItem<br />
{<br />
public string Id { get; set; }<br />
}<br />
<br />
class MyObj<br />
{<br />
public SelItem Selection { get; set; }<br />
}<br />
To fill the drop down list of the combo i use (Id is a string property of the objects im passing through valuesList):
<br />
combo.DisplayMember = "Id";<br />
combo.DataSource = valuesList;
and using the forms designer I've bound the Text & SelectedValue of the combobox in this way (bindingSource contains a list of MyObj):
<br />
combo.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", bindingSource, "Selection", true));<br />
combo.DataBindings.Add(new System.Windows.Forms.Binding("Text", bindingSource, "Selection.Id", true));<br />
Currently, I'm clearing the combo-boxes by setting their SelectedIndex property to -1 every time a 'new' form is launched, but thats just a hack. Anyone got an idea why isnt the combo taking care of this automatically.
|
|
|
|
|
Is it possible to access a remote registry using WMI's StdRegProv namespace using C#? If so could someone direct me to some examples? It seems it can be done using C++ and VBScript but I've yet to find some examples in C#.
Thanks in advance!
Parrish
|
|
|
|
|
I've got a problem with the following piece of code
Boolean retval = false;
StreamReader sr;
try
{
sr = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Write));
sr.Close();
retval = true;
}
catch (FileNotFoundException e)
{
el.WriteEntry("Die Datei " + filename + " existiert nicht.", EventLogEntryType.Error);
}
catch (ArgumentException e)
{
Console.WriteLine("Der Stream konnte nicht gelesen werden.");
}
catch (IOException e)
{
Console.WriteLine("Datei noch nicht fertig geschrieben.");
return false;
}
finally
{
sr.Close();
return retval;
}
I can't access sr in the finally block. Why is that so? I thought try ... catch ... finally would make one construct. Same happens if I don't declare sr before the try.
-- modified at 4:12 Wednesday 17th January, 2007
|
|
|
|
|
In the finally block, you need to check that sr is not null before calling the Close method. This would become:
finally
{
if (sr != null)
sr.Close();
return retval;
}
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
You probably have to initialise sr before the try - plus use the method Pete suggested of checking for null.
StreamReader sr = null;<br />
<br />
try<br />
{<br />
sr = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Write));<br />
}<br />
catch(Exception ex)<br />
{<br />
}<br />
finally<br />
{<br />
if(sr != null)<br />
sr.Close();<br />
}
|
|
|
|
|
Actually initializing it with null did the trick. I'va done too much PHP
Thanks
|
|
|
|
|
Hi!
I have a problem about Scope_identity function();
I've created a dataset with two table, parent and child.
I've configurated both tables with the wizard; in that way for each insert and update of my records I obtain the correct ID.
The problem is that the queries of the child table doesn't return the updated ID, after my inserting or updating in the SQL Server.
I've looked into into the DatasetDesigner.cs, and I've read the queries. Both Update and Insert query have the end-select.
What is the reason of the problem?
What is my error?
Thank you for answers.
|
|
|
|
|
Yes, it does work, but only if used properly. What does you C# code looks like that's expecting this to work? What does the SQL look like?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
this is the query:
this._adapter.InsertCommand.CommandText = @"INSERT INTO [P_OrdiniRighe] ([IdOrdine], [CodiceArticoloInterno], [CodiceArticoloEsterno], [CodiceFinitura], [CodiceVariante], [Quantita], [DataConsegna], [QuantitaConsegnata], [UM], [Prezzo], [Note], [QuantitaImpegnata]) VALUES (@IdOrdine, @CodiceArticoloInterno, @CodiceArticoloEsterno, @CodiceFinitura, @CodiceVariante, @Quantita, @DataConsegna, @QuantitaConsegnata, @UM, @Prezzo, @Note, @QuantitaImpegnata);<br />
SELECT IdRigaOrdine, IdOrdine, CodiceArticoloInterno, CodiceArticoloEsterno, CodiceFinitura, CodiceVariante, Quantita, DataConsegna, QuantitaConsegnata, UM, Prezzo, Note, QuantitaImpegnata FROM P_OrdiniRighe WHERE (IdRigaOrdine = SCOPE_IDENTITY())";
this._adapter.UpdateCommand.CommandText = @"UPDATE [P_OrdiniRighe] SET [IdOrdine] = @IdOrdine, [CodiceArticoloInterno] = @CodiceArticoloInterno, [CodiceArticoloEsterno] = @CodiceArticoloEsterno, [CodiceFinitura] = @CodiceFinitura, [CodiceVariante] = @CodiceVariante, [Quantita] = @Quantita, [DataConsegna] = @DataConsegna, [QuantitaConsegnata] = @QuantitaConsegnata, [UM] = @UM, [Prezzo] = @Prezzo, [Note] = @Note, [QuantitaImpegnata] = @QuantitaImpegnata WHERE (([IdRigaOrdine] = @Original_IdRigaOrdine) AND ([IdOrdine] = @Original_IdOrdine) AND ([CodiceArticoloInterno] = @Original_CodiceArticoloInterno) AND ([CodiceArticoloEsterno] = @Original_CodiceArticoloEsterno) AND ([CodiceFinitura] = @Original_CodiceFinitura) AND ([CodiceVariante] = @Original_CodiceVariante) AND ([Quantita] = @Original_Quantita) AND ([DataConsegna] = @Original_DataConsegna) AND ([QuantitaConsegnata] = @Original_QuantitaConsegnata) AND ([UM] = @Original_UM) AND ([Prezzo] = @Original_Prezzo) AND ([Note] = @Original_Note) AND ([QuantitaImpegnata] = @Original_QuantitaImpegnata));<br />
SELECT IdRigaOrdine, IdOrdine, CodiceArticoloInterno, CodiceArticoloEsterno, CodiceFinitura, CodiceVariante, Quantita, DataConsegna, QuantitaConsegnata, UM, Prezzo, Note, QuantitaImpegnata FROM P_OrdiniRighe WHERE (IdRigaOrdine = @IdRigaOrdine)";
They are generated automatically...
This is the function for updating e inserting
public static void UpdateParentChildObject(<br />
DataTable oParentTable, DbDataAdapter oParentTableAdapter,<br />
DataTable oChildTable, DbDataAdapter oChildTableAdapter)<br />
{<br />
DataTable tblChildDeleted = null;<br />
DataTable tblChildAdded = null;<br />
DataTable tblChildModified = null;<br />
<br />
try<br />
{<br />
tblChildDeleted = oChildTable.GetChanges(DataRowState.Deleted);<br />
if (tblChildDeleted != null)<br />
oChildTableAdapter.Update(tblChildDeleted);<br />
<br />
oParentTableAdapter.Update(oParentTable);<br />
oParentTable.AcceptChanges();<br />
<br />
tblChildAdded = oChildTable.GetChanges(DataRowState.Added);<br />
if (tblChildAdded != null)<br />
oChildTableAdapter.Update(tblChildAdded);<br />
<br />
tblChildModified = oChildTable.GetChanges(DataRowState.Modified);<br />
if (tblChildModified != null)<br />
oChildTableAdapter.Update(tblChildModified);<br />
<br />
oChildTable.AcceptChanges();<br />
<br />
}<br />
finally<br />
{<br />
if (tblChildDeleted != null)<br />
tblChildDeleted.Dispose();<br />
<br />
if (tblChildAdded != null)<br />
tblChildAdded.Dispose();<br />
<br />
if (tblChildModified != null)<br />
tblChildModified.Dispose();<br />
}<br />
}
Tell me if you need more information
|
|
|
|
|
I fail to see where you're returning SCOPE_IDENTITY out of the database.
SCOPE_IDENTITY[^] will return the identity column of the last record INSERTed into a table. You're not inserting anything into the table with this code, so of course it's not going to return anything. On top of that, your SQL code isn't event returning the value of SCOPE_IDENTITY. You may want to read up on it so you get a better understanding of what it does.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
hi
i need to write a program that gets a string from the user,a replacement string and finally the new string.
ex aaabbb
aaa
zzz
output zzzbbb
i need to use a function replaceStr. can anyone help me?
thanks
|
|
|
|
|
You need to look at the string.Replace method.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
The answers below have it.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
rhank you for youre kind help. i'm really struggling with this language..anyway, below was posted a specific ex, i dont have the strings in advance. i need to allocate memory for thr new string.
|
|
|
|
|
This is the C# forum. You don't need to allocate memory for this because this is taken care of automatically. Your routine would probably be along the lines of:
public string MyReplace(string original, string valueToReplace, string replace)
{
if (original.IsNullOrEmpty || replace.IsNullOrEmpty ||valueToReplace.IsNullOrEmpty)
throw new Exception("One of the arguments is empty or null");
return orignal.Replace(valueToReplace, replace);
}
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
<br />
string str = "aaabbb";<br />
string toReplace = "aaa";<br />
string replacement = "zzz";<br />
<br />
str = str.Replace(toReplace, replacement);
life is study!!!
|
|
|
|
|
thank you for you're kind help. the thing is tose are specific ex, i dont know in advance what will be my toreplace string and the replacement. also, i need to alocate memory for the new string
|
|
|
|
|
Do you want us to write your entire project for you?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
s="aaabbb";
s=s.Replace("aaa","zzz");
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
I made this SetUp project using VS 2005, that works fine.
The only thing is that when select prequisites from project properties, I select .NET Framework 2.0, then I select 'Install from the same location' it builds fine.
VS creates a folder in the bin>>debug dir. called dotnetfx, BUT, when I run the setup on another machine where .net 2.0 is not there, I recieve the Message box That .NET 2.0 is not installed ..blah blah blah..
I also tried to delete the Launch condition of .NET Framework , it does not go....
I searched on the net and found http://visualbasic.about.com/od/usingvbnet/a/SetupProj01_2.htm
I added the prerequisites but still, it doesn't install WHY?
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Hi,
You are telling the installer that dotnetfx MUST be installed first AND that if it isn't then dotnetfx.exe can be found in the same location as your program AND to run that first. If this is what you want to do then you will have to distribute dotnetfx bundled with your program.
Glen Harvy
|
|
|
|
|
hi all
does anyone know how to replace the carriage returns in excel ?
the carriage returns are going in fine ("\r\n") and I can remove them and replace them with nothing or whatever I want, but I need to keep the carriage return so I need to know what to change it to. Excel doesnt deal with normal carriage returns and they display as little square boxes.
atm I have :
dr["text_value"].ToString().Replace("\r\n","[WHAT DO I CHANGE TO HERE]")
this is a csv file I'm creating from a db so I just need to know what the correct value for a carraige return in excel is ?
hope tat makes sense.
any pointer well appreciated
tia
tim
|
|
|
|
|
Hi there,
I am currently creating a windows service that calls a class. the class access a file in a certain folder to create a instance of this file(dll). When I call the dll from a console application it works very well with no problems.
When I do call it from a windows service it gives me an invocation exception error. What I did find was that the class has a problem with the file in the specific directory. I have checked user rights and ran the service as an administrator but it cannot access the file.
A friend of mine has precisely the same problem but on totally different sets of code. The only thing the same between his code and mine is that it is both services calling a dll trying to open a file in a specific location.
Can anyone please help me out here.
regards
Nic Scheepers
|
|
|
|
|
In the Service snap in, bring up the properties for the service you have started. There is a log on tab, which identifies who the service logs in as. Check to see what this value is. Then, assign read/write privileges to that user to the directory that the file is present in.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|