problems with writing rows to a DataSet in Visual Studio 2010 C++ - 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];

Related

Get the row of the active Excel cell in C++

I can't understand why it gives an error - an incorrect value. The task is to write a comment in the selected cell by the excel user.I'm trying to get the row and column of the active excel cell - I get an error.Please help me!
`
Variant App, Bks, Bk, Shts, Sht, Cll,Active;
MSExcel = Variant::GetActiveObject("Excel.Application");
MyBook = MSBooks.OlePropertyGet("Item",1);
Shts = MyBook.OlePropertyGet("Worksheets");
Sht=Shts.OlePropertyGet("Item",1); //В какую страницу нам вставить значение
Variant row = Sht.OlePropertyGet("Selection").OlePropertyGet("Row");
Variant col = Sht.OlePropertyGet("ActiveCell").OlePropertyGet("Column");
Cll=Sht.OlePropertyGet("Cells").OlePropertyGet("Item",row,col);
Cll.OleProcedure("AddComment", comment); `
I can't understand why it gives an error - an incorrect value.

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

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.

Record with List of Records Unit Test Failing

I have the following records:
namespace FunctionalInnovate.Domain
module Voting=
open System
type Vote = {
VoteId : int
SuggestionId : int
VotePreference : int
}
type Suggestion = {
SuggetionId : int
SuggestionText : string
}
type User = {
UserId : int
Votes : Vote list
}
From these records, I have created the following Unit Test:
module ``Voting Tests``
open NUnit.Framework
open FsUnit
open FunctionalInnovate.Domain.Voting
[<Test>]
let``Get Vote from given SuggestionId``()=
let votePreference = 1
let vote1 = { VoteId = 1; SuggestionId = 34; VotePreference = votePreference }
let vote2 = { VoteId = 2; SuggestionId = 654; VotePreference = votePreference}
let votes = [ vote1; vote2; ]
let user = {UserId = 321; Votes = votes}
Assert.IsTrue(true) |> ignore
I've just changed the Assert statement to something simple at this point as it keeps failing at present. Using ReSharper, when I run the test I get an error. Upon investigation, it appears to be a problem with the List of Votes being assigned to the Votes type within my user declaration. What I find strange though is that if I load all of the types into FSI and then load each line of the test in turn, it works without any errors.
Anyone got any ideas as to why the unit test is failing?
The error ReSharper Test Runner is producing is:
System.MissingMethodException : Method not found: 'Void User..ctor(Int32, Microsoft.FSharp.Collections.FSharpList`1<Vote>)'.
at Voting Tests.Get Vote from given SuggestionId()
As per #Tomas Petricek and #John Palmer's advice, it was an issue with my ''FSharp.Core.dll'' version.
The version of this DLL in my UnitTest project was much older than what was in my Domain project.
All I did to fix it was going into NuGet Package Manager and update that specific package. Upon running my tests again, everything was green and healthy.

How to use excel in MS visual C++

I want to make a windows form app. You can write text in textBox'es and when you press a button, the app would create an excel file and write the text from the boxes. I got only the UI done, I know some basics but I have no idea how to combine MS Visual C++ and Excel.
There's a lot of libraries listed in this answer:
What is a simple and reliable C library for working with Excel files?
In addition "ExcelFormat Library" is basic, but it sounds like it will do everything you need. It's free and easy to use.
And Number Duck is a commercial library that I have created.
This is a C # code taken from https://code.google.com/p/excellibrary/,
Play a bit with this code in VC + + and make it work. :)
Syntax are different but if you think about it you'll see it's all the same. ;)
First you have to download ExcelLibrary.dll file and add it to the Reference Project.
Than add this two lines:
using namespace ExcelLibrary::CompoundDocumentFormat;
using namespace ExcelLibrary::SpreadSheet;
The aim of this project is provide a native .NET solution to create, read and modify
Excel files without using COM interop or OLEDB connection.
Currently .xls (BIFF8) format is implemented. In future .xlsx (Excel 2007) may also be
supported.
Example code:
//create new xls file
string file = "C:\\newdoc.xls";
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet("First Sheet");
worksheet.Cells[0, 1] = new Cell((short)1);
worksheet.Cells[2, 0] = new Cell(9999999);
worksheet.Cells[3, 3] = new Cell((decimal)3.45);
worksheet.Cells[2, 2] = new Cell("Text string");
worksheet.Cells[2, 4] = new Cell("Second string");
worksheet.Cells[4, 0] = new Cell(32764.5, "#,##0.00");
worksheet.Cells[5, 1] = new Cell(DateTime.Now, #"YYYY\-MM\-DD");
worksheet.Cells.ColumnWidth[0, 1] = 3000;
workbook.Worksheets.Add(worksheet);
workbook.Save(file);
// open xls file
Workbook book = Workbook.Load(file);
Worksheet sheet = book.Worksheets[0];
// traverse cells
foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
{
dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
}
// traverse rows by Index
for (int rowIndex = sheet.Cells.FirstRowIndex;
rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
{
Row row = sheet.Cells.GetRow(rowIndex);
for (int colIndex = row.FirstColIndex;
colIndex <= row.LastColIndex; colIndex++)
{
Cell cell = row.GetCell(colIndex);
}
}

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