|
I have a DataGridView on a form which is populated through databinding from a table in my database. I've followed, more or less, the process outlined on this MSDN page[^]
I've implemented the databinding both ways so that, by clicking on an "Update" button, the changes that have been made on the DataGridView is stored back into the DB. All works well, but...
Imagine the table used for the databinding being something like this:
USERS
- UserID (INT)
- UserName (VARCHAR)
- UserType (INT)
And here's the problem, that UserType field references the identifier in a separate table like this one:
USERTYPES
- UserType (INT)
- UserTypeDescription (VARCHAR)
Currently, my databinding is done with a simple query like this:
SELECT * FROM USERS;
The problem is that the value displayed in the third column is an integer which means nothing to the end user. If I wasn't interested in two way databinding but only wanted to display the contents of the table in the DataGridView I could easily have overcome that problem by using the following query:
SELECT UserID, UserName, UserTypeDescription FROM USERS INNER JOIN USERTYPES ON USERS.UserType = USERTYPES.UserType;
Unfortunately I need for the end user to be able to change that value and I'd like to put a ComboBox in all the cells of that column which is populated from the USERTYPES table.
Would really appreciate some advice.
***EDIT***
Maybe I should add that I have some experience with adding a ComboBox (rather a DataGridViewComboBoxCell) in a DataGridView but that has always been to DataGridViews that have not been databound to a table.
Here's how I would've done that:
private void myDataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
for (int row = 0; row < (sender as DataGridView).Rows.Count; row++)
{
DataGridViewComboBoxCell newCell = new DataGridViewComboBoxCell();
using (SqlCommand sqlCommand = new SqlCommand("SELECT UserType, UserDescription FROM UserTypes", mySQLConnection))
{
using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
{
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
ds1.Tables.Add(dt1);
ds1.Load(sqlDataReader, LoadOption.PreserveChanges, ds1.Tables[0]);
newCell.DataSource = ds1.Tables[0];
newCell.DisplayMember = "GroupName";
newCell.ValueMember = "GroupID";
}
}
newCell.Value = myDataGridView.Rows[row].Cells["UserType"].Value;
myDataGridView.Rows[row].Cells["UserType"].Value = newCell;
}
}
That final line of code generates an ugly exception which I can only assume is because the DataGridView is bound to a table in the DB because in other projects I've used this code successfully.
The exception that I get is:
Unable to cast object of type 'System.Windows.Forms.DataGridViewComboBoxCell' to type 'System.IConvertible'.Couldn't store <DataGridViewComboBoxCell { ColumnIndex=-1, RowIndex=-1 }> in ConnectGroupID Column. Expected type is Int32.
modified 27-Jul-12 8:37am.
|
|
|
|
|
Hello Folks,
If anyone know code to make gridview as rounded corner, Plz help Me.
Thanks
|
|
|
|
|
It would appear that lots of people do[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi,
Below link will generate round corner Div. you can apply it for your gridview by little modification.
CSS generator to round corner[^]
Thanks
-Amit
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
I have frmSearchResult and showing it from frmMain like this:
is_form_exists = false;
foreach (Form search_form in this.MdiChildren)
{
if ((string)search_form.Tag == "BROWSE_PATIENTS")
{
search_form.Activate();
is_form_exists = true;
break;
}
}
if (is_form_exists == false)
{
frmSearchResult SearchResultForm = new frmSearchResult(public_var);
SearchResultForm.Tag = "BROWSE_PATIENTS";
SearchResultForm.MdiParent = this;
SearchResultForm.Dock = DockStyle.Fill;
SearchResultForm.find_what = "FILE";
SearchResultForm.find_text1 = (sender as TextEdit).Text.Trim();
SearchResultForm.find_text2 = null;
SearchResultForm.Show();
}
and in frmSearcResult_Activate event I am running a coded to populate data.
My problem now, if the form already exist and I am passing vartiable from my frmMain to it then it will not refresh but it will just activate the frmSearcResult form.
How can I solve this?
|
|
|
|
|
Refresh (repopulate) the data right after the Activate, and before the break.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
how?
my code in frmSearcResult is public like this:
public void browse_result()
{
......
}
but when i try to run it after the
search_form.Activate();
search_form.browse_result();
is_form_exists = true;
break;
It doesn't requires it!
|
|
|
|
|
Means you'll probably have to move the initialization-code from the constructor to some public method, so that you can invoke that method on an existing object.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I have a question.
How can I pass value to find_what, find_text1and find_text2 in this code:
if ((string)search_form.Tag == "BROWSE_PATIENTS")
{
search_form.Activate();
is_form_exists = true;
break;
}
|
|
|
|
|
jrahma wrote: How can I pass value
Add a parameter to the method;
public class SearchResultForm: Form
{
public void SetSomeStuff(string WHAT, string t1, string t2)
{
this.find_what = WHAT;
this.find_text1 = t1;
this.find_text2 = t2;
}
}
..and it goes like this;
SearchResultForm.SetSomeStuff("FILE", (sender as TextEdit).Text.Trim(), null);
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
How can I att-- title explains.
|
|
|
|
|
I don't think that's possible at all[^] with managed code.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Maybe you get me wrong, what I want to do is that realize what "messages" are windows sending, like spy++
|
|
|
|
|
Member 8551910 wrote: Maybe you get me wrong
I didn't
Member 8551910 wrote: what I want to do is that realize what "messages" are windows sending, like spy++
Spy++ is not written in a managed language.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
You can't do it in managed code. That's a little technique call "DLL injection", which cannot be done in managed code because .NET does not support the exports required to pull it off.
You can still do what you want, just not in C#. It has to be done in C/C++.
|
|
|
|
|
Oh well now im sad.
btw, @dave is target app able to tell if dll is injected to them ? I mean obviously they do but is it like "hey my variable just froze, there must be an injected dll" or they somehow instantly realize ? (talking about big cheat protection systems like vac)
My hopes alredy in toilet now so im just wondering...
|
|
|
|
|
No, there is no way for the target application to know that it's had some DLL injected into it.
|
|
|
|
|
hi,
I have a C# app that access MSSQL 2000 via web service calls to retrieve/update some records. This app has been working well in Windows XP. The web services are also developed in C#. The MSSQL database is residing in a separate server.
Recently, I copy and run this app in a Windows 7 laptop. The time to retrieve/update some records has grown exponentially! It took almost 20 minutes to insert 1000 records, and almost 1 hour to insert 3000 records. These same functions could be carried out in less than 10 seconds in Windows XP.
I tried disabling IPV6, autotuning in the Windows 7 laptop, but that did not help. Any idea what could be the cause of such slowness and any suggestion to solve this strange behaviour is much appreciated.
Thanks!
|
|
|
|
|
There's really is not enough information to answer this question at all. Anything anyone says is purely guess work.
But, first things first. Was the laptop connected to the network over wireless or wired?? Do it on wired network and see what happens. Wireless can be excruciatingly slow compared to wired.
|
|
|
|
|
hi Dave,
Thanks for the response.
I have tried both wired and wireless network, and the results are the same. Please note the MS SQL2000 server, the web services and the C# application are running within an intranet.
I could not understand why a C# app running on a higher end Windows 7 OS laptop (higher processor, ram etc) could lose out to an old Windows XP OS laptop, in terms of accessing the database records.
Please note that the testing environment for both laptops are the same: MS SQL 2000 Server and web service running on Windows 2000 server. I am just running a C# application on both laptops that access the database via the web services.
Do I need to add additional libraries or something for the Windows 7 OS? I am really at a loss where / which direction should I be looking to troubleshoot the problem.
|
|
|
|
|
There are no additional libraries. Chances are really good it's something O/S related, not your code. The onyl thing I can think of is make sure the machine is patched up to latest, including IE patches.
|
|
|
|
|
Hello everyone
This is a program for downloading a file from a url
when i download a file i got a error like access to the path is denined can any one tell me why this happen
This is my code.
<pre lang="c#">
public static void Download(String strURLFileandPath, String strFileSaveFileandPath)
{
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(strURLFileandPath);
HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
Stream str = ws.GetResponseStream();
byte[] inBuf = new byte[100000];
int bytesToRead = (int)inBuf.Length;
int bytesRead = 0;
while (bytesToRead > 0)
{
int n = str.Read(inBuf, bytesRead, bytesToRead);
if (n == 0)
break;
bytesRead += n;
bytesToRead -= n;
}
try
{
FileStream fstr = new FileStream(strFileSaveFileandPath, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(inBuf, 0, bytesRead);
str.Close();
fstr.Close();
}
catch (Exception e) {
MessageBox.Show(e.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (phpurl.Text == "") {
MessageBox.Show("Invalid Url");
}
else if (Uri.IsWellFormedUriString(phpurl.Text, UriKind.Absolute) == false)
{
MessageBox.Show("Invalid Url");
}
else {
Download(phpurl.Text, @"D:\test");
}
}
Also this is my manifest file
="1.0"="utf-8"
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</asmv1:assembly>
Please help me..
Thanks in advance.
|
|
|
|
|
The local user does not have the right to write to that particular location on the D drive.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
What line does this exception occur on??
Either the URL you've specified doesn't exist or you don't have permissions to see it or the filepath that you're writing to doesn't exist or you don't have permissions to write to it.
I think the meaning of the error is pretty obvious, given your code.
|
|
|
|
|
Dave Kreskowiak Thanks for your replay
this is the line exception occur.
FileStream fstr = new FileStream(strFileSaveFileandPath, FileMode.OpenOrCreate, FileAccess.Write);
Please help me.
Thanks in advance
|
|
|
|