C++ | How to remove the DataSource from a combobox? - c++

I'm writing a windows forms application in visual studio with c++ and CLR.
And now, i got the following problem:
I read in a file and save all the important informations in a vector.
With a second step, i convert all items to a CLR array and set this array as DataSource.
array<System::String^>^ PREDEFINED = gcnew array <System::String^>(OP->CIS_Values[OP->selectedCIS]->PREDEFINED_order.size());
for (int i = 0; i < OP->CIS_Values[OP->selectedCIS]->PREDEFINED_order.size(); i++) {
PREDEFINED[i] = msclr::interop::marshal_as<System::String^>(OP->CIS_Values[OP->selectedCIS]->PREDEFINED_order[i]);
}
this->comboBox_header_predefinedtypes->DataSource = PREDEFINED;
this->comboBox_header_predefinedtypes->SelectedIndex = -1;
delete PREDEFINED;
After setting the DataSource, it must be possible to remove it. In C# i can do this with
comboBox.DataSource = null;
but how does it work in C++?
I tried the following cases:
comboBox_header_predefinedtypes->DataSource = NULL;
comboBox_header_predefinedtypes->DataSource = 0;
comboBox_header_predefinedtypes->DataSource = -1;
comboBox_header_predefinedtypes->DataBindings->Clear();
comboBox_header_predefinedtypes->Items->Clear();
I tried it with DataBindings before and after DataSource, but i always get the same exception:
System.ArgumentException: "The complex DataBinding accepts as a data source either IList or IListSource"
How can i fix this issue ?
Thx for help.

In C++ CLR you only need to write:
comboBox_header_predefinedtypes->DataSource = nullptr;
and you don't need to write
comboBox_header_predefinedtypes->Items->Clear();
after removing the DateSource to delete the items.

Related

How to get the screen size with C++ builder (Firemonkey)

I know it is a stupid question, but when changing visual libraries I found a "throuble" with FMX...
My problem is: I need to do my own border, so I set the propriety to Border Style:"None", but the application runs in full screen, also covering the windows toolbar, so I would like a way to resize the application form according to the screen eg.:
mainForm->Height = Screen->Height - 10;
It is possible using VCL, but are there any way to do it using FMX library?
The maximum I conquested with FMX is (I don't know how does it returns values, and the kind of values):
Screen->Size(); // TSize
I've also conquested it now, but I have compiler error:
TSize* Tamanho = new TSize;
Tamanho = Screen->Size();
frmPrincipal->Width = Tamanho->Width;
frmPrincipal->Height = Tamanho->Height - 10;
Error:"E2034 Cannot covert 'TSize' to 'TSize*'"
Finally I've tried to put it on frmPrincipal.h, but the same error:
TSize *Tamanho;
PS.: Other possible solutions to solve the "main problem" are acceptable...
Thanks a LOT!
TScreen::Size() return an actual instance of the TSize struct, not a TSize* pointer. You need to change your code accordingly:
TSize Tamanho = Screen->Size();
frmPrincipal->Width = Tamanho.Width;
frmPrincipal->Height = Tamanho.Height - 10;
Alternatively, you can use FMX's Platform Services framework to access the IFMXScreenService interface directly (this is what TScreen::Size() uses internally):
_di_IInterface Intf;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), Intf))
{
_di_IFMXScreenService Svc = Intf;
TPoint size = Svc->GetScreenSize().Round();
frmPrincipal->Width = size.X;
frmPrincipal->Height = size.Y - 10;
}

Unable to set Reporting Services Parameters

