I'm Trying to make a program that lists name of all the sub folders of a chosen folder, it all work but i cant seem to make a custom width for my datagridview , I've been looking for an answer for hours , but they mostly wont work, I tried :
Gata.columns[0].width = 100; or stuff like this , but they don't work.
this did not work either : MSDN - DataGridViewColumn.Width Property
it seems that they are mainly used for unbound grids , that i have no idea about I tried to link my MySql table to one but failed again. It is pretty much the 2nd program i'm writing so please forgive my noobishness !
I want my table to look like the enter image description here
the auto-size and fill statement on grids properties wont do the trick. I've checked a lot of answer on stack-overflow but none answers this. Thanks in advance for the help !
public partial class Form1 : Form
{
public void Browser()
{
FolderBrowserDialog address = new FolderBrowserDialog ();
if (address.ShowDialog() == System.Windows.Forms.DialogResult.OK)
path0tb.Text = address.SelectedPath;
}
public Form1()
{
InitializeComponent();
}
//_____________________________________________________________List
private void button1_Click(object sender, EventArgs e)
{
// Make a reference to a directory.
DirectoryInfo directory = new DirectoryInfo(path0tb.Text);
// Get a reference to each directory in that directory.
DirectoryInfo[] directory0Arr = directory.GetDirectories();
// Display the names of the directories.
foreach (DirectoryInfo dir in directory0Arr)
{
//MessageBox.Show(directory.Name);
try
{
String sqlcon = "datasource=localhost;port=3306;useame=anime;password=anime";
MySqlCoection myanimedb0con = new MySqlCoection(sqlcon);
MySqlDataAdapter myanimedb0ada = new MySqlDataAdapter();
MySqlCommand myanimedb0cmd = new MySqlCommand("insert into anime.anime0list ( Anime_Name , Anime_Root ) values ( '" + MySql.Data.MySqlClient.MySqlHelper.EscapeString(dir.Name) + "' , '" + dir.Parent + "' );", myanimedb0con);
MySqlCommandBuilder myanimedb0cb = new MySqlCommandBuilder(myanimedb0ada);
myanimedb0ada.SelectCommand = myanimedb0cmd;
DataTable Gate = new DataTable();
myanimedb0ada.Fill(Gate);
BindingSource b0Gate = new BindingSource();
b0Gate.DataSource = Gate;
this.Gate.DataSource = b0Gate;
myanimedb0ada.Update(Gate);
// Updating the table after adding an item
MySqlCommand myanimedb0cmd2 = new MySqlCommand("select * from anime.anime0list ;", myanimedb0con);
myanimedb0ada.SelectCommand = myanimedb0cmd2;
myanimedb0ada.Fill(Gate);
b0Gate.DataSource = Gate;
this.Gate.DataSource = b0Gate;
myanimedb0ada.Update(Gate);
}
catch (Exception Fail)
{
MessageBox.Show(Fail.Message);
}
}
}
//_____________________________________________________________OpenFolder
private void button2_Click(object sender, EventArgs e)
{
Browser();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
