|
In the link (DataTable.Select Method (System.Data) | Microsoft Docs[^]) I can only find these prototypes:
Select()
Select(String)
Select(String, String)
Select(String, String, DataViewRowState) How can I supply a delegate using any of those methods?
I guess a workaround would be to create a hidden column named ShowThisRow and run through it with a for-loop and set the value to either true or false and then apply the standard string expression filters on that column. But it doesn't feels like it's the right way to do it, there must be a better solution to this (probably using a different class than DataTable to hold the data).
|
|
|
|
|
When I was googling I came across this video Created by Camtasia Studio 3[^] and 6 minutes into to it the programmer adds a delegate that would fit my needs perfectly. But I guess I must have misunderstood something, I thought this was included directly in .NET without writing extra code.
|
|
|
|
|
That's using a custom class which adds support for filtering with a delegate:
BindingListView[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I think it seems really great, but I don't seem to able to add rows after the DataGridView has been initialized. Nothing happened when I added an object to my source List<> and BindingListView does not have an Add-method. It has a AddNew-method, but that bring up a file browser dialog!?!?
|
|
|
|
|
As far as I can see, there's nothing in that library which would show a file browser dialog. You'll need to debug your code to see what's happening.
From what I can see, if you want it to reflect changes made to the underlying list, you'll need to pass in a BindingList<T>[^] instead of a List<T> .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you, that worked great!
|
|
|
|
|
You can pass in a row filter to the DataView constructor, but it has to be a string using the Expression Syntax[^]; you can't pass in a custom delegate.
The BindingSource has a Filter property[^], but again it's a string using the same syntax.
In WPF, you can supply a filter delegate to the ICollectionView . But that's not much help if you're using Windows Forms.
You could obviously select the filtered rows using LINQ, and even use the CopyToDataTable extension method to create a new DataTable from the filtered rows. But then you'd have to change the data source every time the filter changed, and you'd lose the connection to the original rows.
I don't think there's a good answer for this.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I want to display a number of files (=the path and file name) in a table (DataGridView or similar). However, I do not have all the files in a single List (or array), instead I have a List of ParentClass objects that each contains a list of ChildClass objects and then finally each ChildClass object contains a List of files. Can I show these files in a table, preferrably using BindingSource, or it is impossible since not all the files are not in a single List?
|
|
|
|
|
It's not impossible, but a single control only has one BindingSource, so you can't just "set it and go" - you will have to create your table manually, and add each row yourself. You can then use the table as a BindingSource to display it all together.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
What are the benefits of using BindingSource to display the data? Would it, for example, enable me to use the filter functionality of BindingSource? Does this approach mean I basically first construct an array with all the files and then bind that array to the table? If so, how can I go from a cell (row number and column number) to the parent and child objects?
modified 22-May-20 3:23am.
|
|
|
|
|
I have seen some examples on the Internet where there are expandable/collapsible rows in the DataGridView. Maybe such an approach would suit my needs better. Could I then use the BindingSource?
|
|
|
|
|
|
I plan so show more in the table than just the file name and path, I just simplified the scenario to cut to the core of the problem. So, I don't think I can solely use a tree, I haven't seen one that supports several columns. I think the best approach would be a blend of a table and a tree, so that I could by default collapse rows that don't require immediate attention of the user.
|
|
|
|
|
|
Wow, that looks pretty perfect. Would that bind easily to my parent and child objects and allow me to filter the shown data without altering the "master objects Lists"?
|
|
|
|
|
Sorry, I've not used those controls before, so I can't answer that.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Let's assume I have a class with values:
public class MyClass
{
public string myString;
public int myInt;
} Further, let's assume I have a List of this class:
public List<MyClass> myList; I would like to display all the myString and myInt in a DataGridView with 2 columns, but I would also like to implement a filter that would restrict what would be shown in the DataGridView. For example, one filter would be to only show myInt values between 0 and 5, but please note that I don't what to alter the List itself, it contains "master data" that should never be thrown out or modified. What would be the best approach to achieve this? I would prefer to do this in .NET 2.0, unless there are major reasons to switching to something newer.
|
|
|
|
|
If you use a BindingSource to bind the data to the grid, you can set its Filter property to filter the items which are displayed without removing them from the underlying data source.
BindingSource.Filter Property (System.Windows.Forms) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Post your question in the forum at the bottom of that article.
|
|
|
|
|
Im trying to consume this WS and response NULL. I dont know why because when I test it in boomerang tool work good. Please if someone can help me
The method dont receive parameters and return a string.
using Tassadar.Core.Interfaces;
using ServiceSeedReference;
using System.Threading.Tasks;
namespace Tassadar.Infrastucture.Repositories
{
public class FacturaRepository : IFacturaRepository
{
public string GetSeedSII()
{
string s2;
CrSeedClient seedClient = new CrSeedClient();
s2 = seedClient.getSeed();
return s2;
}
}
}
Is a public WS.
wsdl: https://palena.sii.cl/DTEWS/CrSeed.jws?WSDL[^]
Thanks!!
PD: sorry for my english!
|
|
|
|
|
You're going to have to contact the vendor for this one.
Everything is being done by the "CrSeedClient" class, but nobody but the vendor knows what the class is doing, what it is expecting from your code, or how it works.
|
|
|
|
|
getSeed requires a parameter of type getSeedRequest , and returns a getSeedResponse object.
Testing this in a console app:
CrSeedClient client = new CrSeedClient();
getSeedRequest req = new getSeedRequest();
getSeedResponse resp = client.getSeed(req);
runs OK but still returns null in resp . If I omit the getSeedRequest parameter it won't compile.
However, if I run the above code with Fiddler listening in, then I can see the response received does actually contain XML, and is not null. Not entirely sure what's happening here but I suspect there's no implementation of getSeedRequest.ToString() so it returns nothing. As a workaround, the following seems to work fine:
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebRequest webreq = WebRequest.Create("https://palena.sii.cl/DTEWS/CrSeed.jws?WSDL");
webreq.Headers.Add("SOAPAction", "");
webreq.Method = "POST";
byte[] bData = Encoding.ASCII.GetBytes("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><q1:getSeed xmlns:q1=\"http://DefaultNamespace\"/></s:Body></s:Envelope>");
webreq.GetRequestStream().Write(bData, 0, bData.Length);
WebResponse webresp = webreq.GetResponse();
XmlDocument doc = new XmlDocument();
doc.LoadXml(new StreamReader(webresp.GetResponseStream()).ReadToEnd());
Debug.WriteLine(doc.InnerText);
}
}
}
|
|
|
|
|
|
Glad you've got it going. Hopefully you can modify this code for any other calls you need for that Webservice.
|
|
|
|