POST
|
actually posting the error message would be most helpful. This said looking at your code, you don't seem to make a provision for the layer not being found... Also you seem to be looping through all the layers in the map including the layers inside the composite layers. Then if the layer is composite, you loop through the layers inside that. If the the layer is a featurelayer, you loop again through all the layers on the map again but only the ones at the root level... I don't understand why the code is so complicated. Based on how you described what you want to do, you can create a .net list of Ilayers from all the layers in the map and bind it to your combobox1 and set the name property as the display property. Then when the selection changes, you can use the selected item from combobox1 which is an iLayer, to look through its fields. thanks for your tips it works well. now the code is look like this- private void cmbShape_SelectedIndexChanged(object sender, EventArgs e)
{
combobox2.SelectedIndex = -1;
combobox2.Items.Clear();
string shape = combobox1.Text;
IApplication pApplication = ArcMap.Application;
IMxDocument pMxDoc = (IMxDocument)pApplication.Document;
IActiveView pActiveView = pMxDoc.ActiveView;
IMap pMap = pMxDoc.FocusMap;
IFeatureLayer pFeatLayer = null;
IFeatureClass pFeatClass = null;
IFields pFields = null;
IField pField;
string FieldName;
IEnumLayer pEnumLayer = pMap.get_Layers(null, true);
pEnumLayer.Reset();
ILayer pLayer = pEnumLayer.Next();
while (pLayer != null)
{
string name = pLayer.Name;
if (name == shape)
{
pFeatLayer = (IFeatureLayer)pLayer;
pFeatClass = pFeatLayer.FeatureClass;
pFields = pFeatClass.Fields;
int i = pFields.FieldCount;
for (int j = 0; (j < i); j++)
{
pField = pFields.get_Field(j);
FieldName = pField.Name;
combobox2.Items.Add(FieldName);
}
}
pLayer = pEnumLayer.Next();
}
}
... View more
10-18-2013
09:29 PM
|
0
|
0
|
259
|
POST
|
Hello everyone, I don't get a clue how to resolve a problem. I have a form which have two combobox and a textbox and a button for search option. when I run the app in combobox1 the LAYER names of TOC will populate, when I select a layer in combobox1 then in combobox2 the fields of that layer will populate. but it is not happening in case of GroupLayer the combobox1 works perfect but combobox2 got messy it populates the field name but populates 6 times and in case of FeatureLayer it give an error.following is my code, Please help me- private void cmbShape_SelectedIndexChanged(object sender, EventArgs e) { combobox2.SelectedIndex = -1; combobox2.Items.Clear(); string shape = combobox1.Text; IApplication pApplication = ArcMap.Application; IMxDocument pMxDoc = (IMxDocument)pApplication.Document; IActiveView pActiveView = pMxDoc.ActiveView; IMap pMap = pMxDoc.FocusMap; IFeatureLayer pFeatLayer = null; IFeatureClass pFeatClass = null; IFields pFields = null; IField pField; string FieldName; IEnumLayer pEnumLayer = pMap.get_Layers(null, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) { if (pLayer is ICompositeLayer) { ICompositeLayer pComLayer = (ICompositeLayer)pLayer; int i = pComLayer.Count; for (int j = 0; (j < i); j++) { if (pComLayer.get_Layer(j).Name == shape) { pFeatLayer = (IGeoFeatureLayer)pComLayer.get_Layer(j); } } pFeatClass = pFeatLayer.FeatureClass; pFields = pFeatClass.Fields; int k = pFields.FieldCount; for (int y = 0; (y < k); y++) { pField = pFields.get_Field(y); FieldName = pField.Name; combobox2.Items.Add(FieldName); } } else if(pLayer is IFeatureLayer) { int l = pMap.LayerCount; for (int u = 0; (u < l); u++) { if (pMap.get_Layer(u).Name == shape) { pFeatLayer = (IGeoFeatureLayer)pMap.get_Layer(u); } } pFeatClass = pFeatLayer.FeatureClass; pFields = pFeatClass.Fields; int k = pFields.FieldCount; for (int f = 0; (f < k); f++) { pField = pFields.get_Field(f); FieldName = pField.Name; combobox2.Items.Add(FieldName); } } pLayer = pEnumLayer.Next(); } }
... View more
10-16-2013
08:31 PM
|
0
|
2
|
705
|
POST
|
Thank you very much Jones, that was very helpful for me. Can you help me a little bit more. the sample code gives me that snapping but when i click the mouse button the point was not fall on the point feature, it creates a point where I clicked(just a little bit side). thank you again. Tauhid, The following blog post should help you out: Incorporating snapping into custom tools
... View more
08-28-2012
07:51 PM
|
0
|
0
|
474
|
POST
|
Hello everyone, I have a Point featureclass and a Polyline featureclass. I develop a tool using C# to draw Line in Polyline feature class. now I want to draw line by snapping the point so that i need to set my snapping environment. but found some code in this forum that is not helpful for me. can anyone give me any suggestion or any code sample to set the snapping environment using C# for ArcGIS 10? all the code samples are for ArcGIS 9x i found in the forum. Thanks in Advance. Tauhid GIS Specialist NRECA International ltd.
... View more
08-28-2012
03:41 AM
|
0
|
2
|
2913
|
POST
|
sshety, thanks for your help. can you please give me any suggestion that how can I use this if statement for open the spatial reference dialog box? Again thanks for pointing out the problem.
... View more
06-05-2012
01:36 AM
|
0
|
0
|
358
|
POST
|
hello sshetty, this won't work either. can you give me any other suggestion please? Thanks, Tauhid GIS Specialist NRECA International Ltd
... View more
06-04-2012
01:26 PM
|
0
|
0
|
358
|
POST
|
Dear KenBuja, Thanks for your reply but it won't help me. I am stuc kwith my code. my code is give below:
private void cmdSub_Click(object sender, EventArgs e)
{
string strdatabasePath = "C:\\" + @txtProject.Text + "\\Survey\\Data_Table\\" + @txtDatabase.Text + @txtSub.Text;
if (!Directory.Exists(strdatabasePath) == false)
{
MessageBox.Show("Destination Directory was not Found, Please Create the Directory First");
}
IWorkspaceFactory pWSF = new FileGDBWorkspaceFactoryClass();
Boolean blsWorkspace = pWSF.IsWorkspace("C:\\" + @txtProject.Text + "\\Survey\\GeoDatabase\\" + @txtDatabase.Text + "\\" + @txtDatabase.Text + ".gdb");
if (blsWorkspace == true)
{
IWorkspace pWorkspace = pWSF.OpenFromFile("C:\\" + @txtProject.Text + "\\Survey\\GeoDatabase\\" + @txtDatabase.Text + "\\" + @txtDatabase.Text + ".gdb", 0);
IFeatureWorkspace pfeatureWorkspace = (IFeatureWorkspace)pWorkspace;
IEnumDatasetName pEnumDatasetName = pWorkspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
IDatasetName pDatasetName = pEnumDatasetName.Next();
while (pDatasetName != null)
{
pEnumDatasetName = (IEnumDatasetName)pDatasetName;
string theDatasetName;
int theValue;
Boolean f = groupBox2.Focused;
int theVal = Convert.ToInt32(f);
while (pDatasetName == null)
{
theDatasetName = pDatasetName.Name;
if (theDatasetName == txtSub.Text)
{
theValue = 1;
pDatasetName = pEnumDatasetName.Next();
if (theValue != 1)
{
ISpatialReferenceDialog pSpaRefDlog = new SpatialReferenceDialogClass();
ISpatialReference m_SpaRef = pSpaRefDlog.DoModalCreate(true, true, true, theVal);
}
MessageBox.Show("FeatureDataset Created");
}
else
{
MessageBox.Show("No Spatial Reference Found, Feature Dataset was Not Created");
}
}
}
}
} there is no error shown but the button is not working when i click the button. please help me to solve the problem. can you please give me any suggestion what should I do. Thank in Advance Tauhid
... View more
06-04-2012
11:56 AM
|
0
|
0
|
358
|
POST
|
Hello Everyone, I am new in development with C#. Can anyone please give me any suggestion how can I create spatial reference using spatial Reference Dialogbox using C# code? Thanks in Advance. Tauhid
... View more
06-02-2012
06:28 AM
|
0
|
8
|
691
|
POST
|
Hello John, Thanks for your help, but this wont help either.. My main problem is in the ISpatialReferenceDialog that I am using but it won't work.can you please help me on that part of the code? ISpatialReferenceDialog pSpaRef = new SpatialReferenceDialogClass(); ISpatialReference m_SpaRef1 = pSpaRef.DoModalCreate(true, true, true, Frame1.ActiveControl()); here Activecontrol is not working so that the spatial reference dialogbox won't show up while I was trying to create the feature Dataset inside a fileGeoDatabase using a button click. Tauhid
... View more
05-31-2012
12:44 PM
|
0
|
0
|
366
|
POST
|
Hello Everyone, this is Tauhid from Bangladesh. I am a beginner in ArcGIS development with C#. Now i Am trying to create a featuredataset using ISpatialReferenceDialogBox in a fileGDB. but I am stuck with the code. Of my form the groupbox named as Frame1 which is contain the cmdDataSet button . the code is given Below: private void cmdDataSet_Click(object sender, EventArgs e) { string strdatabasePath = "C:\\" + @txtProject.Text + "\\Survey\\Data_Table\\" + @txtDatabase.Text + @txtSub.Text; if (!Directory.Exists(strdatabasePath) == false) { MessageBox.Show("Destination Directory was not Found, Please Create the Directory First"); } IWorkspaceFactory pWSF = new FileGDBWorkspaceFactoryClass(); Boolean blsWorkspace = pWSF.IsWorkspace("C:\\" + @txtProject.Text + "\\Survey\\GeoDatabase\\" + @txtDatabase.Text + "\\" + @txtDatabase.Text +".gdb"); if (blsWorkspace == true) { IWorkspace pWorkspace = pWSF.OpenFromFile("C:\\" + @txtProject.Text + "\\Survey\\GeoDatabase\\" + @txtDatabase.Text + "\\" + @txtDatabase.Text + ".gdb", 0); IFeatureWorkspace pfeatureWorkspace = (IFeatureWorkspace)pWorkspace; IEnumDatasetName pEnumDatasetName = pWorkspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset); IDatasetName pDatasetName = pEnumDatasetName.Next(); string theDatasetName; int theValue; while (pDatasetName == null) { theDatasetName = pDatasetName.Name; if (theDatasetName == txtSub.Text) { theValue = 1; } pDatasetName = pEnumDatasetName.Next(); } if (theValue == null) { ISpatialReferenceDialog pSpaRef = new SpatialReferenceDialogClass(); ISpatialReference m_SpaRef1 = pSpaRef.DoModalCreate(true, true, true, Frame1.ActiveControl); IFeatureDataset pfeatDataset; while m_SpaRef1 == false { pfeatDataset = pfeatureWorkspace.CreateFeatureDataset(txtSub.Text, m_SpaRef1); MessageBox.Show("FeatureDataset Created"); } MessageBox.Show("No Spatial Reference Found, Feature Dataset was Not Created"); } } } But its not working. It shows error in "ISpatialReference m_SpaRef1 = pSpaRef.DoModalCreate(true, true, true, Frame1.ActiveControl);" this part of code. Can Anyone please give me the solution? I tried to find the solution but can't fix it. Tauhid GIS Specialist NERCA International Ltd
... View more
05-31-2012
03:45 AM
|
0
|
3
|
708
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|