I'm generating a reporting services report from an ASP.NET (MVC) based application but am having problems setting the parameters for the report.
I believe the issue has only occurred since we upgraded SQL Server from 2005 to 2008 R2 (and Reporting Services along with it).
The original error encountered was from calling rsExec.Render:
Procedure or function 'pCommunication_ReturnRegistrationLetterDetails'
expects parameter '#guid', which was not supplied.
Debugging the code I noticed that rsExec.SetExecutionParameters is returning the following response:
Cannot call 'NameOfApp.SQLRSExec.ReportExecutionService.SetExecutionParameters(NameOfApp.SQLRSExec.ParameterValue[],
string)' because it is a web method.
Here is the function in it's entirety:
public static bool ProduceReportToFile(string reportname, string filename, string[,] reportparams,
string fileformat)
{
bool successful = false;
SQLRS.ReportingService2005 rs = new SQLRS.ReportingService2005();
SQLRSExec.ReportExecutionService rsExec = new NameOfApp.SQLRSExec.ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Prepare Render arguments
string historyID = null;
string deviceInfo = null;
// Prepare format - available options are "PDF","Word","CSV","TIFF","XML","EXCEL"
string format = fileformat;
Byte[] results;
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
SQLRSExec.Warning[] warnings = null;
string[] streamIDs = null;
// Define variables needed for GetParameters() method
// Get the report name
string _reportName = reportname;
string _historyID = null;
bool _forRendering = false;
SQLRS.ParameterValue[] _values = null;
SQLRS.DataSourceCredentials[] _credentials = null;
SQLRS.ReportParameter[] _parameters = null;
// Get if any parameters needed.
_parameters = rs.GetReportParameters(_reportName, _historyID,
_forRendering, _values, _credentials);
// Load the selected report.
SQLRSExec.ExecutionInfo ei =
rsExec.LoadReport(_reportName, historyID);
// Prepare report parameter.
// Set the parameters for the report needed.
SQLRSExec.ParameterValue[] parameters =
new SQLRSExec.ParameterValue[1];
// Place to include the parameter.
if (_parameters.Length > 0)
{
for (int i = 0; i < _parameters.Length; i++)
{
parameters[i] = new SQLRSExec.ParameterValue();
parameters[i].Label = reportparams[i,0];
parameters[i].Name = reportparams[i, 0];
parameters[i].Value = reportparams[i, 1];
}
}
rsExec.SetExecutionParameters(parameters, "en-us");
results = rsExec.Render(format, deviceInfo,
out extension, out encoding,
out mimeType, out warnings, out streamIDs);
// Create a file stream and write the report to it
using (FileStream stream = System.IO.File.OpenWrite(filename))
{
stream.Write(results, 0, results.Length);
}
successful = true;
return successful;
}
Any ideas why I'm now unable to set parameters? The report generation works without issue if parameters aren't required.
Looks like it may have been an issue with how reporting services passes parameters through to the stored procedure providing the data. A string guid was being passed through to the report and the stored procedure expected a varchar guid. I suspect reporting services may have been noticing the string followed the guid format pattern and so passed it through as a uniqueidentifier to the stored procedure.
I changed the data source for the report from "stored procedure" to "text" and set the SQL as "EXEC pMyStoredOProcName #guid".
Please note the guid being passed in as a string to the stored procedure is probably not best practice... I was simply debugging an issue with another developers code.
Parameter _reportName cannot be null or empty. The [CLASSNAME].[METHODNAME]() reflection API could not create and return the SrsReportNameAttribute object
In this specific case it looks like an earlier full compile did not finish.
If you encounter this problem I would suggest that you first compile the class mentioned in the error message and see if this solves the problem.
go to AOT (get Ctrl+D)
in classes find CLASSNAME
3.compile it (F7)

problems with writing rows to a DataSet in Visual Studio 2010 C++

