|
Just found out that that black screen mode is actually a security mode to prevent other programs from hooking into uac when you enter passwords or something...
anyway to invoke this for other programs?
|
|
|
|
|
I have a dataGridView and as I am processing its rows - with a foreach (dataGridViewRow row in this.dg) I may be setting the visible property to false (based on some processing logic). It works for all rows execept the first row. All appropriate rows disappear from my grid except the first row. I first thought it had something to do with it being the current row, but I physically navigated off the first row and then pressed my process button and the first row still was displayed.
Here is the code that I am using to hide/display the row:
private void HideShowRow(DataGridViewRow row, bool visible)
{
CurrencyManager cm = (CurrencyManager)BindingContext[dgSTSimport.DataSource];
cm.SuspendBinding();
row.Visible = visible;
cm.ResumeBinding();
}
I stepped through my code and at the end of the loop, the visible property for the first row was false. As I was processing the second row and setting values for some of its cells, for some reason the visible property of the first row got set back to true (I kept the first row in my watch window). The only code that sets the visible property is the method above, and the debugger never stepped into that code while I was processing the second row, so I am at a loss as to why this is happening.
I put an intermediary fix in place to loop through all the rows in the datagrid a second time and reset the visible property based on the status of the row. That worked fine, but I do not want to have to loop through all the rows a second time if I do not have to.
Any ideas as to what I am missing?
|
|
|
|
|
Can anyone tell me how I can return an array of bitmaps?
I have declared Bitmap[] test = new Bitmap[30]
and tryed to fill it with test[length++]=b (length being initialized to 0, and b being the bitmap)
but the "test" array does not seem to hold the bitmaps, except the last one.
Can anyone point me if not, as to what I have to read to learn how. :S
|
|
|
|
|
AKXman wrote: have declared Bitmap[] test = new Bitmap[30]
and tryed to fill it with test[length++]=b
So, all your array elements ended up holding hte same bitmap ? This is not a value type, it's a class. Unless b is redefined every time, you will find they all point to the one bitmap, change one and you change them all, because there is only one, just 30 references to it
The Clone method of hte Bitmap class will work just fine for this, but you need to cast the result.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thank You.
I tried bunch of things to keep the bitmaps, and I just happened to stumble upon the .Clone() option.
I don't understand why that works, but I will keep searching for an answer, some tutorial or a book ...
Thank You again.
|
|
|
|
|
It works for the reason I stated. Without it, all your array elements are references to the same bitmap, only one exists in memory, and so when it changes, all the elements change.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
there are only a few ways to create an object, the most obvious is using the "new" keyword;
others are calling a method that says Create() or Clone(). Everything else does not create
new objects, at best it duplicates a reference to a pre-existing object.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thank You both for Your answers.
I have managed to solve my problem inspite of all the unknowns I have encountered.
Mucho thanx to CodeProject and MSDN.
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi
Can any one provide me with help on how to serialize this collection of objects? I was trying to put some tags, but I am not really getting anywhere.
<br />
[XmlRoot ()]<br />
public class TableList<br />
{<br />
private ArrayList tableList;<br />
<br />
public TableList()<br />
{<br />
tableList = new ArrayList();<br />
}<br />
<br />
[XmlArray("tables")]<br />
public MyTableItem[] Tables<br />
{<br />
get<br />
{<br />
MyTableItem[] tables = new MyTableItem [tableList.Count];<br />
tableList.CopyTo(tables);<br />
return tables;<br />
} <br />
}<br />
<br />
public int AddTable(MyTableItem table)<br />
{<br />
return tableList.Add(table);<br />
}<br />
<br />
<br />
public class MyTableItem<br />
{<br />
TableInfo TableInfo = new TableInfo();<br />
<br />
[XmlElement("name")]<br />
public string TableName = string.Empty;<br />
[XmlElement("id")]<br />
public string OasisID = string.Empty;<br />
[XmlElement("Info")]<br />
public Object TableInformation = new Object();<br />
<br />
public MyTableItem ()<br />
{<br />
<br />
}<br />
<br />
public MyTableItem (string Name, string OasisID)<br />
{<br />
this.TableName = Name;<br />
this.OasisID = OasisID;<br />
TableInformation = TableInfo.GetTableInformation(Name);<br />
}<br />
}<br />
<br />
public class TableInfo<br />
{<br />
public TableInfo ()<br />
{<br />
<br />
}<br />
<br />
public Object GetTableInformation (string tableName)<br />
{<br />
if (tableName == "Table1")<br />
{<br />
Table1 tb1 = new Table1();<br />
return tb1;<br />
}<br />
<br />
if (tableName == "Table2")<br />
{<br />
Table2 tb2 = new Table2();<br />
return tb2;<br />
}<br />
return null; <br />
}<br />
}<br />
<br />
public class Table1<br />
{<br />
[XmlAttribute()]<br />
public string Prop = "Hello";<br />
<br />
public Table1()<br />
{<br />
<br />
}<br />
}<br />
<br />
public class Table2<br />
{<br />
[XmlAttribute()]<br />
public string WhatIsThis = "Test string";<br />
<br />
public Table2()<br />
{<br />
<br />
}<br />
}<br />
Thank you very much!
|
|
|
|
|
A couple of posts down you were saying that you serialized an object. Did you read my response or you are just asking around without a clue?
A couple of links for you: clickety[^]
|
|
|
|
|
Does anyone know how can I position the new form so that it shows the new record from the database, and not the first one?
I tried it like this, but it didn't work:
<br />
CurrencyManager cm = (CurrencyManager)this.BindingContext[myDataSet, "Author"];<br />
int numberOfRows = cm.Count;<br />
cm.Position = numberOfRows + 1;<br />
|
|
|
|
|
If you have a column that contains an Auto-Generated Index then you can sort by that and then pick either the first or last row based on how you sort. Otherwise, you would have to monitor each insert and handle it that way.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Anyone know a good method for implementing a findnext-ish function on a BindingSource ?
bindingSourceObject.Find works great for finding single rows but won't find the next value.
I'm thinking maybe declaring a DataRow array and assigning its value with dataTableObject.Select . Once I do that I use bindingSourceObject.IndexOf(dataRowArray[nextindex]) to get the desired position of the next row.
Does anyone have any better, more efficient ideas? If so, I'd like to hear them.
|
|
|
|
|
I guess I was on the right track. Here's the code that makes it work.
BindingSource _mainBS;<br />
string _fieldname;<br />
TARData.TARDataSet.DataRow[] _mRA;<br />
string _searchstring;<br />
int _currentPosition;
_mainBS is assigned by a constructor, likewise _fieldname .
public void FindNext() {<br />
if (_searchstring != textBox1.Text)<br />
{<br />
_searchstring = textBox1.Text;<br />
_currentPosition = 0;<br />
string searchCrit = getColumnSearchString(((DataRowView)_mainBS.Current).DataView.Table.Columns[_fieldname].DataType);<br />
_mRA = (TARData.TARDataSet.Carter_TAR_MainRow[])((DataRowView)_mainBS.Current).DataView.Table.Select(<br />
searchCrit + " LIKE '%" + _searchstring + "%'");<br />
}<br />
<br />
if (_mRA.Length > 0) {<br />
this._mainBS.Position = this._mainBS.Find("Main_ID", _mRA[_currentPosition]["Main_ID"]); ;<br />
}<br />
_currentPosition = (_currentPosition + 1) % _mRA.Length;<br />
}
Just in case _fieldname is an int type, I throw in this little tidbit to perform a convert.
private string getColumnSearchString(Type type)<br />
{<br />
if (type == typeof(int))<br />
return "Convert(" + _fieldname + ",System.String)";<br />
else return _fieldname;<br />
}
Not too efficient, but I still like admiring it. Not a bad way to spend an hour of my day.
|
|
|
|
|
Is there anyway to unbox an object without knowing its exact type? I have a situation where I have an object that is guaranteed to be castable to a double. I want to compare it to another value that I have stored as a double. Just casting the object to a double results in an invalid cast exception if the object is not of type double.
The only other way I can see to do this is to hard code cases for every value type that the object could possibly be, but this is obviously a pretty undesirable solution.
|
|
|
|
|
You could always try
try{
Convert.ToDouble(...)
}
catch (...)
{
} If you're using .NET1.1. If you're using .NET2 then take a look at
bool isDouble = double.TryParse(value.ToString(), out doubleVal);
|
|
|
|
|
Thanks for the advice. Parsing it as a string works perfectly.
|
|
|
|
|
How can this
jka347 wrote: Just casting the object to a double results in an invalid cast exception if the object is not of type double
be a problem if this
<blockquote class="FQ"><div class="FQA">jka347 wrote:</div>an object that is guaranteed to be castable to a double</blockquote>
is true?
You could also try object.Equals ( val1 , val2 )
|
|
|
|
|
Hey guys, I have this really weird issues and I can't seem to figure it out, the code list below run fine with no errors what so ever when I run it from a GUI application, but when i put it into a service and use it, it gives me a System.NullException error, but what is weird is that it gives me that error in the Finally Statement, but for some reason it doesn't even bother writing to the registry like it is suppose to, but it keep in mind the exact same code works if it is in a GUI application.
I have labeled the two lines that the error is given at.
Thanks for those who help.
Travis
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Data.SqlClient;<br />
using System.Data;<br />
using Microsoft.Win32;<br />
<br />
class VCS<br />
{<br />
private RegistryKey regKey;<br />
private SqlDataReader rdr = null;<br />
private SqlCommand cmd = null;<br />
private string procValue;<br />
private string connString<br />
<br />
private SqlConnection virasecConn = new SqlConnection();<br />
<br />
public void executeStorProc(string procedureName)<br />
{<br />
try<br />
{<br />
openConn();<br />
<br />
cmd = new SqlCommand(procedureName, virasecConn);<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
<br />
rdr = cmd.ExecuteReader();<br />
<br />
while (rdr.Read())<br />
{<br />
regKey = Registry.LocalMachine.OpenSubKey<br />
("SOFTWARE\\VIRASEC, LLC\\VCS", true);<br />
<br />
procValue = rdr[0].ToString();<br />
<br />
regKey.SetValue("Test", procValue);<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine(ex.Source + "\n" + ex.StackTrace);<br />
}<br />
finally<br />
{<br />
regKey.Close(); - Error occurs here <br />
rdr.Close(); - Error occurs here<br />
closeConn(); <br />
} <br />
}<br />
<br />
public void openConn()<br />
{<br />
virasecConn.ConnectionString = connString;<br />
<br />
try<br />
{<br />
virasecConn.Open();<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine(ex.Source + "\n" + ex.StackTrace);<br />
}<br />
}<br />
<br />
public void closeConn()<br />
{<br />
try<br />
{<br />
virasecConn.Close();<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine(ex.Source + "\n" + ex.StackTrace);<br />
}<br />
}<br />
}<br />
<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Diagnostics;<br />
using System.ServiceProcess;<br />
using System.Text;<br />
using System.Threading;<br />
<br />
<br />
public partial class VCS_Service : ServiceBase<br />
{<br />
Thread threadOne = new Thread(new ThreadStart(mainThread)); <br />
static VCS myVCS = new VCS();<br />
<br />
public VCS_Service()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
protected override void OnStart(string[] args)<br />
{<br />
threadOne.Start();<br />
}<br />
<br />
protected override void OnStop()<br />
{<br />
threadOne.Abort();<br />
}<br />
<br />
public static void mainThread()<br />
{<br />
while (true)<br />
{<br />
myVCS.executeStorProc("GetWesHomeNumber");<br />
Thread.Sleep(300000);<br />
}<br />
}<br />
<br />
}
|
|
|
|
|
Hi,
your code is not safe.
regKey initially is null, it is only some way down the try block it may get a non-null
value, yet you use it without any checking in the finally block.
Imagine OpenCon() fails, you'll drop into the finally without a valid regKey.
remedy: perform a null-test in the finally.
in future: add debug/log statements, or single-step through your code. You can easily
solve this kind of problems yourself.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I appreciate your help, I added the code to check for null values. Another question I am hoping maybe you can help with is, I added debug code to help me sort out any further issues and I noticed that the line that says:
rdr = cmd.ExecuteReader();
fails to execute, it drops immediatley into the catch block, do you have any ideas why that may be happening.
Thanks,
Travis
|
|
|
|
|
Hi,
when you catch an exception you should display and log the entire exception.ToString(),
not just parts of it. That probably will tell you some.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
CREATE PROCEDURE msp_AddPreferredProperty
i have this code. I want that if the property and username exists it wont be added for 2nd time, but if they dont exists i want them to be added in the table
thanks
@CustomerUsername varchar(50),
@PropertyId int
As
if EXISTS
( Select count(*) From tblPreferredProperty Where CustomerUsername = @CustomerUsername
And PropertyId = @PropertyId)
Begin
Insert into tblPreferredProperty(PropertyId, CustomerUsername)
values(@PropertyId, @CustomerUsername)
End
GO
|
|
|
|
|
Looks not far off to me. Try this:
create proc msp_AddPreferredProperty
(
@CustomerUsername varchar(50),
@PropertyId int
)
as
if not exists(select 1 from tblPreferredProperty where CustomerUsername = @CustomerUsername And PropertyId = @PropertyId)
insert into tblPreferredProperty(PropertyId, CustomerUsername) values (@PropertyId, @CustomerUsername)
go
Regards,
Rob Philpott.
|
|
|
|