|
Can someone please tell me if I'm approaching this incorrectly (and if so, suggest a better way) or tell me if I just can't do this at all?
I have 3 tables:
Table 1
tableOneID (PK)
displayString
Table 2
tableTwoID (PK)
displayString
tableOneID (FK)
Table 3
tableThreeID (PK)
displayString
tableTwoID (FK)
I want to be able to display the information in 3 combo boxes, filtered by the selection the 'upper' combo boxes. I have a dataset containing 3 datatables and have created relationships between the tables. It all works great for the first two combo boxes (cboTable_2's data is filtered correctly by selection in cboTable_1) but not for the next combo box - I want cboTable_3's data to be populated based on the selection in cboTable_2.
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Table_1", conn);<br />
da.Fill(ds, "Table_1");<br />
<br />
da = new OleDbDataAdapter("SELECT * FROM Table_2", conn);<br />
da.Fill(ds, "Table_2");<br />
<br />
da = new OleDbDataAdapter("SELECT * FROM Table_3", conn);<br />
da.Fill(ds, "Table_3");<br />
<br />
DataColumn masterOne = ds.Tables["Table_1"].Columns["tableOneID"];<br />
DataColumn childOne = ds.Tables["Table_2"].Columns["tableOneID"];<br />
DataRelation relation = new DataRelation("RelationMasterChild", masterOne, childOne);<br />
ds.Relations.Add(relation);<br />
<br />
cboTable_1.DataSource = ds;<br />
cboTable_1.DisplayMember = "Table_1.displayString";<br />
cboTable_1.ValueMember = "Table_1.tableOneID";<br />
<br />
cboTable_2.Datasource = ds;<br />
cboTable_2.DisplayMember = "Table_1.RelationMasterChild.displayString";<br />
cboTable_2.ValueMember = "Table_1.RelationMasterChild.tableTwoID";<br />
<br />
DataColumn masterTwo = ds.Tables["Table_2"].Columns["tableTwoID"];<br />
DataColumn childTwo = ds.Tables["Table_3"].Columns["tableTwoID"];<br />
relation = new DataRelation("RelationChildChild", masterTwo, childTwo);<br />
ds.Relations.Add(relation);<br />
<br />
cboTable_3.Datasource = ds;<br />
cboTable_3.DisplayMember = "Table_2.RelationChildChild.displayString";<br />
cboTable_3.ValueMember = "Table_2.RelationChildChild.tableThreeID";
The problem: On load this data is displayed correctly
cboTable_1 filters data in cboTable_2 which in turn filters data in cboTable_3
but when cboTable_1 and/or cboTable_2 selection is changed, cboTable_3 is not updated
Thanks for any input.
modified on Sunday, March 2, 2008 11:17 AM
|
|
|
|
|
Hi,
I want to use SHGetFileInfo from shell32.dll u can pass string or pidl(ITEMIDLIST structure) for first param the problem is: u can't convert string (file path) to pidl or vice versa. so I use IntPtr for first param. but the problem is I can't convert pidl to IntPtr.
(the problem is the code below doesn't work I can't find out why)
public class FileFolder<br />
{<br />
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]<br />
public static extern UInt32 SHGetFileInfo(IntPtr pszPath, UInt32 dwFileAttributes, ref SHFILEINFO psfi, UInt32 cbFileInfo, UInt32 uFlags);<br />
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]<br />
public static extern Int32 SHGetSpecialFolderLocation(IntPtr hwndOwner, int nFolder, ref ITEMIDLIST ppidl);<br />
<br />
[StructLayout(LayoutKind.Sequential, Pack = 1)]<br />
public struct SHITEMID<br />
{<br />
public UInt16 cb;<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]public SByte[] abID;<br />
}<br />
[StructLayout(LayoutKind.Sequential, Pack = 1)]<br />
public struct ITEMIDLIST<br />
{<br />
public SHITEMID mkid;<br />
}<br />
<br />
<br />
<br />
}<br />
<br />
<br />
uint flag = FileFolder.C_GetFileInfoFlagt.SHGFI_PIDL| FileFolder.C_GetFileInfoFlagt.SHGFI_ICON | FileFolder.C_GetFileInfoFlagt.SHGFI_SHELLICONSIZE | FileFolder.C_GetFileInfoFlagt.SHGFI_ATTRIBUTES | FileFolder.C_GetFileInfoFlagt.SHGFI_TYPENAME;<br />
<br />
FileFolder.ITEMIDLIST pidl = new FileFolder.ITEMIDLIST();<br />
if (FileFolder.SHGetSpecialFolderLocation(IntPtr.Zero, (int)0x0003, ref pidl) == 0)<br />
{<br />
MessageBox.Show("true");<br />
}<br />
<br />
IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(pidl));<br />
Marshal.StructureToPtr(pidl, pnt, true);<br />
if (FileFolder.SHGetFileInfo(pnt, 256, ref info, (uint)Marshal.SizeOf(info), flag) > 0)<br />
{<br />
MessageBox.Show("Successfull");<br />
}
|
|
|
|
|
Wow! it sometimes works ! a few times it is failed. I can not find out why! plz help!
|
|
|
|
|
Haven't tried it but this[^] may help
Dave
|
|
|
|
|
No, It doesn't help. because it assumes just file system paths not pidl!. you can not convert every pidl to string.
|
|
|
|
|
|
thanks,
I see the code but I can't find out why my code doesn't work properly. my code is like the code in the page that you mention. (the caller is not presented in the page just callee is presented)
modified on Friday, March 7, 2008 5:01 AM
|
|
|
|
|
Hello Amirreza_nl,
I wrote the code that was alluded to earlier in this thread (from CodeGator.com). You are correct that your code is similar to mine, however I am calling a slightly different method to get the path from the PIDL. In my case I am using the SHGetPathFromIDList function. Also, my code doesn't convert from the InPtr to a ITEMIDLIST structure. I am able to deal with PIDL's as IntPtr objects instead of converting them to ITEMIDLIST structures. (See my code here)
You don't say which call is failing in your code, is it SHGetSpecialFolderLocation or SHGetFileInfo?
My suggestion would be to try omiting the conversion of the PIDL to a struct if possible.
I hope I have helped,
Martin
Martin Cook
Jesus answered, "I am the way and the truth and the life. No one comes to the Father except through me." John 14:6
|
|
|
|
|
Hi,
first of all, thanks for ur reply. I think SHGetFileInfo doesn't work well. because the first call's return value is ok. but SHGetFileInfo's return value sometimes is not ok. I run the code 2 or 3 times then it works well and show control panel's (or something else) attributes correctly! I don't know why!
SHGetPathFromIDList doesn't work at all with something like control panel (I think). we can use it when pidl is controled by file system(file or folder that is stored physically in a hard disk). so I can not use it for my app.
typedef struct _SHITEMID {<br />
USHORT cb;<br />
BYTE abID[1];<br />
} SHITEMID;
I wrote this in C#:
[StructLayout(LayoutKind.Sequential, Pack = 1)]<br />
public struct SHITEMID<br />
{<br />
public UInt16 cb;<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]public SByte[] abID;<br />
}
then
typedef struct _ITEMIDLIST {<br />
SHITEMID mkid;<br />
} ITEMIDLIST;
in C#:
[StructLayout(LayoutKind.Sequential, Pack = 1)]<br />
public struct ITEMIDLIST<br />
{<br />
public SHITEMID mkid;<br />
}
|
|
|
|
|
oh, I think I find the bug in my code!
I write:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
but I must write:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
instead.
I use unicode charset for my all methode definitions.
But I wonder why this makes a problem! we have two types of pidl!? on for ansi one for unicode!? why? in pidl address we have string!??
|
|
|
|
|
I am Bang Hoang Viet. I am Vietnamese. My English isn't good. I use datagridview to display data of SQL 2000 database. My data source have a lot of rows. I need view record_id 1500 on screen but i don't know how to. Nomarly I scroll datagridview go to record_id 1500 to confirm by my eyes on screen. Someone help me catch pages's record_id 1500 and display auto on screen.
Soon!
Thank very much for help me!
|
|
|
|
|
|
Thank very much!
That I known. My problem have been I had listed datagridview's record then I modify record's ID 1500. Then I upgraded database and reconnect data source to view datagridview. I want catch record's ID 1500 and view on screen and see I have modified that record. So can you help me resolve this problem.
Waitting for you and thank you very very much!
|
|
|
|
|
Can someone please help me to open a file in the application using openFileDialog. I have a button "Open File" > which then opens an openFileDialog window, I then select the file and click Open, but it does not want to open. I do get the path and everything, but it does not want to open. Maybe I am using the wrong code. Here is a snippet of my code:
//Opens the file and populates the datagrid
private void btnOpenFile_Click(object sender, EventArgs e)
{
ofdExcelDoc.Filter = "xls files (*.xls)|*.xls|All files (*.*)|*.*";
if (ofdExcelDoc.ShowDialog() == DialogResult.OK)
{
ofdExcelDoc.OpenFile();
try
{
// Attempt to open the file and output its contents to a text box
Stream stream;
if ((stream = ofdExcelDoc.OpenFile()) != null)
{
StreamReader reader = new StreamReader(stream);
//dgFileInfo.DataSource = reader.ReadToEnd();
txtOutput.Text = reader.ReadToEnd();
stream.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("There was an Error: " + ex.Message);
}
}
}
}
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
remove the first occurance of ofdEcvelDoc.OpenFile();
|
|
|
|
|
I removed that line but it is still not opening (the file/doc does not get opened)
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
replace
ofdExcelDoc.OpenFile();
with
System.Diagnostics.Process.Start(ofdExcelDoc.FileName);
i hope it will work
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
it worked, thanx
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
glad to know
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
this is first time im posting here... i need some help about explosion or particle system. if anybody have website, ebook or sample project about explosion, can u share with me...i need more information and sample coding about explosion or particle.
because i need that to finish my final project..my final project about explosion modeling using xna.
|
|
|
|
|
|
|
hi,
i'm having a strange problem withe datagridview
i'm designing with right to left
i've have this kind of a table
column1 - column5 are textbox cell
column 6 and 7 are button cell
now the problem is that when i'm in .cs[Design] the buttons "Jumps" to be in 1st and 2nd column
like the index is autometiclly changed to be the 1st and the 2nd column
i've changed the view back to left to right but still tha problem stays
help!!!, what am i doing wrong?
Have Fun
Never forget it
|
|
|
|
|
just change thier order in Columns property
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
i know that
but it's like an anoying dog that always return after you send him away
Have Fun
Never forget it
|
|
|
|