|
Thanx for the help
I have another problem, when i select from other tables it will automatically add the columns to my dataGridView1, how can I change the header for the new Columns ?
|
|
|
|
|
Even when I use data-bound columns, I almost always make my own columns because there are usually columns in my table that I don't want to be displayed--just there for support data and to composite for virtual columns.
When I make columns this way, I can set data-bound and virtual columns' header texts the same way:
private void InitDGV ()
{
int idx;
m_dgvDisplay.AutoGenerateColumns = false;
DataGridViewImageColumn imgCol = new DataGridViewImageColumn();
imgCol.Name = "Status";
imgCol.HeaderText = "Status";
imgCol.SortMode = DataGridViewColumnSortMode.NotSortable;
idx = m_dgvDisplay.Columns.Add(imgCol);
m_idxStatus = idx;
idx = m_dgvDisplay.Columns.Add("PlayerName", "Player Name");
m_dgvDisplay.Columns[idx].DataPropertyName = "Name";
idx = m_dgvDisplay.Columns.Add("Address", "Address");
m_dgvDisplay.Columns[idx].DataPropertyName = "Address";
DataGridViewTextBoxColumn cityCol = new DataGridViewTextBoxColumn();
cityCol.Name = "City";
cityCol.HeaderText = "City";
cityCol.DataPropertyName = "City";
m_dgvDisplay.Columns.Add(cityCol);
...
m_dgvDisplay.DataSource = m_bsData;
}
--
I've killed again, haven't I?
|
|
|
|
|
I've created a small application that print the content of a treeview and ListBox control.
It work's, but only if "DrawMode" is set to normal, when i try to change the value of this prop to OwnerDrawFixed and add this code :
private void LbDare_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)<br />
{<br />
Rectangle rc = new Rectangle(e.Bounds.X + delta , e.Bounds.Y + delta , e.Bounds.Width-10, e.Bounds.Height-delta);<br />
Console.WriteLine(e.State.ToString());<br />
<br />
StringFormat sf = new StringFormat();<br />
sf.Alignment = StringAlignment.Center;<br />
<br />
LbDare = (ListBox)sender ; <br />
<br />
string str = (string)LbDare.Items[e.Index]; <br />
Font font;<br />
if (TvDoc.SelectedNode != null)<br />
font = new System.Drawing.Font(TvDoc.SelectedNode.NodeFont.Name,TvDoc.SelectedNode.NodeFont.Size, TvDoc.SelectedNode.NodeFont.Style);<br />
else<br />
font = new System.Drawing.Font("Arial", 8);<br />
<br />
if ( e.State == ( DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))<br />
e.Graphics.DrawString( str , font , new SolidBrush(Color.Black), rc);<br />
else<br />
e.Graphics.DrawString( str , font , new SolidBrush(Color.Red), rc);<br />
}
to formatting the text that appears, the preview dialog will replace the content of listbox with a totally-black box.
ps. the code below works only with default setting
<br />
this._controlImage1 = GetImage(tree.Handle, tree.Width, tree.Height);<br />
this._controlImage2 = GetImage(ListB.Handle, ListB.Width, ListB.Height);<br />
<br />
System.Drawing.Size size = new Size(tree.Width + ListB.Width, tree.Height);<br />
Bitmap bmp = new Bitmap(size.Width,size.Height);<br />
Graphics g = Graphics.FromImage(bmp);<br />
<br />
g.DrawImage(this._controlImage1, 0,0,this._controlImage1.Width, this._controlImage1.Height);<br />
g.DrawImage(this._controlImage2, this._controlImage1.Width+1,5,ListB.ClientSize.Width, ListB.ClientSize.Height);<br />
<br />
this._controlImage = bmp;<br />
g.Save();<br />
g.Dispose();<br />
<br />
private Image GetImage(IntPtr handle, int width, int height) {<br />
IntPtr screenDC = GetDC(IntPtr.Zero);<br />
IntPtr hbm = CreateCompatibleBitmap(screenDC, width, height);<br />
Image image = Bitmap.FromHbitmap(hbm);<br />
Graphics g = Graphics.FromImage(image);<br />
IntPtr hdc = g.GetHdc();<br />
SendMessage(handle, 0x0318 , hdc, (long)(0x00000010 | 0x00000004 | 0x00000002));<br />
g.ReleaseHdc(hdc);<br />
ReleaseDC(IntPtr.Zero, screenDC);<br />
return image;<br />
}<br />
Please help me... i'm so confused
Sorry for my little english... i'm italian...
|
|
|
|
|
Your question might be better asked in the ADO.NET[^] forum, since you're not asking for any C# code.
*edit* woops, looks like the forum board moved my message. This was originally in reply to "load + save ADO.NET"
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
-- modified at 12:03 Thursday 6th April, 2006
|
|
|
|
|
guys I have two problems with my report
1- I have 4 tables: university, major, sources and CD they all have universityCode in common, I looked alot to find the code that retrieves the following info from my tables
University.Name, Major.Major, Sources.Name, CD.Number
what's the sql select command for this ?
2- I'm using datagridView to show the results and when I get info from other tables I don't have any control over the header, I mean, because this is added to my grid I cannot set any names for the header, how can I deal with this problem ?
Thanx
Mr.K
|
|
|
|
|
Hello,
I have to import dbf database files to my c# application. what is the best way to do that? I use vs2005 express and I have also the sqlexpress
Regards
Hansjörg
|
|
|
|
|
I want to get the primary Key of the selected row in DataGridView when double clicked ...
You know in .net 1.1 we had a datagrid with DataKeyField property to save a special field of table like primary key field. but in DataGrid 2.0 or in DataGridView 2.0 this property disapeared...
Now! how can I get PK when a row selected ?
www.behzadi.net
-- modified at 10:43 Thursday 6th April, 2006
|
|
|
|
|
hi
Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source.
u can use this
|
|
|
|
|
Hi there, I hope someone can help me regarding a windows form program.
I would like the user be able to press a button on the form and then an OpenFileDialog box opens, the user then selects a file that is at a certain location (similar to attaching a file when sending email). Then he presses another button on the form and a SaveFileDialog box appears letting the user select where he wants to save/move the file he just selected. How is this done? Can someone please help me?
I hope I have explained this clearly enough.
Thanks,
F
|
|
|
|
|
Get the path of the file opened from the OpenFileDialog via openFileDialog.FileName. Store that file name in a variable, let's call it oldPath. In the save file dialog, after the user clicks OK, simply call System.IO.File.Move(oldPath, mySaveFileDialog.FileName);
|
|
|
|
|
Thanks for your answer.
I see that File.Move takes as a parameter the source filename but what about the path? Does the dialog box take care of the path, where to save the file?
Thanks again for your help.
F
|
|
|
|
|
When you retrieve the FileName from either the OpenFileDialog or the SaveFileDialog, it should contain both the path and file name, I believe.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hello,
I'm building an upload tool in c# but I only want to show de directories where the user has access to from the computer he is sitting on.
I made a script that lists al the directories in a treeview, but it gives an error when it comes to a directory where the user had no access to.
(ex. c:/documents and setting/administrator)
Here a sample of my script
private void FillDirectoryTree(TreeView tvw)
{
tvw.Nodes.Clear();
string[] strDrives = Environment.GetLogicalDrives();
foreach (string rootDirName in strDrives)
{
MessageBox.Show(rootDirName);
if(rootDirName == "C:\\")
{
try
{
DirectoryInfo dir = new DirectoryInfo(rootDirName);
dir.GetDirectories();
TreeNode ndRoot = new TreeNode(rootDirName);
tvw.Nodes.Add(ndRoot);
GetSubDirectoryNodes(ndRoot, ndRoot.Text, 1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Application.DoEvents();
}
private void GetSubDirectoryNodes(TreeNode parentNode, string fullName, int level)
{
DirectoryInfo dir = new DirectoryInfo(fullName);
DirectoryInfo[] dirSubs = dir.GetDirectories();
foreach (DirectoryInfo dirSub in dirSubs)
{
if ((dirSub.Attributes & FileAttributes.Hidden) != 0)
{
continue;
}
TreeNode subNode = new TreeNode(dirSub.Name);
parentNode.Nodes.Add(subNode);
if (level < MaxLevel)
{
GetSubDirectoryNodes(subNode, dirSub.FullName, level + 1);
}
}
}
private void tvDestFiles_AfterSelect(object sender, TreeViewEventArgs e)
{
txtTargetDir.Text = tvDestFiles.SelectedNode.FullPath;
}
private void btnUploadFiles_Click(object sender, EventArgs e)
{
List<fileinfo> fileList = GetFileList();
foreach (FileInfo file in fileList)
{
try
{
file.CopyTo(txtTargetDir.Text + "\\" + file.Name, true);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Application.DoEvents();
}
private List<fileinfo> GetFileList()
{
List<string> fileNames = new List<string>();
foreach (TreeNode theNode in tvSourceFiles.Nodes)
{
GetCheckedFiles(theNode, fileNames);
}
List<fileinfo> fileList = new List<fileinfo>();
foreach (string fileName in fileNames)
{
FileInfo file = new FileInfo(fileName);
if (file.Exists)
{
fileList.Add(file);
}
}
return fileList;
}
private void GetCheckedFiles(TreeNode node, List<string> fileNames)
{
if (node.Nodes.Count == 0)
{
if (node.Checked)
{
string fullPath = GetParentString(node);
fileNames.Add(fullPath);
}
}
else
{
foreach (TreeNode n in node.Nodes)
{
GetCheckedFiles(n, fileNames);
}
}
}
private string GetParentString(TreeNode node)
{
if (node.Parent == null)
{
return node.Text;
}
else
{
return GetParentString(node.Parent) + node.Text + (node.Nodes.Count == 0 ? "" : "\\");
}
}
Some help please
Thx
wistiti 5
|
|
|
|
|
You should be able to catch the System.UnauthorizedAccessException to "skip" a directory you don't have access to.
|
|
|
|
|
Hello,
I have a treeview control, that I populate from a table. I have a column that specifies the sort order of the nodes. However when I use insert method, it seems that the treeview control resorts the nodes, and re-indexes the nodes on every insert.
So: If I insert the Node1 with index 3, after insert it's index will become 0.
Is there a way of avoiding that? I am using .NET 2.0 and I can't find the TreeView.Sorted property.
Thank you.
-- modified at 9:44 Thursday 6th April, 2006
|
|
|
|
|
You can't insert at index 3 if there aren't at least 2 nodes yet.
What you should do is select your data from your table ordered by the sort order in the table. So if your table is called Foo, and the Sort Order column is called SortOrder, you would do something like:
SELECT * FROM Foo ORDERBY SortOrder
The results will then come back to you in ascending order (i.e. 0, 1, 2, ...). From there, you can just call treeView.Nodes.Add; no need to deal with insertion since they're all in the correct order already.
|
|
|
|
|
Thank you
I thought of that before, but I thought maybe there was other ways to control the node sorting. But I guess there is only one way to go about it. I actually tried IComparer handler, but it did not work out as I wanted to.
Thanks again.
|
|
|
|
|
There is another way, but it requires more memory allocation and more CPU processing on the client end:
When you read data back from the table, insert it into a System.Collections.Generic.SortedList, where the sorted list's keys are the sort order integers. From there, you should be able to iterate through the sorted list and insert a tree node at each index, as the iterating through the sorted list will be ordered in ascending order based on the sort order (i.e. 0, 1, 2, etc.)
But I would recommend you simply do an ORDERBY on your table to get the results back in the correct order to begin with. Easier that way and less overhead.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Please tell me some websites for programming windows form in .NET
Thanks to kind people.
|
|
|
|
|
codeproject is not enough? try csharpcorner.com, csharphelp.com... use google :]
|
|
|
|
|
Try a look around here:
http://www.windowsforms.com
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
Could you give me title some books to design form like the image at the frontpage of www.windowsforms.net
Thanks a lot
|
|
|
|
|
|
Could you give me the best books in that ?
Thank you very much
|
|
|
|
|
Just about anything by Sells, Richter, Box, and Griffiths should suffice. I'd recommend Ian Griffith's .NET Windows Forms in a Nutshell, but that's just my opinion.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|