In C# I have 2 user controls, usercontrol1 contains a bunch of picturebox with flags representing each country and usercontrol2 has a datagridview.
What I want to do is when I click on a picturebox in usercontrol1 call the usercontrol2 with the data corresponding to the selected country loaded into the datagridview.
This is what I have so far for the connection to the Database:
string url = "https:urltosomesite/filewithdata.php";
var json = new WebClient().DownloadString(url);
var m = JsonConvert.DeserializeObject<List<IPUS>>(json);
dataGridView1.DataSource = m;
If I put this on the load of the usercontrol2 it connects to the db and shows the data correctly into the datagridview. However obvioulsy it loads all IP's. Here is the PHP code.
<?php
include "db_conn.php";
$query = "SELECT ip, region, city, zip, provider FROM ip ORDER by region";
$result = mysqli_query($conn,$query);
$rows = array();
while($row = mysqli_fetch_array($result)) {
$ip=$row['ip'];
$region=$row['region'];
$city=$row['city'];
$zip=$row['zip'];
$provider=$row['provider'];
$rows[] = array('ip'=> $ip, 'region'=> $region, 'city'=> $city, 'zip'=> $zip,
'provider'=> $provider);
}
echo json_encode($rows);
Is worth mentioning that the database contains a row called "country" and in that row each country is called by its international code, for example United States is "US"
So basically what I want to do is if I click a picturebox with the American flag it should load the "US" data into the datagridview in usercontrol2. If I select the picturebox with the Italy flag it should only load the "IT" data and so on and so on.
How do I achieve that?
>(json);` Im missing the part to call the other control (usercontrol2) and put the content of the var that has the json string in to the daragridview there.
– Dragonsan's Gameplays Nov 12 '20 at 14:53>(json); usercontrol2 ip = new usercontrol2(); ip.dgv.DataSource = m;` and I got this error: System.NullReferenceException: Object reference not set to an instance of an object. I know I need to initialize the object but I dont know how.
– Dragonsan's Gameplays Nov 12 '20 at 15:57