|
|
I have an application that takes a load of data and pumps it into a Datagrid, the problem I have is that I want to be able to retrieve all the values for the currently selected row in the grid.
Is there a way of using the current row index to retrieve all values into a DataRow (I also need the column header names aswell)?
At the moment I am doing this a god awful and rather restrictive way, by using :
int selectedrow = myGrid.CurrentRowIndex
string val0 = myGrid[selectedrow, 0].ToString();
string val1 = myGrid[selectedrow, 1].ToString();
string val2 = myGrid[selectedrow, 2].ToString();
string val3 = myGrid[selectedrow, 3].ToString();
.....
I am open to any other suggestions, as I dont have to use a DataRow - so over to you guys.
Thanks
|
|
|
|
|
Well I have found what seems to be a solution to my problem. The following code will get the currently selected datagrid row into a datarow :
CurrencyManager cm = (CurrencyManager)dgOrgData.BindingContext[dgOrgData.DataSource];
DataRowView drv = (DataRowView)cm.Current;
DataRow myRow = drv.Row;
Now the plot thickens a little, I use this code to get the datarow values for a datagrid row when a user right right clicks on the datagrid (code is in a contextmenu event) - what I would also like to get is the cell value that the user right clicked on?
|
|
|
|
|
Hi guys !
I've a WinForm with 2 ListView control and I've something special to do with the 2nd ListView. If user changes something (like ColumnHeader size) on ListView 1 then this change will be applied on ListView 2 too.
My first approach was to override WndProc of ListView 1 and foward all messages to ListView 2 (via Win32 api function SendMessage()) but it was unsuccessful.
Any idea ?
--
Regards,
Julian.
|
|
|
|
|
why not just add a delegate for the event then execute a command on the second
|
|
|
|
|
Input from where exactly? From a file, from a stream, from a console application, from a form?
Without context, I can't help you. Mind you, even with context, the question may have no answer either . For example, if you're using a TextReader, you can't get at the "raw" character; it'll have been translated into a standard UNICODE character.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
DeanAgan wrote:
Its actually read from a textbox. Translation into a standard unicode? How do u do that? The code is suppose to block input in the textbox that exceeds 32 characters. But if I would input in Chinese characters, which has a double byte character set, then even if only 32 characters are inputted, problems would still arise coz its actually 64 characters in single byte character set. Im looking for what class to use, though I can solve it without using a class and just by looping through it.
When you are talking about the MaxLength property of the TextBox , that is refering to the actual number of character entries that are allowed, not the number of bytes. Under .NET, the TextBox 's Text property returns a String data type which is of Unicode encoding where all characters are two bytes long.
-Nick Parker
|
|
|
|
|
I heard that C# and other .Net app can be compiled as then native app,don't need to use JIT.
How?
Thank you!
Let's roll!
|
|
|
|
|
Check MSDN for ngen.exe
Alexandre Kojevnikov
MCAD charter member
Leuven, Belgium
|
|
|
|
|
It's really funny,take a look at your app build by vs.net 2003.
I have a app that is 36KB just after been build. But when I run it by double click it and close it. It's size expand to 56KB. And then I run it again,it's size shrink to 36KB,and I close it,well it's size expand to 56KB.
Why? How can it change it's size during runtime?
Well I try the same way using C# Builder. It doesn't happen.
|
|
|
|
|
I just used Borland C# Builder and use it to develop a same program that I used to in vs.net 2003. I found C# Builder compiler is much faster than vs.net. And the program size it build is smaller.
Why?
|
|
|
|
|
Are you working for Borland ?
There is no "C# Builder compiler"...C# Builder is using csc.exe just like VS.NET, so what are you saying there is impossible.
|
|
|
|
|
Are you sure! I don't think so. Just take a look of my recent message,it shows different.
Let's roll!
|
|
|
|
|
Yes, Borland licensed the standard Microsoft C# compiler for C#Builder. The timing effects you're seeing must be due to other reasons (not that I have any suggestions for you on why you're seeing a difference).
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
[sharp] wrote:
Are you working for Borland ?
He could be but that's ad hominem and irrelevant to the truth or falsity of his claim.
[sharp] wrote:
C# Builder is using csc.exe just like VS.NET
All the more reason why he's asking the question!
Kevin
|
|
|
|
|
What is C# Builder like generally? How do its features compare with VS .NET?
Kevin
|
|
|
|
|
Thanks for all your condemn. And I do not work for Borland. I just want to know the truth.
And thank you for your words, I really learn some new English words! Like "ad hominem". I wonder if you could give me more!
Thanks again!
Let's roll!
|
|
|
|
|
"Ad hominem" is a common logical fallacy. It means saying an argument is false because the person is so and so or because he works for so and so.
For example, suppose Fred writes a paper explaining why global warming is not a severe problem. You then find out that he works for Exxon. So you dismiss his argument. That would be an ad hominem argument. To refute Fred's paper you actually have to examine his reasoning.
Kevin
|
|
|
|
|
I cannot use ildasm.exe to dasm the release version app build by vs.net 2003,but debug version can.
Is there any settings and where?
Thank you!
|
|
|
|
|
I don't have vs.net 2003 on my machine yet....but I can make a guess. I would assume that the Framework has placed the release version of the application into a different set of security settings. It would make sense that I cannot dasm a release build of an application just to insure no one can easily hack my code. It is also possible that there is some minor obfuscation going on as well.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
If it's a user manually logging in, best practice is to just say one or more are wrong and not specify which one which is an ancient method of making life a little harder for hackers.
If it's called through code and you want to report which part failed, is that information not returned by the database driver when you attempt to use it?
In any case if you want to know which one is wrong, you pretty much have to first test if the servername is valid by connecting to it then report if not, if it is valid, try logging in and report if that fails. If it's a SQL server, I suspect there is no way to determine which of the password or user id is the incorrect value since they probably follow the time honored tradition of not reporting which one was wrong for the reason above.
------------
|
|
|
|
|
I have a solution, it may not be the best, but I find it works. Say you have two input boxes, one for login, the other for password. What I did was set up a connection to the database, as usual, but, I made my query find all the usernames that matched the username inputed. If this fails, you know the username is invalid. Else, it will check the password, and you will know then if it is incorrect. Here is the code I used - try to use an error provider rather than the messagebox, but this should explain things a bit better.
string s = "Initial Catalog="+db+";Data Source="+srv+";UID="+uid+";pwd="+ps+"";
cnn.ConnectionString = s;
cnn.Open();
if(TxtUid.Text == Empty || TxtPass.Text == Empty)
{
MessageBox.Show("UserID or Password can not be left blank!","Login Fail",MessageBoxButtons.OK,MessageBoxIcon.Error);
TxtUid.Focus();
}
else
{
sda = new SqlDataAdapter("Select usrPassword, usrFullName from users where usrName = '"+ TxtUid.Text +"'",cnn);
ds = new DataSet();
sda.Fill(ds);
dt = ds.Tables[0];
if(dt.Rows.Count == 0)
{
MessageBox.Show("The username specified does not exist","Login Fail",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
dr = dt.Rows[0];
string pass = dr[0].ToString();
string name = dr[1].ToString();
if(TxtPass.Text == pass)
{
Current.Visible = false;
ApplicationData.userNameConst = TxtUid.Text;
ApplicationData.userNameFullConst = name;
frm.Show();
}
else
{
MessageBox.Show("Password does not match username '"+ TxtUid.Text +"'","Login Fail",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
|
|
|
|
|
Just throwing my 2.5 cents into the conversation. As mentioned earlier, it is best not to ever tell a user if the user or password is incorrect. If you do, you just cut your security drastically. If person that is trying to get into the system finds a name that is valid, then they just have to try figuring out the password. If you just say they entered an invalid user name or password, they will never know when the guess one or the other.
User friendly is fine and long as it does not hinder security.
Rocky Moore <><
|
|
|
|
|
Oh, sorry, thought you wanted to know which one was in error to display a message to the user. Not quite sure then why you would care which one was at fault.
Rocky Moore <><
|
|
|
|
|
Hi
When you show the ICQ window, if it is docked to a side of the screen, all maximized windows shrink to show it all.
How can i do something similar ?
Thanks
|
|
|
|