|
I have been struggling for a long while now trying to get a simple table to display in a data grid view on a C# windows form.
I believe I am doing something wrong but...I can't see where I am straying. All of the examples and sample files essentially tell me to create a new data source and then drag the table I want to use onto the forms designer and wa-la! but it isn't working for me. I can preview the data in the table and I see the records there, but running the form shows a blank grid and a -1 shows when I click in the grid.
Can anyone lend some advice? I am using VS2008 SP1 and Access 2007 on a Windows7 machine. I also tried with the exact same results SQLExpress 2008.
Jeff
|
|
|
|
|
Hi,
maybe the bind-command is missing within the source code. Could you post a bit of your code? Maybe the code within the designer.cs where the grid is constructed.
For a detailed example have a look here:
http://69.10.233.10/KB/vb/DataGridViewEditForm.aspx[^]
Regards
Sebastian
|
|
|
|
|
If I understand correctly,
below is the code from the frmMain.designer.cs file. I am a bit confused over this whole thing as to what does what and why. If you have a good reference resource that might help me I would appreciate it, so that I don't use too much of your time. I have Murach's C#2008 and SQL Server 2008 for Developers as well as a number of older MS Press books for C#. The MSPress books are all quite dated and a bit sparse for database information.
<pre>//
// tasksBindingSource
//
this.tasksBindingSource.DataMember = "Tasks";
this.tasksBindingSource.DataSource = this.timeSheetDataSet;
...
...
...
//
// tasksDataGridView
//
this.tasksDataGridView.AutoGenerateColumns = false;
this.tasksDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.tasksDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.dataGridViewTextBoxColumn1,
this.dataGridViewTextBoxColumn2,
this.dataGridViewTextBoxColumn3});
this.tasksDataGridView.DataSource = this.tasksBindingSource;
this.tasksDataGridView.Location = new System.Drawing.Point(36, 195);
this.tasksDataGridView.Name = "tasksDataGridView";
...
...</pre>
Thanks for the time and the help.
Jeff
|
|
|
|
|
Hi Jeff,
I was searching the missing DataBind()-method call as carlecomm already suggested. So I guess using the answer of carlecomm it worked.
There are plenty of examples around but I would suggest you take a look at the msdn sample:
http://msdn.microsoft.com/en-us/library/1x64c23x.aspx[^]
Regards
Sebastian
|
|
|
|
|
Hi, guy, there are codes bellow, you can try to bind GridView firstly.
dataGridView1.DataSource = datatable1;
dataGridView1.DataBind();
modified 27-May-14 5:05am.
|
|
|
|
|
Thanks for the advice, but...
I am not sure how to implement your samples. I am using the "built in" features that generate the code automatically and it looks like the lines you suggest are being called... except for the DataBind() function. it doesn't appear to be an option for this grid control.
Thanks again for the help
Jeff
|
|
|
|
|
Hi all,
I need to process a list of opened excel files. The excel files are already opened by user, and not through any code(at least not through my C# code).i.e if a user has opened 2 excel files, I need my code to detect these 2 opened excel files.
I have tried "google" the problem, but...
Thanks.
|
|
|
|
|
Will your program be - or can it be - running when the user opens the files in Excel? Do you know the location from where they will be opened, for example if they are all in the same folder or some known set of folders? If yes to both you can use a FileSystemWatcher and know when the files are opened that way (or saved, for that matter). You won't know just from this what app they opened the file with, but depending on your scenario this could be enough.
By the way, it seems to me to make more sense to process the files when they are saved than when they are opened. Multiple processes cannot write safely to the same file at the same time without synchronization, so unless the user always opens the workbooks read-only you already have a fundamental problem right here to solve before trying to find out the details of how to do things.
|
|
|
|
|
"Will your program be - or can it be - running when the user opens the files in Excel?"
Yes can be running but it doesn't matter what/which file opens because I need only those files that were open when my code was run.
"Do you know the location from where they will be opened, for example if they are all in the same folder or some known set of folders?"
No. It could be from anywhere on the machine.
As for the last part, I am not worried about synchronization, because it is taken care of. All I need is a snapshot of the files opened by a particular application at a point of time when the code is run.
thanks...
|
|
|
|
|
where can i download the crystal report?i download some ,but it do not work!thanks everyone!
|
|
|
|
|
miss YY wrote: where can i download the crystal report?
http://www.crystalreports.com/[^]
and this is the c# forum - thats a bit different to 'Crystal Reports' .. I suggest if you license the product you go back to the support service if you have other issues with the product itself - of course if you get the software from a dubious source, dont license it etc etc, you deserve everything you get IMNSHO ...
'g'
|
|
|
|
|
Hey,
I am running into a weird problem. I am using below method to extract country location based on IP address.
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
m_IPAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
{
m_IPAddress = HttpContext.Current.Request.UserHostAddress;
}
DataTable dt = GetLocation(m_IPAddress);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
m_IPCountry = dt.Rows[0]["City"].ToString() + "," + dt.Rows[0]["RegionName"].ToString() + "," + dt.Rows[0]["CountryName"].ToString() + "," + dt.Rows[0]["CountryCode"].ToString();
}
else
{
}
}
private DataTable GetLocation(string ipaddress)
{
WebRequest rssReq = WebRequest.Create("http://freegeoip.appspot.com/xml/" + ipaddress);
WebProxy px = new WebProxy("http://freegeoip.appspot.com/xml/" + ipaddress, true);
rssReq.Proxy = px;
rssReq.Timeout = 2000;
try
{
WebResponse rep = rssReq.GetResponse();
XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());
DataSet ds = new DataSet();
ds.ReadXml(xtr);
return ds.Tables[0];
}
catch
{
return null;
}
}
when i try to catch the exception i get error msg "The remote server returned an error: (503) Server Unavailable."
the website is hosted in australia. I am logging all the details in database. IP address is correct at all time just after midnight in australia i am able to get country information while during the day it becomes null. any idea what am i doing wrong. probably need to add something in web.config?
modified on Tuesday, January 5, 2010 8:47 PM
|
|
|
|
|
I cut and pasted your url [http://freegeoip.appspot.com] into a browser and received :-
"App Engine Error
Over Quota
This Google App Engine application is temporarily over its serving quota. Please try again later. "
so is there a possibility its being hammered at some stage of the day and when you want to access it its already 'over quota' ?
'g'
|
|
|
|
|
is there a work around to get a country details based on IP without using this service?
|
|
|
|
|
undoubtedly there are other services 'out there' or other databases - wether they are free or not, remains to be seen
'g'
|
|
|
|
|
|
I tried to implement this solution http://dotnetguts.blogspot.com/2008/06/finding-country-from-visitors-ip-in.html[^]
i didnt use the last step to import database as I only need a country code not flag but its not working. since in the example its using a aspx page to display but in my case I have a all the page which is derived from basepage.cs
in basepage.cs I am trying to get a countrycode and store in a database as a pageview record.
could you please help as to why its null. I am not missed any of the steps mentioned in the article.
Thank you
|
|
|
|
|
|
actually, all the free web services seems to reject request after it reaches certain daily hits. which in my case is true. if google crawls my site i am using the service to get the country code so i gave up on using free webservice to get a country code based on IP. I used this one http://dotnetguts.blogspot.com/2008/06/finding-country-from-visitors-ip-in.html[^]
but its getting a wrong country codes for example in below. I am using my iphone which is in sydney, australia, its logging country code as FR. could someone please help?
58.104.249.183 FR Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16
|
|
|
|
|
good question. 5!
some one has a solution here.
Another solution here.
♫ 99 little bugs in the code,
99 bugs in the code
We fix a bug, compile it again
101 little bugs in the code ♫
|
|
|
|
|
Hi everyone,
My name is Susan and I work for an outside vendor who was hired by SAP BusinessObjects to learn more about what people are saying about CrystalReports in the social media space. I was hoping you could give me some feedback on what your initial thoughts are about CrystalReports. Do you like the product? Do you have any issues with the product? What are your reasons for coming to this message board?
Any feedback would be much appreciated. Thank you!
- Susan
|
|
|
|
|
This would be better asked in The Lounge[^] IMO as it's not really a programming question directly related to C#
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks Dave, I'll post there!
- Susan
|
|
|
|
|
I am wondering how to create a key container on a machine that only my application can access. I have successfully created and used the container, but I think that other users and applications on the machine have access to the private key. Is there any way to protect this information? The code used to generate and utilize the CspParameters object is below:
CspParameters csp = new CspParameters();
csp.Flags = CspProviderFlags.UseMachineKeyStore |
CspProviderFlags.UseNonExportableKey;
csp.KeyContainerName = "Example Container Name";
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(1024, csp); Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Guys,
I`m working on a Windows application and running into a problem, can`t seem to figure it out. Let me first explain the app. Its a windows forms application with a Tab Controls. Each Tab Control is a single file and has other controls within it [tabcontrols, buttons, etc etc]. Based on the file extension only the First tab within the Tab Control changes everything else remains the same. Lets say like a Web browser with Tabs.
The problem I`m running into is - How do I stop duplicate tabcontrols [each tab control is a file] from opening. Lets say I load a file ABC.opt how do make sure ABC.opt is not loaded again..i.e, open by the software. I can load files now, but can`t seem to control the duplicates.
Also, when i Save a file..I want only the contents of the Tab Control open to be saved. Is there a Tab Control active property? What is the best way to do it. Something like a Web Browser..Lets say you open a website in a tab and click on Save on the Menu Strip, only the active Tab is saved.
Here is the code I`m working on.
//File Item Clicked from the MainMenuItem - This has File New, File Open, Save, Save As, etc
private void FileToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
FileToolStripMenuClicked(e.ClickedItem);
}
//FTSI - File Tool Strip Item Clicked
private void FileToolStripMenuClicked(ToolStripItem FTSI)
{
switch (FTSI.Name)
{
case "FileOpenTSMI":
// FileOpen.cs
FileOpen FO = new FileOpen();
FO.OpenFile();
break;
case "FileSave"
//See comments in ABCOpen
//Code here
break;
default:
break;
}
}
//Based on the Extention of the file the ABCOpen() or XYZOpen() functions are called
internal void OpenFile()
{
OpenFileDialog OFD = new OpenFileDialog();
OFD.InitialDirectory = @"C:\Cust";
OFD.Filter = "ABC Files|*.abc|XYZ Files|*.xyz";
OFD.CheckFileExists = true;
OFD.CheckPathExists = true;
OFD.RestoreDirectory = true;
if (OFD.ShowDialog() == DialogResult.OK)
{
switch (Path.GetExtension(OFD.FileName).Substring(1))
{
case "abc":
ABCOpen(OFD.FileName);
break;
case "xyz":
XYZOpen("OFD.FileName");
break;
default:
break;
}
}
}
private void ABCOpen(string FileName)
{
// Code here loads some User Controls
// Code here reads a File and then loads the data into Windows forms
// How do I save it in such a way that only the active tab control data is saved
// Lets say I loaded Sample.abc and Test.xyz. I edit Sample.abc and it is the active Tab, and when I hit save how can I make sure only Sample.abc data is written into the file?
}
Any ideas, help are greatly appreciated.
Thanks!
|
|
|
|