I am new to Visual Studio 2010 and there seen very few C++ examples of anything on MSDN so would appreciate some help.
I have used the DataSet function from the ToolBox window to create a single table with three columns (for brevity I have left out two of them in the example below.
I am getting the following error:
error C3293: 'Item': use 'default' to access the default property (indexer) for class 'System::Data::DataRow'
Here is the code as generated by VS2010 instantiating the table:
this->GraphInput->DataSetName = L"GraphDataIn";
this->GraphInput->Tables->AddRange(gcnew cli::array< System::Data::DataTable^ >(1) {this->RefElectInput});
//RefElectInput
this->RefElectInput->Columns->AddRange(gcnew cli::array< System::Data::DataColumn^ >(3) {this->RefElect0Av, this->RefElect0Max, this->RefElect0Min});
this->RefElectInput->MinimumCapacity = 7;
this->RefElectInput->TableName = L"RefElecInput";
//
// RefElect0Av
//
this->RefElect0Av->ColumnName = L"RefElect0Av";
this->RefElect0Av->DataType = System::Double::typeid;
Here is the code where I try towrite to the row (I have only shown one column):
DataRow^ myRow;
myRow = RefElectInput->NewRow();
myRow->Item[L"RefElect0Av"] = peUnPackDataRec->saeRefElec0.adfRefElecAv[i];
//the error data is of type doubleoccurs here.
//other column's removed.
RefElectInput->Rows->Add(myRow);
I would be grateful for your assistance.
Thank you Simon
Have you tried:
DataRow^ myRow;
myRow = RefElectInput->NewRow();
myRow->default[L"RefElect0Av"] = peUnPackDataRec->saeRefElec0.adfRefElecAv[i];

Windows Phone 7 Consuming Webservice WSDL

Ok I have written some basic generic webservices before but I have never tried to consume a 3rd party one.
The one I am trying to consume is
http://opendap.co-ops.nos.noaa.gov/axis/webservices/predictions/wsdl/Predictions.wsdl
I am not getting any results back from this what so ever and cannot figure out why.
More odd is it is not even reaching PredictionsClient_getPredictionsAndMetadataCompleted when I put a break point in the code it doesn't even reach it.
Any suggestions would be greatly appreciated
public void Bouy(double meters)
{
PredictionService.Parameters PredictionParams = new PredictionService.Parameters();
PredictionService.PredictionsPortTypeClient PredictionsClient = new PredictionService.PredictionsPortTypeClient();
GeoCoordinateWatcher gc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
//gc.Position.Location.Latitude, gc.Position.Location.Longitude
GeoCoordinate myLocation = new GeoCoordinate(27.931631,-82.802582);
foreach (var bl in BouyLocation.GetAll())
{
GeoCoordinate otherLocation = new GeoCoordinate(bl.Lat, bl.Lon);
PredictionParams.beginDate = DateTime.Now.ToString("yyyyMMdd");
PredictionParams.endDate = DateTime.Now.AddDays(1.0).ToString("yyyyMMdd");
PredictionParams.stationId = bl.LocationID;
PredictionParams.timeZone = 0;
PredictionParams.unit = 1;
PredictionParams.dataInterval = 6;
PredictionsClient.getPredictionsAndMetadataCompleted += new EventHandler<PredictionService.getPredictionsAndMetadataCompletedEventArgs>(PredictionsClient_getPredictionsAndMetadataCompleted);
PredictionsClient.getPredictionsAndMetadataAsync(PredictionParams);
double mymeters = myLocation.GetDistanceTo(otherLocation);
if (mymeters < meters)
{
TextBlock DynTextBlock = new TextBlock
{
Name = "Appearance" + bl.LocationID,
Text = bl.LocationName + PredictionResult,
TextWrapping = System.Windows.TextWrapping.Wrap,
Margin = new Thickness(12, -6, 12, 0),
Style = (Style)Resources["PhoneTextSubtleStyle"]
};
DynamicAppearance.Children.Add(DynTextBlock);
this.nearByLocations.Add(new BouyLocationModel() { LocationName = bl.LocationName, LocationID = bl.LocationID, Lat = bl.Lat, Lon = bl.Lon });
}
}
var test = nearByLocations;
}
void PredictionsClient_getPredictionsAndMetadataCompleted(object sender, PredictionService.getPredictionsAndMetadataCompletedEventArgs e)
{
string err = e.Error.ToString();
PredictionResult = e.Result.ToString();
}
Loooking at the code you have here I think that you have used the importing of a ServiceReference to auto build the classes for you?
Unfortunately I have found that this is rather temperamental on WP7 and the only way I actually got it to work was when I connected it to a Microsoft WCF service. Connecting to anything else just doesn't work.
If you do google searches there are various pages talking about the fact it doesn't work and ways around it (which I couldn't get to work).
However, there are ways around it but it isn't as simple as the auto-generated stuff. Basically you do things manually.
Although there are other ways to manually create the web service what I did was follow the information in the following which worked well: http://zetitle.wordpress.com/2010/10/14/using-reactive-extensions-with-webrequest/
You will need to parse the response yourself but XML to LINQ works really well for this.
Hope that helps, or maybe someone will have the solution as it is something I am interested in knowing how to get working too

edit ListView from C++ clr

I am facing some prob in managed C++, I can fill my ListView , but I am unable to edit specific row at later time
I can fill like
listView1->View = View::Details;
listView1->Columns->Add("S.no",......
ListViewItem^ itmp = gcnew System::Windows::Forms::ListViewItem("100");
ListViewSubItem^ itms1 = gcnew ListViewSubItem(itmp, "12:12:12 PM");
itmp->SubItems->Add(itms1);
listView1->Items->Add(itmp);
I want to implement following VB code in managed C++ , but showing errors
Dim FindlvItem() As ListViewItem // here i am facing problem in conversion to c++ managed
FindlvItem = Me.ListView1.Items.Find("100", False)
FindlvItem(0).SubItems(0).Text = "01:01:01 AM"
I dont want to use foreach loop to save processing
vs.net 2008
You should be able to convert the code almost line for line to C++/CLI. The only problem is that Find will return a collection of list view items, not just a single item.
array<ListViewItem^>^ FindlvItem = ListView1->Items->Find("100",false);
if (FindlvItem->Length == 1)
{
FindlvItem[0]->SubItems[0]->Text = "01:01:01 AM";
} // if found